Litespeed LogoI decided to take the plunge and get rid of Apache for something with a smaller footprint and twice the power: Litespeed.
I got a little tired of having to constantly monitor apache as it frequently took up too much memory and affected other services. Sometimes this resulted in my VPS having services killed off for too much memory usage by Virtuozzo.

As I write this, Litespeed is currently running at 14.4MB RAM usage and 0.1% CPU usage. Compare that to Apache swallowing a whopping 80MB+ or RAM, not to mention CPU time you can probably see why switching over to Litespeed is a good idea!
The main selling point of Litespeed for me was the easy replacement of Apache on a WHM/cPanel server. It’s very easy to configure Litespeed to utilise the Apache configuration files that WHM/cPanel writes to. This has the benefit of being fully integrated into the custom tools that WHM and cPanel use in their respective control panels.

Here’s a very quick guide on how to install it.

wget http://litespeedtech.com/packages/3.0/lsws-3.3-std-i386-linux.tar.gz
tar -xvfz lsws-3.3-std-i386-linux.tar.gz
cd lsws*
./install.sh

Once you’ve run through the configuration interface you can now setup Litespeed to load the Apache configuration file. Login through the new administration interface and click Configuration -> Server. Change the following.

Load Apache Configuration => Yes
Auto Reload On Changes    => Yes
Apache Configuration File => /usr/local/apache/conf/httpd.conf
Apache Port Offset  => 2000

You do have the option to enable PHP suEXEC for additional security, although if you enable this you won’t be able to use an opcode cache like APC.

Once you’ve made sure that Litespeed is functioning correctly, you can go back to the above configuration and change the Apache Port Offset to 0 and then disable Apache.
For more thorough guides on how to setup Litespeed and a custom PHP install, I’d suggest visiting Litespeed Install and Litespeed custom PHP.


I’ve lost count how many times I’ve needed to recompile a new version of APC for PHP on my server, so this mainly serves as a reminder on how to do it for next time.

  1. Go to http://pecl.php.net/package/APC and find the latest download link at the time.
  2. Login via SSH and go into root login via
    su -
  3. Navigate to the source folder:
    cd /usr/local/src
  4. wget the latest download from the PHP pecl link above. (i.e. wget http://pecl.php.net/get/APC-3.0.15.tgz)
  5. Unzip the archive like so:
    gunzip -c APC-3.0.15.tgz | tar xf -
  6. Navigate to the APC folder:
    cd APC-3.0.15
  7. phpize the APC folder to make the correct configuration file: /usr/bin/phpize
  8. Make the configuration file:
    ./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config
  9. Start the compile:
    make
  10. Finish and install:
    make install
  11. Edit the php.ini file to enable the APC module based on the location provided from the previous command:
    pico -w /usr/lib/php.ini
  12. Finally restart apache to see the changes:
    service httpd restart

The important bits you need to put inside php.ini are the extension call like so:

extension = "apc.so"

You then also need to enable and configure APC to your liking. Here’s my setup:

apc.enabled = 1
apc.shm_size = 64
apc.ttl = 3600
apc.user_ttl = 3600
apc.optimization = 0
apc.filters = "-Gallery.*\.class, wp-cache-config, -mint.php"
apc.include_once_override=1
apc.write_lock=1

Other things you need to take into account is your PHP extension_dir setting. This needs to be set right to be able to load the module correctly above.
You should also bear in mind that /usr/bin/phpize and /usr/bin/php-config could be different for your system setup.


I had a bit of a problem earlier on with my server. Exim, the bit that handles email, decided to eat up resources, which caused the Virtuozzo operating system to kick into action and start killing off processes that were eating up too much RAM. This left my server with just Apache and MySQL running.

Read the rest of this entry »


Today I went ahead and updated PHP and APC to the latest versions. Unfortunately, WordPress and some of its plugins don’t seem to agree too well with either of them.
I rolled back to PHP 5.2.0 and APC 3.0.12p2 for the time being and will keep an eye on the software to see if any changes are made soon.
I did managed to get Suhosin installed though.


I use loadavg to monitor memory, CPU and network usage on my VPS, just so I can get the bigger picture about what’s happening when I’m not about. However, with the introduction of SLM on my VPS I found that loadavg was reporting incorrect memory usage.

Looking through the PHP code for loadavg, I could see the commands that were being issued to get memory usage. I found this one:

cat /proc/user_beancounters

This was the command that outputted the incorrect RAM usage. It was always about 40 - 100 megabytes out. Far too much for my liking!
Later on in the script, there’s a call to /proc/meminfo if the information from the above code can’t be ascertained. This seemed to be giving the correct information. I worked out that a simple switch would be able to tell the scripts if SLM was enabled and if so, go straight to the latter piece of code and get the correct RAM usage.

Here are the changes you need to make in order to get loadavg working on an SLM based VPS.

Open config.php and add this underneath “Size of kilobyte”

// If you're on a virtuozzo VPS, you may have SLM enabled.
$slm = TRUE;

Open logger.php and change

$beancounters = @shell_exec("/bin/beanc 2> /dev/null");
if (!$beancounters) {
	if (file_exists('/proc/user_beancounters')) {
		$beancounters = `cat /proc/user_beancounters 2> /dev/null`;
	}
	else {
		$ded=TRUE;
	}
}

To

if($slm == TRUE) {
	$ded = TRUE;
} else {
	$beancounters = @shell_exec("/bin/beanc 2> /dev/null");
	if (!$beancounters) {
		if (file_exists('/proc/user_beancounters')) {
			$beancounters = `cat /proc/user_beancounters 2> /dev/null`;
		}
		else {
			$ded=TRUE;
		}
	}
}

That’s you sorted. Re-upload the changed files, delete any existing logs and watch the difference in reported memory usage!

lotsa emails this way!