WordPress: The uploaded file could not be moved to wp-content/uploads/

Some time ago I had reinstalled petersplanet.nl on a new CentOS 7 Linux server with the latest WordPress version. However when I tried to upload new content this was not possible anymore. The error message was that the uploaded file could not be moved to wp-content/uploads/2017/04.
Usually this has something to do with file permissions but all the file permissions were fine. So what could it be?
First I set debugging to true in the WordPress wp-config.php file.

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);

Unfortunately this did not give me much more information.
Next I set SELinux in permissive mode

setenforce 0

And then the uploads were working again! So it had to do with SELinux. After some research I found out that the security settings of the uploads directory should be like this:

semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/wp-content/uploads(/.*)?"
restorecon -R -F -v /var/www/html/wp-content/uploads

And the result:

# cd /var/www/html/wp-content/uploads/2017
# ls -Z
drwxrwxr-x. root apache system_u:object_r:httpd_sys_rw_content_t:s0 04

You can also check for “denied” in the /var/log/audit/audit.log

If you read the instructions on the wordpress.org site the installation of WordPress seems to be fairly simply. However with SELinux enforced (which you should) things become a bit more complicated.

No Comments

Post a Comment