Allows you to search a variety of questions and answers
12-13-2009, 11:47 AM
Lighttpd is another free webserver that is becoming more popular due to it's performance boosts over Apache and thus improving the overall server performance. This guide will show you how it's possible to replace Apache with Lighttpd while running CPanel.
Things to do prior to making the switch:
1. Make sure to recompile Apache with fastcgi support. This can be done via WHM --> Apache Configuration.
2. This setup is better for servers with a few large sites than a host with many smaller sites as a Shared host would have. If Apache is working fine, there is no need to do this.
3. If you need to have sites with SSL enabled, it will be a little trickier and will not be covered in this how-to. You can reference this link for more details: http://redmine.lighttpd.net/wiki/1/Docs:SSL.
4. When creating accounts after making the switch to Lighttpd, you will still use the Create Account feature, but since httpd will not be running, you will have to manually add the virtual host details to the lighttpd.conf file or hosts.conf as we will have in this example.
Step 1
Download and compile Lighttpd:
1. First get the source from www.lighttpd.net and follow the instructions there.
2. To configure: ./configure --with-openssl --with-zlib --with-bzip2 --with-memcache
NOTE: may need to install pcre-devel (yum install pcre-devel)
3. Follow the instructions here to get lighttpd configured after the install: http://redmine.lighttpd.net/projects...tallFromSource. You may need to change the path in /etc/init.d/lighttpd file to /usr/local/sbin/lighttpd for it to start.
4. Configure the lighttpd.conf file in /etc/lighttpd/. Example of a working lighttpd.conf:
server.modules = ( "mod_fastcgi", "mod_rewrite", "mod_dirlisting", "mod_auth", "mod_setenv", "mod_status" )
server.document-root = "/usr/local/apache/htdocs"
server.errorlog = "/etc/lighttpd/error.log"
server.username = "nobody"
server.groupname = "nobody"
index-file.names = ( "index.html", "index.htm", "index.php" )
server.tag = "Web Services"
status.status-url = "/lighttpd-status"
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
server.port = 80
include "includes/mime.conf"
include "includes/optimizations.conf"
include "includes/php.conf"
include "includes/hosts.conf"
You can get the server.document-root from the existing httpd.conf file for Apache for the main VirtualHost.
5. In the /etc/lighttpd directory, create the includes directory:
Code:
mkdir includes
and create the mime.conf, optimizations.conf, php.conf and hosts.conf files in the includes directory. Chmod them to 644:
Code:
chmod -R 644 includes
run this command within the /etc/lighttpd directory.
6. Now we need to populate the created conf files that lighttpd will load upon startup.
mime.conf:
mimetype.assign = (
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar",
"" => "application/octet-stream"
)
optimizations.conf:
server.event-handler = "linux-sysepoll"
server.max-fds = 32768
server.network-backend = "linux-sendfile"
server.max-connections = 8192
server.max-keep-alive-requests = 15
server.max-keep-alive-idle = 15
server.max-read-idle = 15
server.max-write-idle = 15
server.max-worker = 1
The 'server.max-worker' variable should be changed according to how many CPUs the server has, and if it's a 64bit system. If it's a 32bit system, and the load stays low, keep it at 1. To get rid of keep-alive, set both of the keep-alive lines to 0. Max connections can be alterted to your needs
php.conf:
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket-" + var.PID,
"bin-path" => "/usr/bin/php-cgi",
"max-procs" => 20,
"idle-timeout" => 10,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "20",
"PHP_FCGI_MAX_REQUESTS" => "500" ),
)
)
)
To get the bin-path, just run
Code:
whereis php-cgi
and that will show you the path. You have to compile Apache with fastcgi support first via WHM as mentioned previously. PHP can run as DSO/CLI still via WHM.
hosts.conf:
$HTTP["host"] =~ "^(www\.|)domain\.com$" {
server.document-root = "/home/domain/public_html/"
}
$HTTP["host"] =~ "^(www\.|)domain2\.com$" {
server.document-root = "/home/domain2/public_html/"
}
Adjust this file to your needs. Look at your Apache's httpd.conf file and setup each vhost using the above templates for each domain/subdomain you have in httpd.conf. If you wish to add logs to each domain, you can add the following lines to each one of the vhosts above between the {} brackets:
server.errorlog = "/var/log/lighttpd/domain/error.log"
accesslog.filename = "/var/log/lighttpd/domain/access.log"
server.error-handler-404= "/e404.php"
Now you should be all done with the main lighttpd configuration, so go ahead and turn it on:
Code:
/etc/init.d/lighttpd start
.
7. Now we need to turn off Apache so it does not start on boot or start by Cpanel. To do this, login to WHM and go to Service Manager, then uncheck both of the boxes for httpd. You can also run the following command to turn it off via shell:
Code:
chkconfig httpd off
. This will ensure Apache won't start.
At this point, you should be running completely on lighttpd. Everything else in Cpanel/WHM will work as usual (mysql, dns, email, etc..). If you need to recompile php, you can do so via Apache Configuration, just be sure to turn off Apache again after you recompile.