Replacing Apache with Litespeed
April 07, 2007
Updated 4th May ’07
I’ve been running this site and several others (personal sites, desktop modding communities etc.) on my VPS since I first made the move over to PowerVPS about 8 months ago.
It’s been fantastic, the knowledge you gain from managing your own server is quite something and you come to appreciate the various bottlenecks that can affect site performance.
One of which is Apache, the web-server that serves all of the requests. I’ve been looking to replace it for a while but found that because I use cPanel replacements can be tricky, because most alternative servers lack similar features or they’re unable to read the httpd.conf that cPanel updates when adding/removing accounts or sub-domains.
That is, until I discovered Litespeed which since it’s 3.x release (and possibly earlier) offers easy integration with cPanel and several other control panels. Now, there are numerous enterprise versions which have additional features and can scale with multiple processors, but the standard version still offers quite huge performance increases over Apache in high concurrency environments.
You can see a list of the features here but the one that makes this server special is it’s support for standard httpd.conf files to use in configuration. It will even live update so if a change is made in cPanel it will be reflected in the Litespeed server. It logs to the same places as well so bandwidth monitoring and stats packages such as AwStats will still work without a problem.
If you read on I’ll detail how to get this up and running on your cPanel server…
Basic Installation
So… the first thing you need to do is SSH into your server, move to any folder you like and then download Litespeed using wget or curl (substitute the link for the latest version for your platform), then decompress the package, change into the installation directory and run the installer:
wget http://litespeedtech.com/packages/3.0/lsws-3.0.1-std-i386-linux.tar.gz
tar -xvfz lsws-3.0.1-std-i386-linux.tar.gz
cd lsws-3.0.1
./install.sh
Run through the installer but make sure to NOT import Apache configuration, that comes later.
Note - ck made a good point that you’ll need to open the port 7080 and also whatever port you chose for testing purposes. I recommend (like ck) that you use csf which is a terrific security and firewall application. If you don’t have that then you will need to edit your conf.apf file, normally found in /etc/apf/
Once you’re done and it’s up and running you’ll want to go to the admin console ( http://serverip:7080 ), log-in and then go to the “server” → “general” tab. In the “Using Apache Configuration File” table change the following:
Load Apache Configuration => Yes
Auto Reload On Changes => Yes (Changes made in WHM/cPanel will be applied automatically)
Apache Configuration File => /usr/local/apache/conf/httpd.conf
Apache Port Offset => 1000 (Try LiteSpeed on port 1080 and 1443 first, change to 0 later)
You can also optionally choose to enable PHP suEXEC for additional security.
Next you should restart Litespeed and try your sites on port 1080 to see if they’re all working okay. If they are, then stop apache /etc/rc.d/init.d/httpd stop change the Apache Port Offset you edited earlier back to 0 and restart Litespeed.
That’s it! Your sites are now being served with Litespeed.
Completely disable Apache
Now to make sure cPanel doesn’t rain on your parade it’s also worthwhile to disable httpd in the service manager inside the WHM, that way it won’t be automatically restarted or monitored. Also, to make sure Apache isn’t started when the server is rebooted you will want to do the following:
- Find chkconfig using this command
locate chkconfig - Change into the directory where it’s located.
- Run this command
./chkconfig httpd off
PHP
By default Litespeed comes with PHP 4.4.x compiled with LSAPI. This is Litespeeds way of communicating with PHP and it’s much more efficient than mod_php or fast_CGI so it’s recommended you use this. Now, odds are it’s not got the right configuration and it doesn’t have your PHP.ini either, it’s using it’s own. So here’s how to compile your own PHP for Litespeed with LSAPI and then drop in your old PHP.ini with your settings in.
First, move to a suitable directory, download the version of PHP that you want, in this case I’m using PHP 5.2.1 (you can find download links on PHP.net ) and then decompress it:
wget http://uk3.php.net/get/php-5.2.1.tar.gz/from/this/mirror
tar -zxf php-x.x.x.tar.gz
Then change directory cd into php-source/sapi directory
cd php-x.x.x/sapi
I will refer to this unpacked php src directory as “/php-source/”.
Now, download and expand the latest LSAPI for PHP from this site http://www.litespeedtech.com/products/webserver/lsapi/ (make sure you’re in the /php-x.×.x/sapi directory)
wget http://www.litespeedtech.com/packages/lsapi/php-litespeed-3.x.tgz
tar -zxf php-litespeed-3.x.tgz
Change directory to root PHP source directory and run:
cd ..
touch ac*
./buildconf --force
Then you can configure and build PHP with whatever options you need, DON’T include –with-apxs or –with-apxs2 as these are for Apache. Also make sure to include --with-litespeed in the configuration line as well. An example:
./configure '--prefix=/php5' '--with-litespeed' '--with-config-file-path=../php' --with-mysql ...
make
make install
We’re nearly done now :) Finally you need to copy the lsphp binary that was created into your litespeed installation:
Remember – php-source refers to the php-x.×.x/sapi directory we looked at earlier, and lswsinstall refers to where you installed litespeed.
cd /lswsinstall/fcgi-bin/
mv lsphp lsphp.old
cp /php-src/sapi/litespeed/php lsphp
If you want to use your old PHP.ini you can copy that over too: (the path may not be exactly the same, you’ll need to check)
cd /lswsinstall/php/
mv php.ini php.ini.old
cp /usr/local/ZEND/etc/php.ini
All you need to do now is restart Litespeed and you’re done! A freshly compiled PHP, a lightening fast server… not bad for 10-20 minutes of work :)
Feedback?
If you’ve found errors or have some feedback please . Comments aren’t currently enabled due to spam but I’m sure they’ll return in the future.