Press "Enter" to skip to content

WordPress Updates in CentOS 7 + Apache + SELinux

Francesco Mondello 0

A couple of weeks ago I moved my WordPress blogs from a trivial shared hosting to a more sophisticated VPS running CentOS 7 since I was in search of more flexibility from my server.

During these days, I learned a lot about managing a web server on my own and I’m still currently learning a ton of interesting things about this topic.

One of the most annoying problems I faced a couple of days ago concerned, in particular, my WordPress installation. Everytime I was trying to update its core and plugins, the dashboard showed me a message similar to this:

Downloading update from http://downloads.wordpress.org/plugin/plugin.x.x.x.x.zip…
Unpacking the update…
Could not create directory

This problem looked quite strange to me since I carefully set all correct users, groups and permissions to my WordPress directory tree.

Fortunately, I soon discovered this problem was not about wrong permissions but was related to SELinux.

SELinux infact, for security reasons, prevented WordPress from automatically create and modify directories and files.

Since deactivating SELinux could not be the best idea possible, we have to allow Apache to read and write some directories in order to make the updating process work smoothly.

Setting up the correct permissions

First of all, we have to set the correct permissions to the WordPress directory tree.

Firstly, we have to set apache as a user:

# chown -Rv apache:apache /var/www/wordpress/

The second thing to do is giving the correct permissions to files and directories with the following two commands:

# find /var/www/wordpress/ -type d -exec chmod 755 {} \;
# find /var/www/wordpress/ -type f -exec chmod 644 {} \;

Setting up Selinux

Now, we have to allow httpd to read/write the correct directories:

# chcon -t httpd_sys_rw_content_t /var/www/wordpress/wp-content -R

Extras

Wordpress Connection Informations
WordPress Connection Informations

If WordPress is showing you a strange page about Connection Informations asking you for some informations about FTP user and password credentials when you try to update/install new plugins, add the following line at the end of your wp-config.php file:

define(‘FS_METHOD’,’direct’);

That’s all. From now on, you should be able to update your WordPress installation and to update or install new plugins without problems!

Comments are closed.