Permission problems running WordPress on Nginx

January 26, 2015 10.7k views

I recently set up a new droplet using the "LEMP on 14.04" stack on DO, and I'm experiencing some issues with permissions for when uploading images or updating plugins in the WordPress admin. I figure this has to do with ownership of the folders. The plugins and uploads folders are currently set to 755. I have one user and group on the server, both named root. How would I easily solve this - adding a secondary group / user and then granting new ownership of the folder?
Setting any of the folders to 777 makes everything work but I don't want that for security reasons.

2 Answers

The issue is likely because your files are owned by root. Your nginx process would be running as the user "www-data" and so it would not have the needed access to these files. You can change the ownership of your files using the command:

chown -Rf www-data:www-data /usr/share/nginx/html

Using the path to your web root if it is different from the one shown.

Simply put, you need to have nginx run PHP-FPM.

You can look at how to do that by going to the config part in this how-to:

Basically, the part you want:

  • Edit /etc/php-fpm.d/www.conf
  • change user and group:
user = nginx
group = nginx

restart PHP-FPM, then you can just run this on your folder (Change "/path/to/your/website" to the actual path):

cd /path/to/your/website; find . -type d -print0|xargs -0 chmod 755; find . -type f -print0|xargs -0 chmod 644; chown nginx:nginx * -R
  • PHP Fpm is already installed and running on the LEMP stack, so that's not the issue. Thanks for looking into it though.

  • I fully understand that PHP FPM is installed. Who is it running as?

    If it's apache, it needs to be nginx, and the files need to be owned by nginx.

    run this:

    is_apache=$(cat /etc/php-fpm.d/www.conf|grep group|grep apache|wc -l); if [ "$is_apache" = "1" ]; then echo "It's running as apache. You need to change it to nginx"; else echo "That file is set right. That's not the issue"; fi

    It will tell you if I'm off course or not.

Have another answer? Share your knowledge.