Forum: 

Cannot upload to Wordpress Media Library (in Wordpress Appliance)

David Lambros's picture

Hi all,

I'm having trouble uploading files to the Media library using either the browser upload or flash uploader. I receive this error:

“test.jpg” has failed to upload due to an error
The uploaded file could not be moved to /var/www/wordpress/wp-content/uploads/2013/05.

I've found that if I give 777 or 757 permissions to the "05" folder the upload works correctly. I'm new to linux and am having trouble diagnosing why this isn't working with the standard 755 permissions. My guess is that the "user account" wordpress is using is NOT the root account which seems to be the owner of the directory. 

Does this make sense? lol. Please help if you have a few minutes... 

Thanks!

Andrew Smith's picture

I don't think it's a "root" user issue. Directory permission should be "777" (read, write & execute) to upload the things.

David Lambros's picture

No kidding! Awesome. So if i recursively set permissions to 777 on the Upload folder will all newly created folders inherit the 777 permission? By default the wordpress media upload creates folders based on month and year and I don't want this problem to recur next month.

Jeremy Davis's picture

IMO it would be better to keep the permissions as 755 and give ownership to the webserver account (www-data). It probably doesn't make significant difference in the grand scheme of things but best practice is to keep permissions as tight as possible. Using 777 for testing is legitimate IMO, but there should be no need to leave permissions that loose in production. Root owned directories with 777 should have the same impact on WordPress as those dirs having 755 and owned by www-data. (FYI the 3 numbers refer to owner, group, others - 7 means read/write/execute; 5 means read/execute).

So personally I would do this:

chown -R www-data:www-data /var/www/wordpress/wp-content/uploads 
chmod -R 755 /var/www/wordpress/wp-content/uploads 
Laudemir's picture

Thans for your help. I was trying to upload themes but was not working. Everything ok after change the user and group to www-data instead of nogroup and nobody or root and root.

Adam K's picture

It's interesting, my inital thought was that it was a permission error and I tried giving permissions but it still didn't work. Then i tried changing ownership like you suggested and it worked perfectly. Thanks for your help!

tookimdown's picture

worked perfectly, thanks a lot !
David Lambros's picture

Thanks Jeremy. After thinking about it I was getting uncomfortable with the 777 idea. Your post helps a ton. I'll try those commands right after I get a fresh backup. THANK YOU for your details explaination - it really helps a linux noob like me. :)

Fareed's picture

I have windows hosting and I have congfgured wordpress with FileZilla. Could someone tell me how to change or modify permission of wp-content

Jeremy Davis's picture

If you mean that you are on a Windows server, then sorry I have no idea. TBH I doubt anyone round here will... We are all Linux guys... :)

gege's picture

I want to ask about "if I try to change the permissions already 777, 757, 755 and 655 why still can not upload, space on the server is still empty many updates also affects whether, because there is a notification system upgrade to version 3.9.1" Error saving media attachment.

Jeremy Davis's picture

Then it should just work. However obviously something is not quite right. Also as you may already know, 777 permissions are a security risk...

Best thing to do is to give the webserver ownership of the location, like I said in my post above.

Cameron Sargeant's picture

How would I make sure the webserver ownership is set as it should be. I am new to the backend management of WP. 

 

Cameron Sargeant

Jeremy Davis's picture

Follow the link that I posted above. This only applies to TurnKey Linux though. Having said that TurnKey is built on Debian (and Ubuntu is also built on Debian) so should also be relevant there. If you are using a different OS then I suggest that you post on their support forums (these are the TurnKey Linux forums).
charles's picture

I recently moved a client over to a new site, and I came across your blog on the search for an answer to this.
I wrote this on it: http://www.charleslabri.com/wordpress-the-uploaded-file-could-not-be-mov...

But essentially, I moved them from apache to nginx/php-fpm and the USER that PHP-FPM was running under did not have the permissons to write to the folder. Using anything other than 755 is not recommended for those folders in production.

Euclides's picture

Open the Terminal and type in :

sudo chown -R www-data:www-data /var/www/wp-content

Make sure you add -R to the command so it changes the permission to the uploads and his sub directories.

Euclides's picture

You might need to replace www-data with the current apache user and group on your server.

Jeremy Davis's picture

But seeing as this is the TurnKey Linux forums (which is based on Debian) then www-data is the correct user/group (and would be for all Debian derivative OS).
James's picture

Try increasing the upload_file_maxsize and max_execution_time values in PHP.INI Builder. Also you could also try disabling "Crop thumbnail to exact dimensions (normally thumbnails are proportional)" in media settings. http://debug.ga/wordpress-media-upload-errors-part-2/

Vince's picture

I'm working on moving from Dreamhost to a VPS (also Debian). So far I have had three permissions issues, two of which I resolved already, but the third is kicking my butt. 

First, Wordpress couldn't create a directory to install new plugins. I found how to install ssh2 and authenticate that way, so that was taken care of.

