Friday, January 21, 2011

Directory sharing between Apache and a user

There are times when a user needs to maintain files in a directory managed by Apache. This would usually be a folder created via the web server and is therefore owned by that web server, the www-data or nobody user.

There is more than one way to allow another user access to that directory and the one I prefer is to ensure that the Apache user has a umask of 002 and to add the user to the Apache group.

These are the steps I took on Ubuntu 10.4 LTS:-

sudo echo 'umask 002' >> /etc/apache2/envvars
sudo usermod -a -G www-data username
sudo apache2ctl restart

The location of the envvars file can be found by inspecting /etc/init.d/apache2 (or maybe /etc/init.d/httpd).

These are the steps I took on a Virtual Private Server at Servint (as root):-

echo 002 > /var/cpanel/easy/apache/rawenv/umask
echo 'umask 002' >> /usr/local/apache/bin/envvars
usermod -a -G nobody username
/etc/init.d/httpd stop
/etc/init.d/httpd start

As this is a managed server and the envvars file is recreated by a script when Apache is rebuilt, I had to update both /var/cpanel/easy/apache/rawenv/umask and /usr/local/apache/bin/envvars. The first is to include the umask setting in the automated creation of envvars and the second was to do a manual insert before restarting the web server.

No comments:

Post a Comment