I have copied PHP files developed in windows to ubuntu, but when I want to browse these files on ubuntu, they don’t excute anything. why ?
edit
No error message, I open them in the browser but it seems that if they don’t have any code. for instance, if a file has the code <?php echo "hello"; ?> this file don’t do anything.
If I create a new file it works fine, but when I copy a similar file, it doesn’t do anything .
In order for a php file to run automatically under Unix/Linux, it needs two things:
Files that you transfer from windows to Linux probably won’t have the correct permissions, and they almost certainly won’t have the correct hashbang line. Use ‘ls -l’ and chmod to view and change the permissions (I’ll leave this as an exercise to the reader).
The hashbang line for php will looks like this on my Ubuntu box:
So your example would actually look like this:
The actual path can be found using
There is a subtle issue about the hashbang line that you do have to take in to account when transferring files from windows to unix, and it is in fact what skyline mentioned: Windows uses the ‘\r\n’ line feed combination, unix uses only ‘\n’. This means that the hashbang line from a file that was edited on a windows box will actually look like this:
You won’t see the ‘\r’ character (it’s a carriage return after all), but the operating system will try to execute ‘php\r’ rather than ‘php’… so yes, you do have to use dos2unix or frdos to remove the carriage returns from the file.