Question

Permission problems running WordPress on Nginx

  • Posted January 26, 2015

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.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

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:

https://www.digitalocean.com/community/questions/install-magento-1-9-1-0-on-centos-7-with-lemp?answer=19492

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