Installation failed: Could not create directory – CentOS 7

I have spent over 6 hours trying to do the 5-minute installation. I’ve searched Google over and over, and have yet to find anything that will actually fix my problem, so hopefully someone here can be of help.

I installed WordPress (using these instructions). Installation went as expected. However, I now cannot install or uninstall any plugins or themes. My server does not have FTP (and I intend to keep it that way), so I’m using define('FS_METHOD','direct'); in functions.php.

I’m using Nginx on CentOS 7, so I set the owner of /usr/share/nginx/html (recursively) to nginx:nginx. That directory is the location of my WordPress installation. I have also set my directories to chmod 755 and files to chmod 644, per every reputable resource I could find online. As far as I can tell, based on what I can find online, those things there should make it work, and yet, the issue persists.

What do I need to do to fix the file permissions?

I know I’m probably going to get marked as duplicate, but I assure you I have attempted every reasonable idea I could find online, both on Google and on this site. Just for the record:

  • Chmod 777 on everything doesn’t make it work
  • Chown root on everything doesn’t make it work
  • Yes, I’m using -R on my chown and chmod commands
  • Yes, I have rebooted my server several times.

1 Answer
1

SELinux was the problem. Its enforcement was, for lack of a better term, overriding the file permissions and keeping WordPress from writing to any of the files.

To solve the issue, I did the following:

Check if SELinux is enabled:

# getenforce

If the response is “Enforcing”, then SELinux is enabled and it is probably your problem.

Just for good measure, let’s go ahead and ensure that the file permissions are correct:

# cd /path/to/wordpress/
# find . -type d -exec chmod 755 {} \;
# find . -type f -exec chmod 644 {} \;

In those commands, we navigated to the directory where WordPress is stored, and then set the file permissions per the WordPress File Permissions help article.

Before we move on, we need to lock down all SELinux enforcement for the entire WordPress directory. This ensures that we don’t have any stray vulnerabilities:

# chcon -t httpd_sys_content_t /path/to/wordpress/ -R

Next, we need to set SELinux to allow the appropriate write access:

# cd /path/to/wordpress/
# chcon -t httpd_sys_rw_content_t wp-config.php
# chcon -t httpd_sys_rw_content_t wp-content -R

Note that we allowed write access (rw) to both the wp-config file and the wp-content directory, recursively.

Once you have completed all those steps, restart Nginx and visit WordPress in your browser. You should now be able to successfully install/remove plugins and themes.

Note: DO NOT DISABLE SELINUX ALTOGETHER. Only modify the enforcement as listed above. Disabling SELinux is a major security vulnerability.

Leave a Comment