Unable to Create Directory wp-content/uploads
Having problems with WordPress upload directory. Wanted to just go in there and mkdir, change to 777 – but that’s not really solving the problem. Also not very secure.
I had installed WordPress on AWS Amazon Linux. I checked wordpress.org and found out what the directory and file permissions should be (source).
They state folders should be 755 and files should be 664 at most (666 maybe if using the WP editor, but then they should be changed back to 664.)
So I ran the following commands:
sudo find /path/to/my/files/wordpress -type d -exec chmod 755 {} +
sudo find /path/to/my/files/wordpress -type f -exec chmod 664 {} +
(With thanks to source)
I went back into WordPress and tried to upload the file again. But nope. Not working yet. I checked out the server and I saw that no uploads directory yet existed in wp-content. I was going to make that directory, but then I decided against it. I would rather that WP be able to make the directory itself if it needed it. So since the permissions were correct, I decided to run
ls -lah
to see the user of the files. Sure enough, all the files were created by nobody. I decided that the problem must be that these files were not owned by the web server. Therefore, the solution was to change the ownership of all the files to the web server.
The first step was to find out what the username of my web server was. So I ran this command:
cat /etc/passwd
(Which I found here)
I saw many users including apache, mysql, mail, ftp, nobody and more. Clearly apache was my guy. So I went and recursively chowned the ownership of my wordpress directory to apache.
I used the info on this page (which is basically just a Linux manual page for chown) to accomplish this. I came up with:
sudo chown -R apache /path/to/my/files/wordpress
The result? SUCCESS! I was immediately able to start uploading files.