Reputation: 64854
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 ?
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 .
Upvotes: 1
Views: 1211
Reputation:
Check the file permissions with ls -la
. They should be readable by the Apache user (www-data
in the standard case).
Try running chmod -R 755 /path/to/website
and see if it works.
Upvotes: 0
Reputation: 11042
Also you might need to convert your line endings from Windows to Unix format.
You can do this in Notepad++.
Edit>EOLConversion>Unix Format
Upvotes: 1
Reputation: 4416
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:
#!/usr/bin/php
So your example would actually look like this:
#!/usr/bin/php
<?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 '\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:
#!/usr/bin/php\r
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.
Upvotes: 0
Reputation: 71170
It maybe because you dont have the necessary infrastructure in place to run PHP files locally, i.e. in the case of WAMP: http://www.wampserver.com/phorum/read.php?2,44101,44101, you may need to install LAMP or similar. Its hard to determine wihtout additional detail..
Upvotes: 0