Wiki
 

PHP 4/5 with LSAPI Compile/Install How-To

Preamble

LSAPI is LiteSpeed's open-source API between external applications and LiteSpeed Web Server. This how-to is for compiling and installing PHP + LSAPI on Linux, OS X, FreeBSD, Solaris, and so on.

In this how-to such directories as /lswsinstall and /php5 are used as general directories to refer to the paths actually used. If you did not modify the installation location of LSWS on initial installation this will be at /usr/local/lsws. The PHP install directory can be any directory which you will set upon the initial configuration of PHP by changing the –prefix value.

With LSWS 3.3 release or later, LSAPI PHP can be built from within the web console. Step 1-6 can be skipped in this tutorial.

If PHP has been installed on your server, either as mod_php or FastCGI PHP, you should copy over the configuration parameters used for your current PHP. The configuration parameter is available from a phpinfo() page. When you copy over the configuration parameters, you should remove parameters specific to that SAPI, like ”–with-axps(2)”, ”–enable-fastcgi”, etc. The web console will add ”–with-litespeed” automatically.

You also need to make decision whether to install PHP to its current location. Usually is ”–prefix=/usr/local”. If you compile the same PHP version for LiteSpeed, you can choose to install to the same location. Just remember to upgrade both LiteSpeed PHP and Apache mod_php later together if you want to keep both LiteSpeed and Apache work properly. Mixing different version of PHP together may break you PHP installation.

If you want to compile different PHP version, for example, have LiteSpeed support both PHP4 and PHP5, you should install them to different location. For PHP4 we recommend something like ”–prefix=/usr/local/lsphp4”, for PHP5, we recommend something like ”–prefix=/usr/local/lsphp5”.

Instructions

You can skip step 1-5 by using the new "Compile PHP" feature from LiteSpeed Web console under "Actions" menu

1) Download/expand latest PHP 5 from http://www.php.net/downloads.php:

cd /tmp
wget http://us3.php.net/get/php-5.4.29.tar.gz/from/us2.php.net/mirror
tar -zxf php-5.4.29.tar.gz

We will refer to the unpacked php src directory as ”/php-source/”.

2) Patch PHP source code with latest LSAPI release.

Download and expand latest LSAPI for PHP from http://www.litespeedtech.com/products/lsapi/download/

wget http://www.litespeedtech.com/packages/lsapi/php-litespeed-6.6.tgz
tar -zxf php-litespeed-6.6.tgz
cp litespeed/*.c litespeed/*.h php-5.4.29/sapi/litespeed
cd php-5.4.29

Note:

  1. For PHP 5.2 and below, need copy the whole litespeed directory with command
cp -r litespeed php-5.4.29/sapi/

3) For PHP 5.2 and below, need to regenerate the configuration script, Change directory to root PHP source directory and run commands:

touch ac* 
./buildconf --force

4) Configure/Compile PHP:

We have it installed to /usr/local/lsws/lsphp54

./configure '--prefix=/usr/local/lsws/lsphp54' '--with-litespeed' --with-mysql ...
make
make install

If you would like to compile with additional PHP extensions, insert the options in the ./configure line. If you migrate from a Apache installation, you can use exact the same configuration options dumped in output of a phpinfo() page, just remember to remove –with-apxs and –with-apxs2 options. These are for installing PHP with Apache, not Litespeed. If you want to use PHP with MySQL 4.1 and above, you should build PHP with the client library coming with MySQL installed on your server by using option –with-mysql=<path_to_mysql_base_dir>, MySQL client shipped with PHP may not work due to changes in MySQL authentication.

Note: You must compile PCRE (Perl Compatible Regular Expressions) support in order for the default auto-index PHP script to work correctly (at least this is true for 3.0RC2).

Note: For fixing the errors in the compile stage, refer to this troubleshooting guide

5) Replace the lsphp5 binary (backup first) in /usr/local/lsws/fcgi-bin/ directory with sapi/litespeed/php:

cp sapi/litespeed/php /usr/local/lsws/fcgi-bin/lsphp-5.4.29
ln -sf lsphp-5.4.29 lsphp5

Check Installation

6) To check installation success:

cd /usr/local/lsws/fcgi-bin/
./lsphp5 -v

It should return something like:

PHP 5.4.29 (litespeed) (built: Aug 26 2008 14:09:09)
Copyright (c) 1997-xxxx The PHP Group
Zend Engine vX.X.0, Copyright (c) 1998-XXXX Zend Technologies

Notice litespeed in parenthesis. This means that the PHP binary has litespeed (LSAPI) support builtin.

Final check:

./lsphp5 -i

Above command will dump all the version info, configuration settings, and list of installed extensions with PHP.

Final Instructions

7) Location of php.ini:

lsphp5 -i

give the location that PHP looking for php.ini,

Configuration File (php.ini) Path => /usr/local/lsws/lsphp54/lib

You should place php.ini at

/usr/local/lsws/lsphp54/lib/php.ini

8) Restarting Litespeed Webserver

Our final step is to restart LSWS and use our new PHP binary.

/usr/local/lsws/bin/lswsctrl restart

We should now be running our new PHP binary with LSAPI, however we'll check. Run:

tail -n100 /usr/local/lsws/logs/error.log
tail -n100 /usr/local/lsws/logs/stderr.log

to make sure your newly compiled PHP did not throw any fatal errors on startup.

Trouble shooting

If you LiteSpeed PHP setup give 503 errors, you may have PHP configuration problem, usually it is because the version of a loadable module does not match the PHP version used. You need to recompile the loadable module to fix it.

Some trouble shooting techniques:

  • check lsws/logs/stderr.log and lsws/logs/error.log.
  • try to start the lsphp binary with matching user id with command like
sudo -u nobody ./lsphp5 -i
  • disable opcode cache one by one, especially when multiple caches are used, like xcache, eaccelerator, APC, ionCube, etc.
  • compare the phpinfo() page to a working installation, sometimes, due to permission problem, php configuration files cannot be fully loaded.
  • strace/truss/ktrace a lsphp process, it shows all the system calls made by the process.
 
litespeed_wiki/php/lsapi.txt · Last modified: 2014/06/03 09:51 by George Wang