Permission denied whenever uploading files

Posted October 9, 2014 63.5k views

I am running the LEMP Stack on Ubuntu 14.04

I am always getting permission denied whenever my php file is trying to save or upload something. If I chmod the folder to 777 it works but I don’t want to change it to 777. I checked the owner of all the files in my application . It is root / root (owner / group ).

I have the exact same project on a different server with permissions set as 0755 and the owner as 501 / 500 and the application works flawlessly. But I don’t know that the 501 / 500 stands for.

Also I just checked the following for my application:

script owner : root
script getmyuid : 0
script getmygid : 0

How come the script owner is root and I still get permission denied ?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
7 answers

By default the nginx process runs as the user www-data. Changing the ownership of your files and directories inside your web root to this user will allow nginx to create new files and directories in this path.

chown -Rf www-data.www-data /usr/share/nginx/html/*
  • worked, thanks ! How can I know under which user a process runs ?

  • One way is to run “top” when the process is running. It will indicate the user the process is being run by. On Ubuntu Apache and nginx always use the user www-data. On CentOS/Fedora the user is generally “httpd” by default.

If you are running apache on Ubuntu 14.04 you want to invoke it as such

sudo chown -Rf www-data:www-data </var/www/html/*
sudo chown -Rf www-data:www-data /var/www/html/*

This worked for me!

i have same problem . i trying to copy wordpress zip file but getting: scp: ./ Permission denied

I ran your command on my VPN but still the same.

can u help me??
i have same problem but i follow this tutorial but it does not bring results.

Hi , I had the same issue ..I couldn’t upload anything from my admin panel so I changed the permission on the media folder and gave all users full permission(to media folder).
I achieved that by executing this on my media folder…
sudo chmod -R a+rwx /media (path to your media folder) restarted everything then it worked . You can try it.