I just unpacked a fresh install of WordPress 5.2.1… at first I could not upload themes. But this was fixed by chmod 777 wp-content
/uploads.
Then the themes installed via ftp would installed, giving me the error “could not create directory”. I fixed it by doing this:
Just login to your webserver. Then change directory to the root of the wordpress site. And type in the following incantation:
sudo chown -R www-data:www-data .
.. tada! And dont forget the dot at the end of that command.
This fixed my issue on my new WP install on a VPS. Thank you!
It would be helpful if you explained what the command line is doing. I can’t tell who you changed the owner to.
Here you go Lee. I’m the guy that wrote up the answer.
sudo # execute the command using root privileges
chown # change the ownership of the files
-R # do so recursively, meaning in this directory and all directories below it
www-data:www-data # set the owner of the files to the user www-data and the group www-data. You may have to change either or both values based on what user and group your apache server is using on your server.
Hi! I have no idea where to use this code for the same error! Could you help me out? Thanks a bunch.
Raj, login to your server and type the command at the shell prompt:
ssh myusername@myserver.com
shell> cd document_root_of_wordpress_site
shell> sudo chown -R www-data:www-data .
And dont forget there is a dot at the end of that line “sudo chown -R www-data:www-data .”
This is wonderful, and here I was chmodding stuff according to the first hits I got in Google, while researching this problem. Very safe and good solution thx!
I get chown: invalid user: `www-data:www-data’
yes, the user operating the Apache process might be different on your machine.
to see what groups exist on your machine, type:
cat /etc/group | sort
You might need to ask on ServerFault how to find out which user is running the apache process on your machine. On my machine I typed:
ps -eaf | grep apache2
and that showed me the apache user was www-data:
Here is a screenshot of the output of that command:
https://www.evernote.com/l/ATXlO9WzTWpJBIefmyEHUTTGNc2egBFTz7oB/image.png
Just to make things a bit more clear. Even though the error was invalid user, that string `www-data:www-data’ contains the username, a colon, and then the group. So the first step would be to determine the apache user using the command
ps -eaf | grep apache2
And you should see something like below, but not see “www-data” but something else:
https://www.evernote.com/l/ATXlO9WzTWpJBIefmyEHUTTGNc2egBFTz7oB/image.png
Once you determine the user that apache2 is running as, then you can replace the www-data before the colon with that username.
I could be wrong, but doesn’t this allow visitors to execute code on the server, a big security no-no?
you could be right Philip. Can you demonstrate a case of this compromising a server? I ask in genuine curiosity. In fact, the wordpress instance that we are chatting on has that very command executed. Here is a screenshot: https://www.evernote.com/l/ATUhK4bGJkBHipFnisCgN5B9umjyNjZdrlQB/image.png … this machine is backed up everday so if you do manage to hack in, it would just be educational for you and I and the readers of this thread.
Thank you so much for this delightfully simple fix!
Thanks, worked great. Did this to install the update, then changed back to the user/group I had before.
Thanks! your small code helpful for me!
Hallelujah! It still works even now, Oct 20, 2017 — THANK YOU!