Compiling PHP on LiteSpeed for Magento

October 30th, 2008

LiteSpeed is my favorite web server solution, even though it is closed source *GASPS*.

Here is how to compile php for litespeed - specifically targeted at the requirements for running a Magento storefront.

First off the free version of litespeed is not available for 64bit operating systems, which you probably are running.  So first we need to get the 32 bit os libraries. apt-get install ia32-libs

The next chunk of commands will install everything that is required to compile php5 with support for MagentoCommerce.apt-get install mysql-common mysql-client mysql-server
apt-get install autoconf
apt-get install build-essential
apt-get install libxml2 libxml2-dev
apt-get install libsqlite0 libsqlite0-dev libsqlite3-0 libsqlite3-dev
apt-get install libcurl3 libcurl3-gnutls libcurl3-dev
apt-get install libjpeg62 libjpeg62-dev
apt-get install libpng12-dev libpng12-0
apt-get install libmysqlclient15-dev
apt-get install mcrypt libmcrypt-dev libmcrypt4 libmhash-dev


Now lets get the install package for LiteSpeed.wget http://www.litespeedtech.com/packages/3.0/lsws-3.3.21-std-i386-linux.tar.gz

Now untar the package and run the litespeed installertar -xzvf lsws-3.3.21-std-i386-linux.tar.gz
cd lsws-3.3.21
./install.sh

Walking through the setup, use the defaults unless otherwise mentioned belowPath: /usr/local/lsws
User: www-data
Group: www-data
HTTP port: 80
Setup PHP: Yes

The setup PHP option will automatically setup PHP4 under FastCGI mode. Great to start off with, but will not work with Magento.

Now we need to compile PHP5 with the Litespeed API (lsapi). Log in to the administration control panel for your litespeed server. ex: http://yourip:adminport/ Go to Actions -> Compile PHP. At the top of that page will be the form for compiling PHP5 for your server. Use the following settingsversion 5.2.6 (newest)
no extra path environment
install path prefix /usr/local/lsws/lsphp5
config params
--with-mysqli --with-zlib --with-gd --enable-shmop --enable-track-vars --enable-sockets --enable-sysvsem --enable-sysvshm --enable-magic-quotes --enable-mbstring --with-iconv --with-mhash --with-mcrypt --with-mysql --with-pear --with-xml --with-simplexml --with-zlib --with-enable-inline-optimization --disable-debug --with-dom --with-dom-xslt --with-sqlite --with-curl --with-php-soap --with-soap --enable-soap --enable-pdo --with-mysql-pdo --with-pdo-mysql --with-kerberos --with-gif --with-jpeg --with-png --enable-jpg --enable-png --enable-gif --with-jpeg-dir=/usr/include/
Check Suhosin patch
Check XCache as OPcode cache
Now click Build PHP 5. This should take some time. If you receive any errors… please note them & leave me a comment.

Things to double check… The lsphp5 symbolic link in $Server_Root\fast-cgi\ should point to the new lsphp-5.2.6 executable.
the script handler in server configuration for php & php5 extensions should point to lsphp5 symbolic link.

You can now compile newest php5 every time they release, the symbolic link should automatically update, and you will have the newest version of PHP for your Magento storefront!

Magento Shopping Cart on Litespeed - Smoking Apache

October 30th, 2008

Does MagentoCommerce’s performance keep you up at night?  Are slow page loads and high server usage tainting your online presence.  Drop Apache!

My recent interest in the open source e-commerce solution MagentoCommerce has led me down some interesting paths.  Magento is a very large e-commerce solution.  Its excellent design makes Magento the most flexible shopping solution I have ever used.  Did I mention its also free! Mmmm free beer.

Magento is so large that many shared and dedicated hosting solutions will come to a crawl.  PHP is a great language (feel free to flame in the comments section) but when you look at the OOP scheme Magento is built on, most server implementations will choke.  Any production Magento store requires every little hack available to a server admin.  Magento hits the database server - HARD, hits the php engine - HARD, hits the disk drives - HARD, etc…  Every peice of the server powering Magento will get taxed.


Here is a list of some quick optimizations for any server setup looking to run magento (most of these bump up wordpress performance too!)

  • Opcode Caching
    1. XCache
    2. APC - Alternative PHP Cache
    3. Zend Optimizer
    4. eAccelerator
  • Turn off all logging
  • Use FastCGI if possible

Here is a quick summary of what I have done to maximize performance of my Magento installations.

  • Use Litespeed Web Server
  • Compile PHP to work through the LiteSpeed API (LSAPI)
  • Create memory partition to store high IO Magento folders (”/var/cache” etc…)
  • Run XCache

Ballpark performance numbers:  System specs: P4 2.4ghz, 512mb ram, Ubuntu 8.04 7200rpm 60GB hdd
Apache2+mod_php5 = >4 seconds average
Apache2+php5 as fastcgi = >2 seconds average
Litespeed+php5 as fastcgi = >1 second average
Litespeed + php5 as lsapi = < .8 second average
Litespeed + php5 as lsapi + xCache + mem disk = < .3 second average

These were run using apache benchmark for 100 requests with concurrency of 3  (it isn’t a server box… give it a break)

Whatever litespeed has done with their lsapi module for php5… they definately did something right!  I use Magento’s SOAP API to upload a product catalog of over 200 items.  On apache it would take half a workday.  With litespeed, the batch can finish in an hour.