Ubuntu – Best way to configure apache2 access rights

14.04Apache2

I have a server with ubuntu 14.04.

I installed apache2,php5 and pure-FTPd.

So apache is running in mpm prefork with one process owned by root and all child processes owned by www-data.

The /var/www/html is owned by root (-rw-r–r– 1 root root)

Now I have a ftp user called ftpuser.

What would be the best way (and more secure) so that the ftpuser can create and edit files under /var/www/html ?

Can I change the group owner of /var/www/html to www-data with write access and add ftpuser to www-data group ?

If now I also want to use mediawiki, it sometimes needs write access to the /var/www/html. So same question : Can I change the group owner of /var/www/html to www-data with write access ?

Best Answer

Usually, it is a bad idea to give write access to the account running the Web Server (www-data under Ubuntu).

For your scenario, I would change the owner of /var/www/html to the ftpuser with a read-write for him, read only for the group and the others. Apache needs at least to be able to read in this directory.

UPD: If you have more than one user to give access to, put them all in the same group, change the group ownership to this group and give the group read & write access too.

Security-wise, it is a bad idea to give Apache write access to all files he can access. If someone is able to do "nasty things" with your web server, at least he won't be able to change the files using Apache directly.

Don't forget to secure the installation of the FTP server you intend to use to let ftpuser upload files.

If Mediawiki needs to write on some files, I would give to these files only the read-write rights for the www-data user (by setting the owner of these files to www-data). If you cannot predict which files need to be writable by the web application, you'd better to isolate this application into a subfolder of ´/var/www/html´.

By experience, I know that when right access is needed on some of the file, usually the documentation of the application details exactly which ones.

Related Question