Installation failed: Could not create directory – CentOS 7

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.