Skip to main content

Apache - Change www-data user

Did you ever had situation on your local Ubuntu enviroment, when your PHP script or other Apache library could not modify some files due to permissions problem? Or maybe you couldn't modify some automatically generated files by PHP, Apache? You've used workaround with chmod and chown? There is a better way to do that.

The reason of similar problems is that you work as other user than Apache. Both may have other permissions. First, check your Apache process:

ps -aux | grep apache
> www-data     3780  0.0  0.3 577456 65096 ?        S    lut14   0:01 /usr/sbin/apache2 -k start

First column is user, owner of this process. So anytime Apache will create files on your local system, permissions will be granted to www-data user by default. Now check your user name:

> scriptun

My user is scriptun, and Apache use www-data, see the difference?

Apache is runned by www-data user by default. It's really convenient and safe to change www-data to your user on your local enviroment. When Apache will work as same user as you, you will never have access problems.

Find envvars file and edit it. You can use gedit for Gnome or kate for KDE, or VIM if you know how to close it:

sudo gedit /etc/apache2/envvars
kate /etc/apache2/envvars

By default, there is www-data user set for Apache, find this part:

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

Put there your username instead of scriptun:

export APACHE_RUN_USER=scriptun
export APACHE_RUN_GROUP=scriptun

Restart apache:

sudo service apache2 restart

And check processes:

ps -aux | grep apache
> scriptun     8450  0.0  0.1 495276 17568 ?        S    00:11   0:00 /usr/sbin/apache2 -k start

Permissions problems gone.

Add new comment


This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

We use cookies on our website to enhance your user experience. We also use Google analytics and ads.

Click here to read more I've read it