Line endings difference Windows <-> Linux

Patrick Asselman iceblink at seti.nl
Tue Jun 11 07:59:47 UTC 2013


On 2013-06-10 22:38, Christofer C. Bell wrote:
> On Mon, Jun 10, 2013 at 2:24 PM, Bo Berglund <bo.berglund at gmail.com> 
> wrote:
>
>> On Mon, 10 Jun 2013 13:50:00 -0500, "Christofer C. Bell"
>> <christofer.c.bell at gmail.com> wrote:
>>
>> >On Mon, Jun 10, 2013 at 1:38 PM, Bo Berglund 
>> <bo.berglund at gmail.com> wrote:
>> >
>> >>
>> >> So here is my simple question:
>> >> Has Apache/PHP/MySql been adapted to accept all line ending 
>> systems
>> >> around without breaking like in the old days?
>> >> If that is so then I can stop worrying about line endings in the
>> >> future. :-)
>> >
>> >
>> >
>> >I can't answer your question, but I can say you might consider 
>> installing
>> >the package dos2unix.  It includes the commands dos2unix and 
>> unix2dos for
>> >converting the line endings in ascii files automatically.  I won't 
>> convert
>> >what doesn't need converting, either.  So you can run "dos2unix" 
>> twice on
>> >the same file and still have the Unix format file.  You can run it 
>> in
>> >binaries (images, programs) and it won't corrupt them.
>> >
>> >Convert your entire website at once:
>> >
>> >$ find /var/www | xargs -r dos2unix
>> >
>> >I hope this helps!
>>
>> Well, things are a bit complex.
>> I check out the files from CVS to my Windows7 machine and I commit
>> back when they are edited. On Windows this requires them to be using
>> CRLF line endings.
>> I have also used an Apache server on my Win7 PC to check the site
>> before sending to the real server. This worked fine until I had to
>> start doing MySql stuff too. Much too complex to install in Win7...
>>
>> So I created an Ubuntu test machine (VMWare virtualization) and got
>> the needed website stuff:
>> apt-get install lamp-server^
>> was all I needed to do! :-)
>>
>> Over the weekend I have also struggled to make rsync over ssh work 
>> and
>> I finally succeeded, so when I have edited the site files in Windows 
>> I
>> can just launch a batch file with my rsync commands to update the
>> website on ubuntu with the changed files.
>> Then I can test it.
>>
>> But it is not possible to do rsync to the web hosting company so I 
>> am
>> limited to FTP or sFTP, and here is where I saw the line ending
>> "problem".
>>
>> If it is not a problem then fine, otherwise I will have to be vary
>> careful every time I update the public server....
>
> From which system do you publish to the hosted server?  You can
> "correct" the files with find and dos2unix there and then push them
> out, or you can convert them on the hosted server if you're able to
> install dos2unix on it.  The problem doesn't seem to be anywhere else
> in your workflow other than "once it hits production".  So the files
> only need to be corrected either immediately prior to deployment or
> immediately after deployment.
>
> If immediately prior:
>
> workstation:~$ find staging/ | xargs -r dos2unix
>
> workstation:~$ deploy staging/ # where "deploy" is a placeholder for
> whatever you use
>
>  If immediately after:
>
> server:~$ find production/ | xargs -r dos2unix
>
> Or have a periodic cronjob that runs it every few minutes (I'm not
> sure how many files we're talking about).  If you find that 
> everything
> is working on your testing VM already anyway, then all of this is
> moot.  What works in your Ubuntu VM will undoubtedly work in
> production, as long as you are deploying from your test environment
> (i.e.; the actual code you test is what is copied to production).
>
> --
>
> Chris
>
> "If you wish to make an apple pie from scratch, you must first invent
> the Universe." -- Carl Sagan

PHP does not care how you end your lines for interpretation of the 
code.

BUT there are some risks, for instance if you print a string, the 
string may come out differently, depending on how you coded it. Or if 
you read a line of text from a file.

My suggestion would be to find a good FTP program, and to make sure the 
files are converted as they are transferred.
For instance FileZilla has a sane default setting and knows that php 
files are basically text files that need converting when transferred 
from one system to the other. But all ftp programs have such a setting 
(set "transfer type" to "auto" will do the trick).

Best regards,
Patrick Asselman





More information about the ubuntu-users mailing list