Server – How to Give Directory Ownership to Apache User

Apache2permissionsserverWordpress

I have installed wordpress on LAMP.
As I am new one to Ubuntu. So, I Used this online tutorial
How to install wordpress on ubuntu manually

But when I am trying to give ownership of the directory to the apache user it's not working
I am giving the following commands

sudo chown admin:www-data /var/www -R 
sudo chmod g+w /var/www -R

"admin" is the name which I choose for my wordpress database user.
Can anyone please guide me through this?

Best Answer

Do not use the database user as the UNIX user. Use www-data.

sudo chown -R www-data:www-data /var/www

There is a difference between the database user and the Apache user. The Apache User is the only one who can actually read the files. The database user is only meant for giving/taking database read/write permissions.

In addition, keep the default permissions from the webapp install. Do not change those, except for the owning user/group. If you are instructed by the webapp, change permissions.


If you are more concerned about security, you could instead run the following commands:

sudo chown -R $USER:www-data /var/www
sudo chmod -R 640 /var/www

This makes the actual files owned by your user, so that only you (and root) can modify them. The reason www-data is referenced is so that Apache can still READ the files, but not actually write to them.

The 640 allows you (the file owner) to read and write, while allowing the www-data group to read files. It also blocks anyone else from possibly reading the file contents.

(The above is only one possible (untested) method. More good ways are available here.)

Related Question