{"id":194,"date":"2017-04-04T14:32:53","date_gmt":"2017-04-04T12:32:53","guid":{"rendered":"https:\/\/www.petersplanet.nl\/?p=194"},"modified":"2017-07-09T16:01:56","modified_gmt":"2017-07-09T14:01:56","slug":"wordpress-the-uploaded-file-could-not-be-moved-to-wp-contentuploads","status":"publish","type":"post","link":"https:\/\/www.petersplanet.nl\/index.php\/2017\/04\/04\/wordpress-the-uploaded-file-could-not-be-moved-to-wp-contentuploads\/","title":{"rendered":"WordPress: The uploaded file could not be moved to wp-content\/uploads\/"},"content":{"rendered":"<p>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.\u00a0The error message was\u00a0that the uploaded file could not be moved to wp-content\/uploads\/2017\/04.<br \/>\n<!--more-->Usually this has something to do with file permissions but all the file permissions were fine. So what could it be?<br \/>\nFirst I set debugging to true in the WordPress wp-config.php file.<\/p>\n<pre>define('WP_DEBUG', true);\r\ndefine('WP_DEBUG_LOG', true);\r\n<\/pre>\n<p>Unfortunately this did not give me much more information.<br \/>\nNext I set SELinux in permissive mode<\/p>\n<pre>setenforce 0\r\n<\/pre>\n<p>And then the uploads were working again! So it had to do with SELinux. After some research I found out that\u00a0the security settings of the uploads directory should be like this:<\/p>\n<pre>semanage fcontext -a -t httpd_sys_rw_content_t \"\/var\/www\/html\/wp-content\/uploads(\/.*)?\"\r\nrestorecon -R -F -v \/var\/www\/html\/wp-content\/uploads\r\n<\/pre>\n<p>And the result:<\/p>\n<pre># cd \/var\/www\/html\/wp-content\/uploads\/2017\r\n# ls -Z\r\ndrwxrwxr-x. root apache system_u:object_r:httpd_sys_rw_content_t:s0 04\r\n<\/pre>\n<p>You can also check for &#8220;denied&#8221; in the \/var\/log\/audit\/audit.log<\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.\u00a0The error message was\u00a0that the uploaded file could not be moved to wp-content\/uploads\/2017\/04.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-194","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/comments?post=194"}],"version-history":[{"count":18,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":212,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/194\/revisions\/212"}],"wp:attachment":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}