In order for a php file to run automatically under Unix/Linux, it needs two things:
- the file must be executable
- the file must have a valid 'hashbang' line as the first line in the file.
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:
<?php echo "hello"; ?>
The actual path can be found using
command -v php
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 '
' line feed combination, unix uses only '
'. 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 '' character (it's a carriage return after all), but the operating system will try to execute 'php' rather than 'php'... so yes, you do have to use dos2unix or frdos to remove the carriage returns from the file.