This guide will take you through the steps to compile PHP (with LSAPI) for LiteSpeed Web Server (LSWS) . This guide is recommended for for all users except WHM and DirectAdmin users. Our WHM Plugin and DirectAdmin's CustomBuild integration offer more convenient methods for compiling PHP to match your Apache installation.
LiteSpeed Server API (LSAPI) is LiteSpeed's open-source API for communications between LSWS and external applications. LSWS can also use PHP with FastCGI (PHP-FPM), but LSAPI has repeatedly been shown to be faster and more efficient than FastCGI. PHP LSAPI also contains functionality, like suEXEC Daemon and ProcessGroup modes, that PHP-FPM does not offer.
LSAPI is included in PHP packages 5.3 and up including PHP 7. PHP will automatically be configured for use with LSAPI when you compile PHP using LiteSpeed Web Server's Build PHP utility (WebAdmin console > Actions > Compile PHP). If a new version of PHP LSAPI comes out, simply recompile PHP and the new version will be installed.
If you compile PHP from source code, normally the latest version of LSAPI has been included in sapi/litespeed/. Of course you can download the latest one from LSAPI download page and patch it by overwriting *.c *.h files, though it may not be necessary.
You can either compile PHP through LiteSpeed WebAdmin Console or from PHP source code downloaded from php.net.
PHP can be compiled from the WebAdmin console. Under the Actions menu, go to Compile PHP.
Select the version of PHP you would like to use. If you would like to use a version not listed, you will have to edit the WebAdmin console's source code located at
On the next screen you will choose PHP's compile options. This can be a complicated task. If you have PHP installed already, you can view your current configurations from a phpinfo() page. If you have been using mod_php or PHP-FPM (FastCGI) you can simply copy these options into the Configure Parameters field. Remove parameters specific to other SAPIs, such as
–with-axps(2) (mod_php) or
–enable-fastcgi (PHP-FPM). The WebAdmin console will add the
–with-litespeed parameter (for using LSAPI) automatically.
The next screen will download and prepare PHP and the latest version of LSAPI. When the process is done, you can proceed to building PHP by pressing the Next button.
You will now be asked to log into your server and run the stipulated command as root. This is required for security reasons.
When the build process has started, you will be able to see an overview of what is happening in the Main Status field. You can view a detailed log, just below that. (The detailed log is useful if you run into an error.)
If the build completes successfully, you will be asked to restart LSWS to apply the new PHP build.
This can be done under the Actions menu.
mkdir /home/php cd /home/php wget http://us1.php.net/get/php-5.x.x.tar.gz/from/this/mirror tar -zxvf php-5.x.x.tar.gz cd php-5.x.x
The following is a example for your build requirement, though you may not need all of them or you may need other packages depend on your compiling configuration.
yum install patch gcc glibc libstdc++ binutils libtool autoconf make bison pam-devel libcap-devel openssl-devel tcp_wrappers-devel bzip2-devel curl-devel db4-devel gmp-devel httpd-devel libstdc++-devel sqlite-devel sqlite2-devel liyuybedit-devel pcre-devel libtool gcc-c++ libtool-ltdl-devel libevent-devel libc-client-devel cyrus-sasl-devel openldap-devel mysql-devel postgresql-devel unixODBC-devel libxml2-devel net-snmp-devel libxslt-devel libxml2-devel libjpeg-devel libpng-devel freetype-devel libXpm-devel t1lib-devel libmcrypt-devel libtidy-devel freetds-devel aspell-devel recode-devel enchant-devel firebird-devel gdbm-devel tokyocabinet-devel
In the source code folder, run ./configure with “–with-litespeed” and other configuration options. For example:
./configure '--prefix=/usr/local/lsws/lsphp56' '--with-libdir=lib64' '--with-zlib' '--with-gd' '--enable-shmop' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--with-curl' '--with-openssl' '--with-gettext' '--with-mcrypt' '--enable-mbstring=all' '--enable-mbregex' '--with-png-dir=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--enable-ftp' '--with-imap=/usr' '--with-imap-ssl' '--with-mysql=/usr' '--with-mysqli=/usr/bin/mysql_config' '--enable-pcntl' '--with-freetype-dir=/usr' '--with-pdo-mysql=/usr' '--with-litespeed'
You have to adjust configuring options to suit your need, for example, prefix can be set to '–prefix=/usr/local/lsws/lsphp54' if you compiles PHP 5.4 version, add or remove options to meet your application need.
make make install
If you run into any problem, please check our PHP compiling troubleshooting guide.
Navigate to WebAdmin console > Server > External App and click “Add”. Then select “LSAPI App” from drop down menu and click “Next”.
Now set your PHP configuration. The following is an example of a typical setting, make sure you set the PHP binary path to the right location: set “command” to “$SERVER_ROOT/lsphp56/bin/lsphp”; the rest of configurations can be adjusted according to your situation.
Name: lsphp56 Address:uds://tmp/lshttpd/lsphp56.sock Max Connections: 35 Environment: PHP_LSAPI_MAX_REQUESTS=500 PHP_LSAPI_CHILDREN=35 Initial Request Timeout (secs): 60 Retry Timeout : 0 Response Buffering: no Auto Start: yes Command: $SERVER_ROOT/lsphp56/bin/lsphp Back Log: 100 Instances: 1 Memory Soft Limit (bytes): 2047M Memory Hard Limit (bytes):2047M Process Soft Limit: 400 Process Hard Limit: 500
Navigate to WebAdmin console > Server > Script Handler, where you might see that the “php” suffix already exists. Click “edit” for “php”, set “Handler Type” to “LiteSpeed LSAPI”, and then set the “Handler Name” to the one you just created. For example “lsphp56”. Lastly save the changes.
Restart LiteSpeed to make it effective.
There are a number of ways to check whether your PHP installation was successful. One of the simplest is to run the following code:
cd /usr/local/lsws/fcgi-bin/ ./lsphp5 -v
It should return the information on your new PHP build:
PHP 5.5.15 (litespeed) (built: Aug 20 2014 14:09:09) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
litespeed in parentheses. This means that the PHP binary has been built with LSAPI support.
If you hit errors while building PHP, please refer to our troubleshooting guide. Many common errors, as well as sample PHP configurations, are covered there.
If you run into 503 errors, this is often indicative of a problem with PHP. Please see our 503 troubleshooting guide for the steps to diagnosing and fixing these errors.