Litespeed - php install

Now the base Litespeed Server install has been completed (see Litespeed - installation) you have the option of installing the latest version of PHP.

This is an optional step in our Ubuntu/Litespeed setup so if you have no need for PHP then simply skip this article.

In part 1, we installed the Litespeed Server in /usr/local/lsws, so the first thing we need to do is go to that directory:

cd /usr/local/lsws

Now we're going to update the default PHP version (4.4.6) to the latest PHP version (5.2.3 at the time of writing). To do this we will use the PHP source code and a patch from Litespeed.

As we are working in a directory owned by root, most of the commands will be prefixed with sudo. Let's start off by getting a needed PHP patch from Litespeed:

sudo wget http://www.litespeedtech.com/packages/lsapi/php-litespeed-4.0.tgz

At the time of writing this article, the latest version of PHP is 5.2.3. When downloading the source code please go to the main PHP site to select a mirror near you. Now download the source code:

sudo wget http://uk3.php.net/get/php-5.2.3.tar.bz2/from/uk.php.net/mirror

Unpack the downloaded source code and move into the 'sapi' directory in the unpacked code:

sudo tar xjvf php-5.2.3.tar.bz2
cd php-5.2.3/sapi

The patch downloaded from Litespeed needs to be unpacked in this directory. Note the exact syntax of the command. It will locate the downloaded patch and extract it into the 'sapi' folder:

sudo tar xvfz ../../php-litespeed-4.0.tgz

Move up one directory and create a single file:

cd ..
sudo touch ac*

Next we need to create configuration files using 'buildconf', but first we need to install 'autoconf' as it is not yet included in the OS.

sudo apt-get install autoconf -y
sudo ./buildconf --force

Before we configure and compile PHP with Litespeed support we need to sort out a couple of things:

Firstly, I like to keep my php.ini (the php configuration file) in a 'configs' folder in my home folder. There is no more risk having it there than anywhere else and it is easy to access. So, create a 'configs' foler:

mkdir /home/paul/configs

We don't need to put anything into it yet, but it is there ready for the configure command. The configure command is as follows (don't enter it yet - I'd like to explain a few things first):

sudo ./configure '--prefix=/usr/local/php5'
'--with-config-file-path=/home/paul/configs' '--with-litespeed' '--with-mysql'
'--with-mysqli' '--enable-exif' '--enable-ftp' '--with-gd' '--with-jpeg-dir=..' '--with-png-dir=..'
'--enable-mbstring'

Have a look at the configure command: it tells php where to install and to include litespeed support. I have added some extra commands as I want mysqli support along with, exif, gd, jpeg, png and so on.

Note the '--with-config-file-path=/home/paul/configs' part. If you don't want your php.ini file to reside in that folder then adjust it accordingly.

If we went right ahead and gave the ./configure command, it will fail pretty quickly as quite a few support programmes are needed. Go ahead and install the necessary items (the command needs to go on one line):

sudo apt-get install automake1.4 bison chrpath debhelper flex freetds-dev 
po-debconf libbz2-dev libcurl3-openssl-dev libcurl3-dev libgcrypt11-dev 
libgd2-xpm-dev libgdbm-dev libjpeg62-dev libmhash-dev libncurses5-dev 
libpam0g-dev libpng12-dev libpq-dev librecode-dev libsnmp9-dev libt1-dev 
libwrap0-dev libxmltok1-dev libxslt1-dev re2c unixodbc-dev

It's quite a list but for the PHP extensions we need the jpeg, png and hash support.

Once installed, go ahead with the configuration command (again, all on one line):

sudo ./configure '--prefix=/usr/local/php5'
'--with-config-file-path=/home/paul/configs' '--with-litespeed' '--with-mysql'
'--with-mysqli' '--enable-exif' '--enable-ftp' '--with-gd' '--with-jpeg-dir=..' '--with-png-dir=..'
'--enable-mbstring'

Now 'make' and 'make install':

sudo make
sudo make install

Success!

Let's remove any old php binaries and move the newly created one to a working folder:

cd ..
sudo mv fcgi-bin/lsphp fcgi-bin/lsphp.old

The second command shown above keeps the default php binary (version 4.4.6) by renaming it to lsphp.old.

Now move the newly created Litespeed PHP binary to the working directory:

sudo cp php-5.2.3/sapi/litespeed/php fcgi-bin/lsphp

A quick check to see if the build includes litespeed support:

fcgi-bin/lsphp -v

My build outputs this:

fcgi-bin/lsphp -v
PHP 5.2.1 (litespeed) (built: May 11 2007 09:58:34)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

Note the litespeed after the PHP version? This confirms that litespeed support is included. For a more detailed output which includes all extensions and other information try this:

fcgi-bin/lsphp -i | less

