rss feed Twitter Page Facebook Page Github Page Stack Over Flow Page

Change apache default user

It is a pain to always sudo to change permissions on a folder your script or web page created? If yes, then here's a quick solution for you. With apache, you can (very) easily fix this issue and set the current user (whoami). This will basically change the www-data to the one you prefer.

First, you need to edit the envvars file:

sudo vi /etc/apache2/envvars

and change the APACHE_RUN_USER and APACHE_RUN_GROUP to your user.

export APACHE_RUN_USER=MyUserName
export APACHE_RUN_GROUP=MyUserName

Now, restart apache:

sudo /etc/init.d/apache2 restart

If you get an error like this:

 * Restarting web server apache2       ... waiting /var/lock/apache2 already exists but is not a directory owned by user.
Please fix manually. Aborting.

Don't panic, and change the permission to the apache locks and restart apache:

sudo chown -R myuser:myuser /var/lock/apache2/
sudo /etc/init.d/apache2 restart

Now you will see:

 * Restarting web server apache2  [ OK ]