LAMP Web Application Ownership and Permissions

I’ve read a lot of articles on the subject of setting ownership and permissions for web servers and found good information, but I still can’t settle on the right answer. Are you able to help?

The scenario:

A small number of low profile websites, all of which need write access for logs, cache, etc. Updates are deployed frequently by using git over SSH. All are sites I have coded and am managing, so it’s only me that accesses the box. The server doesn’t do anything else other than LAMP.

The default position seems to be:

  • Apache/mod_php runs as www-data user
  • File ownership set to root:www-data
  • Permissions set to 755 except for the logs/cache/etc which will be 775.

I could do this by running a deploy script as root that updates the site and resets all the ownership and permissions. I would have to use a long/complex password for every change and adding a file will need chown/chmod.

This is OK, but this seems to be a much more convenient configuration:

  • Create user account web, set Apache/mod_php to run as this user.
  • Store all websites as subfolders of /home/web.
  • Can deploy, edit and update all as user web via SSH without further authentication.
  • Use sudo with strong password for system configuration

The benefits of the former method would be that write permissions are more limited, but if you can write at all then how much does that matter? It might be harder to escalate permissions as www-data than as a user with sudo access, but is brute forcing a strong password a realistic attack?

Can anyone offer advice or an alternative?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Brute force attacks should be a concern but you could easily set the web user to only be accessible via ssh with a key and set up your SFTP client to use the key instead of a password.