Lighttpd on Cpanel VPS
Posted on | March 28, 2007 | 15 Comments
Working on a new project for a client, I need to run Django/Satchmo. At my advice, the client purchased a VPS from LiquidWeb to run it on.
The problem is that I want to run with Python 2.5 instead of 2.4, and I don’t want to use Apache 1.3. Unfortunately, that’s what comes stock with CPanel. So, I came up with a decent workaround that I haven’t seen documented anywhere else.
What I did was to set up Lighhtpd on one of the other IPs provided with the account, and I simply use my custom-compiled Python with that.
Step by step instructions
Step 1 – Add a new user
Login to your WHM instance and add a new user. Do not check the "IP" checkbox. We’ll be faking out CPanel on this one.
Step 2 – Plan your IP usage
2) Using WHM, go to IP Functions/Show IP Address Usage. The first IP should be the IP you used to get to WHM. I’ll call that your "Base IP". Pick any of the other unused IPs and note that for the next step. That’s where you’ll be binding Lighttpd.
Step 3 – Update your DNS
3a) Using WHM, go to DNS Functions/Edit DNS Zone. Note that you should have (at least) two. One is the domain for WHM and the other is your new domain. On Liquidweb, these are "host.yourdomain.com" and "yourdomain.com".
3b) Edit the DNS Zone for "yourdomain.com". Change "mail.yourdomain.com" from "CNAME" "yourdomain.com" to "CNAME" "host.yourdomain.com" (which you noted above). This will keep mail going to the IP for your WHM instance, which is where CPanel is expecting it to go.
3c) Continuing to edit the zone, change the "a" record for "yourdomain.com" from the base IP to the IP you’ll be using for Lighttpd.
3d) Save.
3e) Watch out for the gotcha. You have to be using your own VPS as the private nameserver for your domain or this won’t work. Your VPS provider should have instructions for how to tell your domain registrar to register a private nameserver. It is very common, but not as widely understood as I might hope. If you can’t do this, then you’ll just assign IPs using whatever nameserver you are already using, and CPanel wouldn’t be managing your IPs anyway.
Step 4 – Get root
4) You want to get yourself "sudo" rights as the new user you added in step 1. Do this by logging in as root (your WHM user) on the base IP. Then run "visudo". Find the line that says "root ALL=(ALL) ALL" and add a new line after it that says "YOURUSERNAME ALL=(ALL) ALL". Of course, substitute the user name from step 1 here.
Step 5 – Build and install Lighttpd
5a) Login to the base IP as the username from step 1.
5b) Get the lighttpd tarball, and build.
$ wget http://www.lighttpd.net/assets/2007/1/29/lighttpd-1.4.13.tar.gz
$ tar xzf lighttpd-1.4.13.tar.gz
$ cd lighttpd-1.4.13
$ ./configure --with-openssl && make
$ sudo make install
Step 6 – Disable Apache on the Lighttpd IP
6a) Right now, Apache is listening on all your IPs, you need to stop it being so greedy. Edit /etc/httpd/httpd.conf
$ sudo vi /etc/httpd/httpd.conf
Search for "Listen", then add "Listen 1.2.3.4:80" after that line. Substitute your "Base IP" for the 1.2.3.4.
6b) Restart Apache
$ sudo /etc/init.d/httpd restart
Step 7 – Bind Lighttpd to your chosen IP.
7) Edit /etc/lighttpd/lighttpd.conf and substituting your lighttpd IP for 1.2.3.4, add:
server.bind = "1.2.3.4"
Step 8 – Add an init script for Lighttpd
8a) I couldn’t use the init script that came with the Lighttpd distribution, since it was written for LSB, and my VPS has a Red-hat based init system so I wrote my own, feel free to use or improve it. Put something like this at /etc/init.d/lighttpd
#! /bin/sh
# Copyright (c) Bruce Kroeze brucek@solidsitesolutions
# All rights reserved.
#
# Provides: lighttpd
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: Start lighttpd
LIGHTTPD_CONFIG=/etc/sysconfig/lighttpd
test -r $LIGHTTPD_CONFIG || exit 6
. $LIGHTTPD_CONFIG
test -x $LIGHTTPD_BIN || exit 5
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo "Could not find functions file, your system may be broken"
exit 1
fi
case "$1" in
start)
echo -n "Starting lighttpd"
daemon $LIGHTTPD_BIN -f $LIGHTTPD_CONF_PATH
echo
;;
stop)
echo -n "Shutting down lighttpd"
killproc lighttpd
echo
;;
try-restart)
$0 status >/dev/null && $0 restart
;;
restart)
$0 stop
$0 start
;;
force-reload|reload)
echo -n "Reload service LIGHTTPD"
killproc -INT lighttpd
$0 start
touch $LIGHTTPD_PID_FILE
;;
status)
echo -n "Checking for service LIGHTTPD: "
status lighttpd
;;
probe)
test /etc/lighttpd/lighttpd.conf -nt $LIGHTTPD_PID_FILE && echo reload
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
exit 1
;;
esac
exit
8b) That script requires a config file at /etc/sysconfig/lighttpd. Here’s mine:
LIGHTTPD_CONF_PATH=/etc/lighttpd/lighttpd.conf
LIGHTTPD_PID_FILE=/var/run/lighttpd.pid
LIGHTTPD_BIN=/usr/local/sbin/lighttpd
8c) Install the init script with "sudo chkconfig –add lighhtpd"
Done! Start testing.
Technorati Tags: lighhtpd, cpanel, liquidweb, vps
Comments
15 Responses to “Lighttpd on Cpanel VPS”
Leave a Reply
March 28th, 2007 @ 12:08 pm
Why LiquidWeb as opposed to the one you chose for yourself, Rimuhosting?
March 29th, 2007 @ 7:23 am
I gave him both choices, and he went with LiquidWeb. They’re hard to beat when it comes to service.
More importantly, Rimuhosting is an *unmanaged* service, while LiquidWeb is *managed*. Need that SSL cert installed? Need daily backups? Need 24/7 tech support who will make needed changes? Then use a managed service.
?March 29th, 2007 @ 8:51 pm
Hi Bruce,
Thank you very much for posting your story and offering Liquid Web to your client. We really appreciate the kind words! Shoot me an email and I would be glad to give you a referral credit for the purchase if you are interested.
May 7th, 2007 @ 5:12 am
Have you considered putting lighttpd behind apache’s mod_proxy? Should make the IP setup simpler.
May 7th, 2007 @ 10:34 pm
I might just try that Erik. It hadn’t occurred to me, to be honest. I just get so fed up with how annoying Apache is to manage and configure so I thought I’d skip it.
The IP allocation problem does worry me, especially on the dedicated host where I have many more IPs , sites, and where I share with my partners.
?May 25th, 2007 @ 7:44 pm
If you need a CP that supports both lighty and apache natively, you can check out http://lxlabs.com/software/lxadmin-sse/
Thanks.
November 12th, 2007 @ 10:28 am
[...] Lighttpd on Cpanel VPS Tags: none Related posts: [...]
January 3rd, 2008 @ 3:20 pm
[...] cPanel is a leading provider of software for the webhosting industry. If you would like to learn more about cPanel please visit our website at … (link) [...]
March 23rd, 2008 @ 7:16 pm
Great tutorial, exactly what I was looking for.
As a side note, I’m a strong supporter of LiquidWeb, glad to see another fan out there.
I’ve been using LiquidWeb for coming on two years now, they’ve been a great host.
June 26th, 2008 @ 8:58 am
Thanks for taking the time to write this.
I’ve got a VPS from Liquidweb with cPanel
I get hung up on step 6. In my httpd.conf is a slightly different location:
/etc/httpd/conf/httpd.conf
I have the following lines in my cofig file:
# Defined in /var/cpanel/cpanel.config: apache_port
Listen 0.0.0.0:80
I tried adding my base url after this line and all my sites stopped working. Do I replace the 0.0.0.0? Do I edit the /var/cpanel/cpanl.config file?
June 26th, 2008 @ 9:57 am
I believe you would comment out that 0.0.0.0 line.
?June 7th, 2009 @ 5:54 pm
hey
this is not working lol.
i modified apaches httpd conf correctly to that remote ip but then lighty says that addr already on use. why ? that now
June 16th, 2009 @ 10:42 am
Did you restart Apache after removing the IP you want Lighty to use?
?June 23rd, 2009 @ 11:02 am
I configured lighty
IP:80
Apache too
But then apache not starts it says Addres already in Use.
Sure i try it to restart Apache the Same Error
August 14th, 2009 @ 1:03 pm
Hi how would i configure lighttpd to stream media using whm cpanel