How to fix "The uploaded file could not be moved to wp-content/uploads/"

edited July 5 in Web Development

If you work with WordPress for your business or personal website, at some point you will likely come across this error when trying to upload new media to your Media Library:

“image.png” has failed to upload.
The uploaded file could not be moved to wp-content/uploads/2017/06.

You may also see errors like this when trying to add a file:

To top if off, you will also have issues updating plugins automatically or updating the theme. It will say something like:

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Why does this happen?

This is basically the security of WordPress at work. Your web server is enforcing the permissions it is aware so it is generally a good thing. It does not help you with uploading those images or updating the plugins.

How NOT to fix this problem

There is plenty of discussion on the internet regarding this problem. I have seen quite a few posts simply suggesting that you change permissions on your /wp-content/uploads folder to 777. This is a really bad idea and will likely lead to your WordPress site becoming hacked. Do NOT change permissions on your /wp-content/uploads folder to 777.

How to fix the problem

If you running your WordPress your website on a shared hosting server then you may need to submit a support ticket or send an email into support to get this error taken care of. Some shared servers do have some form of SSH access so to get started open or download then open the Putty program on your computer and login.

Once logged in as root, execute this command:

ps aux | egrep '(apache|httpd)'

This will show what user apache is running as. Usually nobody.

You can then simply give the user "nobody" rights to upload images to the directory.

This can be done running the following command:

chown -R nobody /home/_serverusername_/public_html

Be sure to change serverusername with your actual server username. This is what you use to login to cPanel and can also be seen in the path to your server.

Tagged:
Sign In or Register to comment.