Second, a .css file wasn't writable for the theme. I'm not sure what was going on there, but I chmodded it to 777 as a workaround and took care of that.

Third, the one that I can't resolve, is the problem here: Wordpress can't move uploads into the proper folders. I've chowned the entire wp-content folder with the proper user:group, and I've chmodded it to 777 to test (currently 775). 

I tested the chown/chmod fix on a brand new test install and got it working by changing ownership of the directories recursively. But I can't just install a new site for the existing project I'm moving. Do you have any advice on how to fix this? 

Jeremy Davis's picture

Not that it should really matter, but in TKL you are root by default. If it is something which doesn't have root enabled (and you're using it) then sudo should work but perhaps it's setup wrong/locked down so sudo isn't getting full root type access? I don't know really, just throwing random ideas about...

I know you said you're confident the permissions are set ok but you can double check permissions with 'ls -la' (this will list all files/directories with ownership and permissions inc hidden ones). Also perhaps double check the WP config to make sure that it isn't trying to save/move stuff to somewhere that it doesn't have permission (i.e. outside of it's install directory).

Other than that, the only other thing that I could imagine trying is restarting Apache. TBH I have never heard of that causing a problem but I'm all out of ideas beyond that...

Euclides's picture

Hey Vince, could you tell who is the owner of the www directory and the inner directories7files? Make sure that http is the owner .

Vince's picture

The owner is www-data, the Apache user. That's what fixed the issue on my test website on the same server.

http://sounddoctrinemusic.com/phpinfo.php (this is the test website)

Jeremy Davis's picture

On Debian based systems (e.g. Debian, Ubuntu, Mint, etc) the Apache user is 'www-data'; AFAIK on RHEL based systems (e.g. RHEL, CentOS, Fedora, etc) the Apache user is 'httpd'.

2Surge's picture

Here is a great article on how to fix this error with Wordpress that will probably help. Very detailed explanation on how to fix this permanently!
hiral's picture

When i upload image into wordpress i get error like:

The uploaded file could not be moved to wp-content/uploads/2015/03.

How can i solve?

Jeremy Davis's picture

chown -R www-data:www-data /var/www/wp-content
freevectorpic.com's picture

I moved my wordpress vps to antoher new and also encounter this problem I failed to upload media file , there is same error message similar with "The uploaded file could not be moved to wp-content/uploads/2015/03." and I followed above way issue the following command in my vps :

chown -R www-data:www-data /var/www/yourwebsite/wp-content

I installed ubuntu 14.04 in my vps, so I hit this problem ,before I used centos,  I just create a "www" user as apache user ...no found this problem..

 

 

thanks Jeremy 

notradamequeen's picture

dear jeremy,

i've tried to type

chown -R www-data:www-data /var/www/yourwebsite/wp-content

but it said chown: cannot access ‘/var/www/notradame/wp-content’: No such file or directory...i'm a very newbie..

please help me, i use lampp, and i placed the wordpress folder in /opt/lampp/htdocs, i named my wp notradame.

 

Jeremy Davis's picture

So here is a theoretical command:
chown -R user:group /some/directory

chown is the command to change ownership! :)

-R is the switch to use when you want to change ownership Recursively (i.e. /some/directory and all the sub-directories and files inside)

user is the username and group is the group name. By default on Debian all users are also automatically members of a group with the same name (as their username). So if I create a new user 'jeremy' it will automatically create a new user group also called 'jeremy' and the user 'jeremy will be a part of this new 'jeremy' group.

In Debian, the webserver runs under a special user account called 'www-data' (which as per above, also has a group by the same name).

/some/directory is a path. It can be to a file or a directory. However the use of the -R switch only makes sense if it's a directory!

So when I suggest:

chown -R www-data:www-data /var/www/yourwebsite/wp-content
What I am really saying is:
change ownership of /var/www/yourwebsite/wp-content so it and all it's contents belong to the webserver user and group

But your content path is different so the 'cut and paste' command won;t work!

By now I'm guessing you can probably work it out for yourself, but here it is anyway!:

chown -R www-data:www-data /opt/lampp/htdocs
notradamequeen's picture

thank you jeremy...it work well :)

Sumanta Sarkar's picture

The apache user can be chabged in Ubuntu....as Jeremy said that is www-data is the default one...it can be apache:apache also.

So the best practice is first find out the user for apache  by vi etc/passwd....look at the file and you can easily understand which is the apache user (apache,www-data,httpd...etc). Then run

 

chown -R user:group [directory path]

Julie's picture

Hi, your method did the trick for me :) the website I had trouble with just recently changed hosting. The upload folders of the previous months (up to may 2015) had the right user and group, only june and july had root as user and group. Now I do wonder what will happen next month? Will the map of august again have root user and root group?

note: I believe the maps wp-content and uploads have correct settings as their user and group are still very much the same as a few months ago

Avelino Alves's picture

I already have done everything but instead of use www-data i use nginx:nginx and still have the problem....

 

any help?

Post new comment