CentOS/Nginx WordPress Folder Permissions for Auto-Update and Plugin Install

November 10, 2013 20.3k views
Hi, Installation guides are not thoroughly clear on how to install WordPress on CentOS/Nginx, so that, a user can auto-update and install plugin from within WordPress without permission error hassles. Debian based distribution guides recommend changing folder and file owner to www-data and adding HomeUser to www-data. I have had a hard time finding who actually is the default user of nginx on CentOS. In the CentOS/LEMP guide we changed apache user to nginx in nginx.conf. That makes me think nginx should be the web server user on CentOS/Nginx. Extrapolating the Debian guide here is what I think I should do on CentOS. chown -R nginx:nginx wordpress/ usermod -aG nginx HomeUser This should help me update WordPress using my HomeUser SSH login. Next I am concerned about file permissions. Default folder permission of WordPress 755 and file permissions are 644. That will mean HomeUser which is added to group nginx will neither be able to write in folder group permission 5 equivalent to r-x or file group permission being 4 equivalent to r-- . These are WordPress recommended permission. WordPress recommends highly against 777 permissions. What is the best possible thing I can do to maintain balance between usability and security? Another question I have is who tends to be the owner of WordPress - web server user, mysql user, root user or home user? Thanks.
7 Answers
Are you getting permission hassles with this guide How To Install Wordpress with nginx on CentOS 6?
by Etel Sverdlov
Wordpress is a free and open source website and blogging tool that uses php and MySQL. It was created in 2003 and has since then expanded to manage 22% of all the new websites created and has over 20,000 plugins to customize its functionality. This tutorial shows how to install Wordpress on a server with LEMP (with nginx instead of apache). It is written for Centos 6.
Of course because WordPress user doesn't have permission to write in root folder.

I did as mentioned above and don't have any problems.

chown -R nginx:nginx wordpress/
usermod -aG nginx HomeUser

Surprisingly it didn't even ask me my HomeUser username and password.
Ah... ha! You were right. Looks like the CentOS article is missing a section RE: permissions, when compared to the tail of Step Five of How To Install Wordpress with nginx on Ubuntu 12.04.
by Etel Sverdlov
Wordpress is a free and open source website and blogging tool that uses php and MySQL. It was created in 2003 and has since then expanded to manage 22% of all the new websites created and has over 20,000 plugins to customize its functionality. This tutorial shows how to install Wordpress on a server with LEMP (with nginx instead of apache). It is written for Ubuntu 12.04.
My understanding is Debian based distros have www-data user for Apache, Arch has http for both Apache and nginx and from my reading CentOS uses Apache for Apache and nginx for nginx. So, proper command should be.

chown -R nginx:nginx /var/www/wordpress

I am not sure how secure this is. After running above command WordPress can install any plugin or ideally should be able to make change to any directory that is owned by user nginx. I have to catch up on WordPress security. The above command is mentioned on all tutorials here on Digital Ocean. I hope I am wrong.
I've been using a similar command along with 775 as the permissions. The idea is to use the group used by nginx and the user under which the profile is installed:

chown -R wordpress:nginx /var/www/wordpress

On my server I use:
chown -R sampleacct:nobody /home/sampleacct/public_html/

Then chmod 775 the directory and sub-directories.

For anyone reading this, check your php-fpm configuration and make sure it's the correct user running the module.

Running Centos 7 and nginx I had to change apache to nginx in /etc/php-fpm.d/www.conf and run sudo systemctl restart php-fpm.

None of the above solutions worked for me using WP 4.8.2 on Centos 7.X and NGINX.

Have another answer? Share your knowledge.