Now restart Litespeed and have a look at the errors report for any problems:

sudo /usr/local/lsws/bin/lswsctrl restart
sudo tail -n100 /usr/local/lsws/logs/error.log
sudo tail -n100 /usr/local/lsws/logs/stderr.log

The stderr.log should be empty.

Have a look at the initial welcome page again:

Click on the 'Test PHP' link - you will see that it now shows the phpinfo text for version 5.2.3.

Congratulations. You've got Litespeed with PHP 5.2.3. installed.

Remember the configs folder we created earlier? Now create a blank php.ini file:

nano /home/paul/configs/php.ini

Place whatever adjustments you need to make in the file. Note it is not a full php.ini file - it only contains the changes from the default php.ini. Here is an example php.ini

I've changed very little expect turn off the ridiculous magic_quotes_gpc and turn display errors to off. You can add as little or as many changes as you see fit.

If you do want to use a custom php.ini file, there is one change you need to make in the Admin gui. Log into the Admin Area and 'hover' over the 'Configurations' link and click on 'Server':

Next click on the 'External App' tab and then on the 'phpLsapi' link. This will take you to the php configuration page:

Click on the 'edit' link and change the 'Command' entry. Simply remove the '-c ../php' so it reads:

$SERVER_ROOT/fcgi-bin/lsphp

The removed part of the command told Litespeed to look for the php.ini file in a specific place. We don't want that as we have configured PHP to look for the php.ini file in /home/paul/configs.

Remember to click 'save', 'Apply Changes' and then gracefully restart the server.

Now refresh the phpinfo page and any changes you made in your custom php.ini file are now active.

Any further changes or tweaks to your php.ini will require the server to be restarted (just as with any server). You can do this via the command line:

sudo /usr/local/lsws/bin/lswsctrl restart

Or via the Admin Gui by clicking 'Control Panel' and 'Graceful Restart'.

As you can see, once you get used to the Litespeed Admin Area, changes are very easy to configure and implement. I find it quicker than having to log in to the server via SSH, adjust a file by hand, restart the server, etc, etc. One browser, one page.

The next article will secure the administration area using a SSL connection and configuring Litespeed to accept connections from certain IP addresses only.

PickledOnion.

Digg it | del.icio.us | reddit | StumbleUpon

Article Comments:

Alex 12 Jun, 2007

I was doing pretty well following along until I got to this one. I'm having trouble with getting virtual hosts working (some path issue) and getting PHP updated. I'll try to catch you on IRC.

Alex 12 Jun, 2007

Pickle! Thanks man! I really appreciate your time an patience helping me out. It works great now and I actually understand what's going on a bit better! Cheers, Alex

Felix 10 Aug, 2007

Thanks for the excellent tutorials. Just a quick question for you, in the PHP5 configure command, you had the following: '--with-jpeg-dir=..' '--with-png-dir=..'. Why is ".." used there?

PickledOnion 11 Aug, 2007

Felix,

Sorry for the delay in replying. I lost the email notice of your post :)

Anyway, without a specific directory specified (such as "/usr") the ./configure command will check for png headers and libs in default locations.

So unless you have installed them in an odd location, you do not need a specific named directory and without the original '--with-png-dir=' png support will not be installed.

That's how I understand it.

PickledOnion.

Felix 25 Aug, 2007

Thanks for the interesting reply. I'm just curious, why there is a '--with-gd', but not similar things like '--with-jpeg', '--with-png' which will enable jpeg/png support w/o specifying the directory explicitly.

PickledOnion 27 Aug, 2007

Felix,

IIRC, there is no '--with-jpeg' configure option, it is '--with-jpeg-dir'. The correct configure syntax is also '--with-gd' and not '--with-gd-dir'.

I've no idea why the developers chose those particular options as I am not involved in that side of things.

You can also enter '--with-jpeg-dir' instead of '--with-jpeg-dir=..' - I beleive both will work perfectly well but I haven't tried it. Sometimes a working method (without a hack) is all I need but I am sure it could be DRYed up a bit.

PickledOnion.

Ben Berry 05 Sep, 2007

Hi, everything was working great until the configure step. I got the following error:

configure: error: Cannot find MySQL header files under yes. Note that the MySQL client library is not bundled anymore!

I entered the configure command exactly as you showed it. Perhaps there's a difference with how you installed MySQL and how the deprec gem does? Any ideas?

PickledOnion 05 Sep, 2007

I imagine that is exactly the issue - you do need the mysql dev package. I outline the packages in page 3 of the Ubuntu install: Ubuntu See if you have all the mysql packages installed. That should solve the issue but let me know if it doesn't. PickledOnion

Ben Berry 06 Sep, 2007

Thanks, Pickled. That worked like a charm.

Comments are closed for this article.