Knowledge Base

How Can We Help?

Fix : WordPress has failed to upload. Unable to create directory.

You are here:

In this tutorial, we will explore methods to fix the issue – “filename.jpg” has failed to upload. Unable to generate directory wp-content/uploads/yyy/mm. Is its parent directory writable by the server?

WordPress is a costless and open-source content management system (CMS) based on PHP and MySQL. You can utilize WordPress to construct an exquisite website, blog, or application.

 

The uploaded file could not be relocated to wp-content/uploads

This frequent error commonly appears when you transfer your website from one hosting to another. This error is displayed when you attempt to upload files to your website via the WordPress admin dashboard. This error also produces some adverse effects such as the inability to add/update plugins. When you try to add a new plugin to the website, WordPress will present you with FTP credentials screen. Until this error is resolved, you will have to manually add new plugins.

Wordpress-Failed-To-Upload-Error

Causes

Oftentimes, this error occurs in the context of migrated websites. Websites that were previously functioning without any issues will display this error shortly after migration. When you upload files to the website, WordPress sends a request to the internet server (apache) to retrieve the requested file from your hard drive and uploads the file to a temporary memory on the server. This file is then saved in the WordPress media library within the location wp-content/uploads/. The account that retrieves the file from your hard drive is the apache user account, which is ‘nobody’ by default. You will encounter the error message ‘The uploaded file could not be relocated to wp-content/uploads/’, if the apache user account lacks the necessary permission or rights to access the wp-content/uploads/ folder.

 

Resolution Methods

Determine the apache service account

To carry out the steps, you need to be logged into your server as the root user. Once logged in as root, execute this command.

# ps aux | grep httpd

This will yield the following output.

root      5597  0.0  0.1  70904  6552 ?        Ss   Nov18   2:03 /usr/local/apache/bin/httpd -k start -DSSL

nobody    8715  0.0  0.0  69728  2516 ?        S    17:11   0:00 /usr/local/apache/bin/httpd -k start -DSSL

nobody    8717  0.0  0.0  70904  2608 ?        S    17:11   0:00 /usr/local/apache/bin/httpd -k start -DSSL

nobody    8718  0.1  0.4 1332864 17180 ?       Sl   17:11   0:06 /usr/local/apache/bin/httpd -k start -DSSL

nobody    8719  0.1  0.4 1333004 17012 ?       Sl   17:11   0:07 /usr/local/apache/bin/httpd -k start -DSSL

nobody    8720  0.1  0.4 1333356 16828 ?       Sl   17:11   0:07 /usr/local/apache/bin/httpd -k start -DSSL

nobody    8808  0.1  0.4 1333584 16088 ?       Sl   17:12   0:06 /usr/local/apache/bin/httpd -k start -DSSL

nobody   11467  0.1  0.2 1332816 11696 ?       Sl   18:51   0:00 /usr/local/apache/bin/httpd -k start -DSSL

root     11611  0.0  0.0   4052   188 pts/0    D+   18:56   0:00  grep httpd

The output indicates that the apache process is owned by the user ‘nobody’. The apache service account ‘nobody’ must be granted access to the wp-content/uploads folder.

 

Grant access to the apache service account

From the previous method, we have discovered that ‘nobody’ is the apache service account. The next step is to grant access to the ‘nobody’ user for the wp-content/uploads folder. The easiest way to do this is by assigning ownership. Execute the following command to assign ownership to the ‘nobody’ user.

# chown nobody wp-content/uploads

This action will make the ‘nobody’ user account the owner of wp-content/uploads and grant access.

 

Upload files

Now return to your WordPress admin dashboard and try to upload files again. You will notice that the uploads are successful and no errors are triggered. Additionally, you will be able to add and update your plugins within your website.

 

777

Please refrain from setting 777 permission for your wp-content/uploads folder. This is highly dangerous as it allows anyone to access your secure files. Permissions should be set to 755/644.

 

If you require further assistance, please contact our support department.

 

 

Leave a Comment