Report this

What is the reason for this report?

Secure VPS and LAMP configuration

Posted on September 4, 2014

Hi,

I need to set up a new Ubuntu server for hosting multiple websites. Which steps should I follow for maximum security and performance?

Specifically:

  • How can I configure Apache, so that each users won’t be able to access each other’s files?
  • And every virtual host runs with a separate user?


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!

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.

@aguilar1181, thanks but it’s not an option now. I need to do it myself and I’m looking for helpful advices

This can be done with a combination of Apache’s mod_userdir and SFTP chroots. To limit an SFTP user to their home directory, you can edit /etc/ssh/sshd_config to include:

Match User username
    ChrootDirectory %h
    AllowTCPForwarding no
    X11Forwarding no
    ForceCommand internal-sftp

Then enable mod_userdir with:

sudo a2enmod userdir
sudo service apache2 restart

Now files in /home/username/public_html will be available at:

http://your.ip.address/~username

hi @asb,

that’s not what I want. I will set up a Virtual host for each client with custom domain name.

If Apache process runs as one single user, like www-data or apache, clients can read each other’s files.

Should I run an Apache process by a separate user for each client? Or should I use chroot jailing for Apache?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.