Chrooting Apache2 With mod_chroot On CentOS 5.4
|
Submitted by falko (Contact Author) (Forums) on Wed, 2010-07-21 16:52. :: CentOS | Apache | Security
Chrooting Apache2 With mod_chroot On CentOS 5.4Version 1.0 This guide explains how to set up mod_chroot with Apache2 on a CentOS 5.4 system. With mod_chroot, you can run Apache2 in a secure chroot environment and make your server less vulnerable to break-in attempts that try to exploit vulnerabilities in Apache2 or your installed web applications. I do not issue any guarantee that this will work for you!
1 Preliminary NoteI'm assuming that you have a running CentOS 5.4 system with a working Apache2, e.g. as shown in this tutorial: The Perfect Server - CentOS 5.4 x86_64 [ISPConfig 2]. In addition to that I assume that you have one or more web sites set up within the /var/www directory (e.g. if you use ISPConfig).
2 Installing mod_chrootThere's no mod_chroot package for CentOS 5.4, therefore we must build it ourselves. First we install the prerequisites: yum groupinstall 'Development Tools' yum groupinstall 'Development Libraries' yum install httpd-devel Now we build mod_chroot as follows: cd /tmp Then we restart Apache: /etc/init.d/httpd restart
3 Configuring ApacheI want to use the /var/www directory as the directory containing the chroot jail. CentOS' Apache uses the PID file /var/run/httpd.pid; when Apache is chrooted to /var/www, /var/run/httpd.pid translates to /var/www/var/run/httpd.pid. Therefore we create that directory now: mkdir -p /var/www/var/run Now we must tell Apache that we want to use /var/www as our chroot directory. We open /etc/httpd/conf/httpd.conf, and right below the PidFile line, we add the line ChrootDir /var/www; also comment out the PidFile run/httpd.pid line and add the line PidFile /var/run/httpd.pid: vi /etc/httpd/conf/httpd.conf
Next we must tell our vhosts that the document root has changed (for example, a DocumentRoot /var/www translates now to DocumentRoot /). We can do this either by changing the DocumentRoot directive of each vhost, or more easier, by creating a symlink in the file system. 3.1 First Method: Changing The DocumentRootLet's assume we have a vhost with DocumentRoot /var/www. We must now open the vhost configuration of that vhost and change DocumentRoot /var/www to DocumentRoot /. Accordingly, DocumentRoot /var/www/web1/web would now translate to DocumentRoot /web1/web, and so on. If you want to use this method, you must change the DocumentRoot for every single vhost.
3.2 Second Method: Creating A Symlink In the File SystemThis method is easier, because you have to do it only once and don't have to modify any vhost configuration. We create a symlink pointing from /var/www/var/www to /var/www: mkdir -p /var/www/var Finally, we have to stop Apache, create a symlink from /var/run/httpd.pid to /var/www/var/run/httpd.pid, and start it again: /etc/init.d/httpd stop ln -sf /var/www/var/run/httpd.pid /var/run/httpd.pid That's it. You can now call your web pages as before, and they should be served without problems, as long as they are static HTML files or using mod_php. If you are using CGI, e.g. Perl, suPHP, Ruby, etc., then you must copy the interpreter (e.g. /usr/bin/perl, /usr/sbin/suphp, etc.) to the chroot jail together with all libraries needed by the interpreter. You can find out about the required libraries with the ldd command, e.g. ldd /usr/sbin/suphp [server2:/var/www/web1/log]# ldd /usr/sbin/suphp If you've copied all required files, but the page still isn't working, you should take a look at the Apache error log. Usually it tells you where the problem is. Also read http://core.segfault.pl/~hobbit/mod_chroot/caveats.html for known problems and solutions.
4 Links
|
www.seamlessenterprise.com
One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com
One Number. One Voicemail.
Make it easier for clients to reach you. Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com
One number. One voicemail. Sprint Mobile Integration.
www.seamlessenterprise.com
One number. one voicemail. Seize the lead with Sprint. Learn more
AT&T Synaptic Compute as a Service. Boost your power on demand.
Trial: IBM Cognos Express Reporting, Analysis & Planning
Learn benefits of Simpana software.
View the Gartner Video
Sprint 4G - The Ultimate Mobile Broadband
Click here
SAP-Business Objects Crystal Reports Server
Complete reporting without hidden costs. Free Trial









Recent comments
20 hours 46 min ago
1 day 32 min ago
1 day 5 hours ago
1 day 8 hours ago
2 days 12 hours ago
2 days 12 hours ago
2 days 12 hours ago
2 days 12 hours ago
2 days 13 hours ago
2 days 21 hours ago