I (PHP newbie) am setting up a legacy PHP website on my Linux/Apache server.
When I test the site in my browser I get this error:
Warning: move_uploaded_file(/var/tmp/jinfo/Circuit/best_cities.csv):
failed to open stream: Permission denied in /var/www/jinfo/includes/jinfo.inc.php on line 89
Warning: move_uploaded_file(): Unable to move '/tmp/phpMLE9Ox' to
'/var/tmp/jinfo/Circuit/best_cities.csv' in
/var/www/jinfo/includes/jinfo.inc.php on line 89
Looks like a file system permissions problem. The script uses /var/tmp/jinfo and its subfolders to store files. The permissions on that directory are:
drwxr-xr-x 5 root root 4096 Aug 7 15:32 jinfo
Since Apache is running as user www-data, the error message is expected. But what should the permissions be? I am sure there are lots of ways to make the error message go away by loosening permissions, but I want to follow the best practice. Should I change the owner (chown) to www-data, or chmod the permissions?
Note: I need the changes to propagate to subdirectories too.
You need to fix your permissions before changing the group will be effective. As mentioned in Explosion Pill’s answer, you should change the group to be
www-datafor Apache. You can do this recursively on your/var/wwwdirectory:where
owneris the user that currently owns the files.Here you can see the read/write/execute permissions on the file for the owner, group, and others respectively:
Ignore the
d, the other letters mean:This site gives you the meaning of the
chmodnumbers:http://www.goldenplanet.com/support/kb/articles/changing-of-file-rights-chmod-on-the-webserver.html
You can do
chmod 775on the directory that is giving the permission error which will give the owner of the file and the group full permissions, while only giving “others,” read and execute access.