12

I am trying to upload pictures in WordPress but I get this error:

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

I am running it in localhost but the answers I have found are to change the folder permissions to 777 on the server.

I tried making an uploads folder myself, but it's of no use and there is no option to change the folder permissions to anything except read and write.

I'm using XAMPP on Mac OS X; I'm new to WordPress - how can I fix this?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Wang'l Pakhrin
  • 858
  • 3
  • 15
  • 29

5 Answers5

20

It is most likely a permissions issue. Find the user processes running on the site by navigating to your sites wp-content folder on the server your site is on. Then type this;

ps aux | egrep '(apache|httpd)'

Ignore root, but look at the other users

root      2507  0.0  0.3 423820 14328 ?        Ss   Aug04   0:51 /usr/sbin/httpd
apache    4653  0.5  1.9 483900 77252 ?        S    16:27   0:14 /usr/sbin/httpd
apache    4654  0.5  2.1 500160 84912 ?        S    16:27   0:13 /usr/sbin/httpd
apache    4656  0.8  2.0 484708 78712 ?        S    16:27   0:21 /usr/sbin/httpd
...

For me it actually was apache (usually www-data). Finally change the users of the uploads folder to this user;

sudo chown -R apache:apache uploads

(make sure you are in the directory above the uploads folder when running this command)

This will permit the correct user to access this directory using the correct access permissions of 755.

By using the dreadful '777' advice of others, you are simply allowing the correct user to access the directory assigned to the incorrect user - as well as anyone else who can access that directory!

myol
  • 8,857
  • 19
  • 82
  • 143
  • After entering `ps aux | egrep '(apache|httpd)'` within `wp-content`, I tried to cd into "uploads" and typed the suggested command in the terminal: `chown -R myusername:myusername uploads` This gave me an error - No such file or directory. Am I misunderstanding how you change the users of the `uploads` file? – HappyHands31 Mar 29 '17 at 18:55
  • 1
    Your command is trying to change files in `uploads/uploads/` which doesn't exist. You need to go up (back) one level. Use `ls` to ensure you can see the `uploads` folder listed before you run the command. – myol Mar 30 '17 at 09:12
  • Went back one level and used `ls` to see the `uploads` folder listed. Tried `chmod 755 uploads` and `sudo chmod 755 uploads` and nothing happened. Then tried `chown -R daemon:daemon uploads` and got this: http://imgur.com/a/vbIun (the red lines are crossing out myfullname). – HappyHands31 Mar 30 '17 at 15:35
  • I don't use a mac but you should take a look at this answer - https://superuser.com/a/518545/364893 You will probably need to use `-R` on each command and change file to `uploads` – myol Mar 30 '17 at 16:19
  • That said, you will need to then reset the permissions on the files as that answer suggests ` Give everyone read-write permission to file` which is exactly what we are trying to avoid – myol Mar 30 '17 at 16:21
  • I got it to work - the key was to just add `sudo` before `chown -R daemon:daemon uploads`. The `chown` command requires super user rights. So `sudo chown -R daemon: daemon uploads`. – HappyHands31 Mar 30 '17 at 18:48
  • 1
    Glad you figured it out, I updated my answer to be more explicit. Thank you. – myol Mar 30 '17 at 20:26
3

Provided that your wordpress directory is "owned" by the correct user, you should see your problem resolved if you set the permissions to 755.

Log on to your server, and cd to wp-content, then run:

chmod 755 uploads
Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
2

I would recommend, for security's sake, instead of

sudo chmod 777 uploads

which gives permissions (read, write, execute) to the user who owns the folder (the root), to other users in the file's Group and to other users not in the file's group (anyone else).

sudo chmod 755 uploads

which gives all permissions to the owner, but only read and execute permissions to the other users

UserK
  • 884
  • 3
  • 17
  • 40
1

For anyone who has landed here but using a Windows / IIS platform then you can achieve the same thing by giving modify permissions to the Everyone group for your wp-content\uploads directory.

permissions dialog

Chris Pickford
  • 8,642
  • 5
  • 42
  • 73
1

another possible reason is wrong owner and group of uploads folder.

try

chown -R _www:_www wp-content/uploads

assuming your apache group and owner is _www

rok
  • 9,403
  • 17
  • 70
  • 126