Table of Contents

Compile PHP for LSWS (with LSAPI) (Archive Only)

There is a functionality available in the LiteSpeed Web Server (LSWS) Web Admin console, “Compile PHP”. This is a legacy function used for previous releases but that will soon be retired. The function is incompatible with all current control panel environments such as cPanel, Plesk, and DirectAdmin. Even in environments without a control panel “Compile PHP” is obsolete. Especially with RPM and Debian Packages providing a more efficient way to install and configure PHP. There are even certain environments ( CloudLinux ) providing their own special packages for PHP that claim to be more secure and stable than that of the standard packages. There are currently not many use cases in which compiling PHP from source is required, but if one does run into such a case, please follow the following steps, but take note this is legacy information.

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.

Compiling PHP

Compiling PHP through WedAdmin Console

Access the Compile PHP utility

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 /usr/local/lsws/admin/html/utility/build_php/buildconf.inc.php.

Choose your PHP options

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.

Compile options example for php 5.x:

'--with-mysqli' '--with-zlib' '--with-gd' '--enable-shmop' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-mbstring' '--with-iconv' '--with-mysql' '--with-mcrypt' '--with-pdo' '--with-pdo-mysql' '--enable-ftp' '--enable-zip' '--with-openssl '--with-curl' '--enable-soap' '--enable-xml' '--enable-json' '--enable-bcmath' 

Note: '--with-libdir=lib64' can also be added if it is for x86_64 systems.

Compile options example for php 7:

 '--with-mysqli --with-zlib --with-gd --enable-shmop --enable-sockets --enable-sysvsem --enable-sysvshm --enable-mbstring --with-iconv --with-mcrypt --with-pdo-mysql --enable-ftp --enable-zip --with-curl --enable-soap --enable-xml --enable-json  --with-openssl --enable-bcmath'

Note:  '--with-mysql' and '--with-pdo' are obsoleted in PHP 7. 

You may need the folllowing packages for your PHP build.

For CentOS/Redhat:

yum -y install epel-release
yum -y install gcc
yum -y install libxml2-devel libcurl-devel libpng-devel libmcrypt-devel openssl-devel

For Debian/Ubuntu:

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install pkg-config
sudo apt-get install libssl-dev libmcrypt-dev

Compile options for WordPress

Compile options for Joomla!

Compile options for Magento

Compile options for Drupal

Build PHP

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.

Compiling PHP from source code

Download PHP source code

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

Install build requirements

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.

For CentOS/Redhat:

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

For Debian/Ubuntu:

sudo apt-get build-essential pkg-config openssl libssl-dev openssl-blacklist openssl-blacklist-extra  bison autoconf automake libtool re2c flex libxml2-dev libssl-dev libbz2-dev libcurl4-openssl-dev libdb5.1-dev libjpeg-dev libpng12-dev libXpm-dev libfreetype6-dev libt1-dev libgmp3-dev libc-client2007e-dev libldap2-dev libmcrypt-dev libmhash-dev freetds-dev zlib1g-dev libmysqlclient-dev libncurses5-dev libpcre3-dev unixODBC-dev libsqlite0-dev libaspell-dev libreadline6-dev librecode-dev libsnmp-dev libtidy-dev libxslt-dev libt1-dev

Configure, Compile and Install

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 and for 64bit system, '--with-libdir=lib64' should be used in configure option.

then:

make
make install

If you run into any problem, please check our PHP compilation troubleshooting guide.

Create external LSAPI app pointing to installed PHP binary

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
Start By Server: 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

Set script handler

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.

Setup PHP.ini

Normally you can specify php.ini file path through '-with-config-file-path=xxx' during the compiling. If not, you can verify through

bin/lsphp -i | more 

Configuration File (php.ini) Path ⇒ /usr/local/lsws/lsphp56/lib/ Loaded Configuration File ⇒ /usr/local/lsws/lsphp56/lib/php.ini

In general, you can copy a sample php.ini file from source code to lsphp56/lib location.

cp php.ini-production lsphp56/lib/php.ini

You can run the php binary again to check if the php.ini file being loaded.

bin/lsphp -i | more 

Checking Installation

There are a number of ways to check whether your PHP installation was successful. One of the simplest is to run the following code:

/usr/local/lsws/lsphp56/bin/lsphp -v

It should return the information on your new PHP build:

PHP 5.6.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

Notice the litespeed in parentheses. This means that the PHP binary has been built with LSAPI support.

Troubleshooting

Build errors

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.

503 errors

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.