Linux Uptime

Correct Permissions for WordPress 2


If you’re getting permissions errors when trying to update WordPress plugins or themes (or even WordPress itself), it can be a major pain to try and troubleshoot WordPress permissions, and the documentation is unclear on exactly what the optimal WordPress permissions settings are.

I recommend these using the following four easy Linux commands to set the correct WordPress permissions for most settings.

Step 1: Find Which User is Running the Web Server

WordPress works best if its files are “owned” by the same user that runs the web server. On Fedora/RedHat/CentOS platforms, the user’s simply apache. On Ubuntu or Debian, it’s www-data. But if you’re unsure or want to confirm the username, do:

ps -ef | grep httpd | grep -v `whoami` | grep -v root | head -n1 | awk '{print $1}'

That will spit out the correct username (probably apache or www-data). You’ll need to use that username in the next step.

Step 2: Let the Web Server User Own WordPress Files

Make sure you’re in your WordPress root directory (the same directory that contains wp-config.php), then set the web server username  as the owner of everything in and below that folder.

Fedora/RedHat/CentOS users should do:

sudo chown apache:apache -R *

Ubuntu/Debian users should do:

sudo chown www-data:www-data -R *

If another user runs your web server, just do the above command with the appropriate username.

Step 3: Change WordPress Directory Permissions

Running this command in the WordPress directory will find all the directories below the WordPress root directory and set their permissions to 755:

find . -type d -exec chmod 755 {} \;

Step 4: Change WordPress File Permissions

Running this command in the WordPress directory will find all the files below the WordPress root directory and set their permissions to 644:

find . -type f -exec chmod 644 {} \;

You’re all done! You now have the perfect permissions for nearly every WordPress installation. If you’re running some additional cacheing software that complains that it needs ever more permissive settings, it will generally tell you specifically which commands to run.

But for now, go enjoy your correct WordPress permissions by updating some plugins and themes!