views:

256

answers:

3

Hi everybody, I have been administering a few LAMP servers with 2-5 sites on each of them. These are basically owned by the same user/client so there are no security issues except from attacks through vulnerable deamons or scripts. I am builing my own server and would like to start hosting multiple sites. My first concern is... ISOLATION. How can I avoid that a c99 script could deface all the virtual hosts? Also, should I prevent that c99 to be able to write/read the other sites' directories? (It is easy to "cat" a config.php from another site and then get into the mysql database) My server is a VPS with 512M burstable to 1G. Among the free hosting managers, is there any small one which works for my VPS? (which maybe is compatible with the security approach I would like to have) Currently I am not planning to host over 10 sites but I would not accept that a client/hacker could navigate into unwanted directories or, worse, run malicious scripts. FTP management would be fine. I don't want to complicate things with SSH isolation.

What is the best practice in this case? Basically, what do hosting companies do to sleep well? :)

Thanks very much! David

+1  A: 

Check out ITK MPM for Apache 2.x: http://mpm-itk.sesse.net/

I am using it on a number of busy sites for a couple of years now, without any problems.

sanmai
mpm-itk's only downside is that it runs as root before the privilege drop.
LiraNuna
yeah, to overcome this it uses POSIX capabilities to run itself with lowest privileges possible
sanmai
+1  A: 

you should use the PHP directive open_basedir in your Apache Configuration for each Virtual Host by adding this line :

<VirtualHost x.x.x.x:80>
ServeName www.example.com
DocumentRoot /path/to/your/virtualroot
...
... usual stuff ...
...
php_admin_value open_basedir /path/to/your/virtualroot:/some/other/path
</VirtualHost>

this will limit all your PHP processes to access only this (or these) path on your filesystem. Opening files on other locations will be forbidden, even by chdir() or using symbolik links.

You can also provide this directive at runtime with ini_set() since PHP5.3.0 but imho it's better to apply this directly in your vhosts.conf file(s).

PHP Manual

ifZenElse
+1  A: 

For ultimate isolation, consider lightweight virtualization (OpenVZ on Linux, FreeBSD jails or similar). It's similar to orginary virtual machines, but shares the kernel and therefore doesn't bear the overhead of complete virtualization. The lightweight VMs can also share the disk space in a cooperative manner instead of using a separate disk image each, and can all use single copies of the same files. The drawback is that lightweight VMs always run the same kernel, i.e. you can't run one OS within another, which doesn't seem to be an issue for you.

Alexey Feldgendler
I second this because I have seen too many shared hosting environments go down because of a script running wild, or hitting a memory leak. Things like that are much easier to control in a virtualized environment. Also, it is much better scalable: If a customer needs more resources, you just take their virtual machine and move it to a bigger server. No moving hassle, done in 15 minutes. Virtualization is great.
Pekka