3

I get this problem now and then, where I use an FTP account given to me by the host and use them in Wordpress FTP. But for some reason when updating themes for example, the new theme gets created under apache/apache and not user/psacln user name/group. So at that point I can't delete or do anything with those files as I am under psacln group.

I would like to find out more about why this may happen to avoid this problem - any suggestions are welcome!

Thanks in advance.

Sergey
  • 939
  • 1
  • 6
  • 13

2 Answers2

3

When you upload files via the wordpess admin page (like themes) the httpd process running as the apache user is actually creating them on your system--hence why they are owned by the apache user. I suggest this options to work around this:

  1. Add yourself and apache to a new group called 'wordpress'
  2. Use to change group ownership of your wordpress to the new group
  3. Use set the sgid permission bit and the group write permission to all directories in the wordpress docroot.

The setting of the sgid bit will make all files added to a directory be the same group owner.

Assuming you've added yourself and apache to the same group, here's the linux commands to setup the directories to ensure files get created writable to all in the wordpress group:

chown -R :wordpress /path/to/wordpress/docroot/ 
chmod  -R g+w /path/to/wordpress/docroot/
find  /path/to/wordpress/docroot/ -type d -print | while read i; do SAVEIFS=$IFS; IFS=$(echo -en "\n\b");chmod g+s $i; IFS=$SAVEIFS; done

Additional thing that may be needed:

If you see apache creating files with group permissions without write, you may need to change the default umask for the apache user for creation of new files. By default it should be owner and group write allowed, but I know some accounts (like root user) have the default umask set to be group read only.

Ray
  • 40,256
  • 21
  • 101
  • 138
  • 1
    Thanks for the commands! But you see, 90% of the time I have no control over the server environment (e.g no shell access) as clients are likely to run something cheap with Namesco etc. I guess this would be one way to fix the problem - but surely, I am not the only one and there has to be a way that works in a limited environment without root access. – Sergey Mar 03 '13 at 18:50
  • 1
    So why does scumbag Wordpress do it this way? I have to download the folder and re-upload it via FileZilla just so I can work with those files, hmm... – Sergey Mar 03 '13 at 18:57
  • 1
    See also http://stackoverflow.com/questions/1113691/a-general-linux-file-permissions-question-apache-and-wordpress. – pbhj Jul 28 '14 at 10:57
0

because apache's worker children run under apache's userid, and a "common user" on a unix system cannot make files be owned by some OTHER user. Only the root account can "give away" ownership.

Why? It'd be trivial for a normal user to make a file owned by root, or owned by another user. If a given system was running with user quotas, this would allow a user to completely subvert the quotas, or deny someone else access by "giving" them a bunch of huge files and exceeding that user's quota.

If you need access to those files, regardless of the unix ownership, you could look into using POSIX acls, which exist above/beyond the unix permissions.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Cheers! Yes, this makes sense. However in most cases I face this problem in a limited environment (on client's shared hosting) - and so I don't have access to any fancy commands / set permissions myself. – Sergey Mar 03 '13 at 18:52