hosted by liquidweb

Go Back   Web Hosting Talk : Web Hosting Main Forums : Web Hosting Talk Tutorials : VPS Tutorials : How to replace Apache with Lighttpd on Cpanel

Forum Jump

How to replace Apache with Lighttpd on Cpanel

Reply Post New Thread In VPS Tutorials Subscription
Send news tip View All Posts Thread Tools Search this Thread Display Modes
Join Date: Oct 2011
Location: /usr/bin/php
Posts: 111

How to replace Apache with Lighttpd on Cpanel

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:
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 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: 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:
mkdir includes
and create the mime.conf, optimizations.conf, php.conf and hosts.conf files in the includes directory. Chmod them to 644:
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.

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"
server.event-handler = "linux-sysepoll"
server.max-fds = 32768 = "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

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" => (
To get the bin-path, just run
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.

$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:
/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:
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.


Sponsored Links

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to replace apache prefork to apache worker on Centos 5?? toy_boy Hosting Security and Technology 5 09-09-2009 12:59 AM
Requires Lighttpd expertise: Apache Rewrite Rules to Lighttpd format realrena Employment / Job Offers 2 01-16-2008 08:46 PM
lighttpd and apache with cpanel or directadmin jon-f Hosting Security and Technology 0 06-21-2007 01:35 AM
Apache + Lighttpd on cPanel ntfu2 Employment / Job Offers 3 10-14-2006 05:39 PM
Need help - lighttpd + apache + cpanel sytker Hosting Security and Technology 8 02-19-2006 05:32 PM

Related posts from
Title Type Date Posted
Nginx to be Included in Upcoming Ubuntu Release Web Hosting News 2014-01-08 15:17:12
GoDaddy Supports cPanel as Part of Web Hosting Updates Web Hosting News 2014-05-09 12:40:20
What's New at cPanel: IPv6 and 1:1 NAT Support Web Hosting News 2013-10-01 18:12:07
Researchers Urge System Admins to Check for New Apache Web Server Backdoor Malware Web Hosting News 2013-05-01 11:35:53
cPanel & WHM Software 11.36 Reaches Stable Tier Status Web Hosting News 2013-04-09 11:44:33

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Log in with your username and password

Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Web Hosting News:
WHT Membership
WHT Membership



Welcome to

Create your username to jump into the discussion! is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.

(4 digit year)

Already a member?