0

Basically, I was trying to fix an issue where I couldn't upload images to my newly migrated WordPress site. The site is on a VPN and I found this article, http://2surge.com/how-to-fix-the-uploaded-file-could-not-be-moved-to-wp-content-error-message/, which gave the following solution: Execute the following command as root user to give Apache user ownership of WordPress files:

chown -R nobody /home/<username>/public_html

But I think I should have given ownership to the WP directories within my main directory. Instead, I gave the Apache user ownership of my public_html folder. And now I can't access public_html via ftp. I get the error: Failed to Return Directory Listing.

Can I simply change the owner back to the original system user using the same command like so:

chown -R originaluser /home/<username>/public_html

Or is that oversimplifying a concept I have a very rudimentary and patchy grasp of?

Arf
  • 3
  • 3

1 Answers1

1

Yes, you could change the user back, no problem. However, this probably will block the uploading of images again.

I guess that your problem is that you have 2 services - Apache and FTP, running under different users (e.g. apache running from user nobody).

In this case I would advise you that you should create a user group and give a permissions to that user group on the folder you need (I suggest that it should be /wp-content/uploads/).

For example:

# create new group:
groupadd webservices
# add apache user (nobody) to this new group
usermod -a -G webservices nobody
# add ftp user (?) to this new group
usermod -a -G webservices <ftp user>
# add yourself to this group (in case you need to access the folder from non-root account)
usermod -a -G webservices <myself>

Now you need to set a user and group for this folder and give correct group permissions to that folder (recursively).

For example:

# change the folder ownership
chown -R nobody:webservices /path/to/wp-content/uploads/
# and set group permissions to be the same with user permissions:
chmod -R g=u /path/to/wp-content/uploads/

Now both apache and ftp users will have the same rights for this folder and its contents, since both users are in the webservices group (and the webservices group has correct permissions, which are copied user permissions).

See also:

What permissions should my website files/folders have on a Linux webserver?

https://serverfault.com/a/284478/118677

man chown

man chgrp

man chmod

Andrey Sapegin
  • 1,191
  • 2
  • 11
  • 27
  • So my plan was to change the user back and then put all my wordpress files in a folder within my main directory, and then grant apache user ownership of just those files. Can I create a user group as you suggested without messing with the ownership of that folder again and or should I change the owner back to the original user and then create a new user group? – Arf Jun 04 '15 at 18:36
  • Sorry, I'm not sure if I understand you correctly. Creation of user group, user ownership, group ownership, user permissions and group permissions are "independent" operations. So (1) you can create any groups any time you want in the system, it has no effect on the folder/permission until you set the ownership using this new group; (2) you do not need to switch the user back before changing group/user ownership/permissions; (3) you probably need to read the documentation about users, groups, permissions and ownership. https://help.ubuntu.com/community/FilePermissions is valid for any Linux OS – Andrey Sapegin Jun 05 '15 at 08:08