Skip to content

This guide will show you how to build custom LSPHP (PHP with LiteSpeed API) on your Linux machine.

We will cover:

Building Custom PHP

Danger

We do not recommend this method! In most situations, you should install LSPHP through the LiteSpeed repository.

We are providing these instructions as a courtesy, but compiling and building PHP is out of the scope of our web server support. Building PHP is a big topic. If you experience trouble, we will not be able to help you. You may be able to find assistance on a PHP users forum.

If you have a rare situation that requires you to compile and build PHP for some special need, you can use OpenLiteSpeed's Compile PHP tool.

Navigate to WebAdmin console > Tools > Compile PHP. Select a PHP Version and click Next.

Choose build options

The Installation Path Prefix designates the location where the PHP executable will be built. (It is equivalent to '--prefix=' in the mod_php build options.) This setting is important because this is where your php.ini will be and where extensions should be installed. Use the Configure Parameters and Add-on Modules fields to selected necessary compile options and modules. Click Next when you're finished.

Download Source Code

The server will download the PHP source packages and LSAPI.

Build PHP

Before building the package, install the necessary dependency packages, like so:

apt-get install -y pkg-config libxml2-dev build-essential libssl-dev libzip-dev libsqlite3-dev libcurl4-openssl-dev libjpeg-dev libpng-dev libonig-dev

Note

The dependency packages you will need to install depends on your system, PHP version and configuration parameters.

For security reasons, please log in to your server and run the pre-generated script from the shell.

/usr/local/lsws/phpbuild/buildphp_manual_run.sh

The tool will begin compiling PHP for you. Do not refresh your browser or leave the page, or the process will be interrupted.

You can monitor the build progress in the Main Status window.

If you would like to see a more detailed log, you can view the file that is named in the first line of the Main Status window. In the screenshot above, it says:

**MAIN STATUS** retreived from /usr/local/lsws/phpbuild/buildphp_1761785588.8.progress

To see the full details, you would open /usr/local/lsws/phpbuild/buildphp_1761785588.8.progress from the command line.

Restart service

The last step is to restart the web server:

service lsws restart

Verify

You can use the command line to verify the version and module, or create a phpinfo page and verify it from the browser:

/usr/local/lsws/lsphp8/bin/lsphp -v
PHP 8.4.10 (litespeed) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.10, Copyright (c) Zend Technologies

Building old PHP on new system

You may have a need to build an old or end-of-life PHP version like 7.4.33 on an Ubuntu 24.04 (Noble) system, but newer systems only ship OpenSSL 3 and above. Old PHP packages may depend on libssl 1.1. So, in this case you would compile openSSL manually, and then point PHP 7.4 to it.

Manually build OpenSSL 1.1

Compile OpenSSL 1.1, like so:

curl -L -o /usr/local/src/openssl-1.1.1w.tar.gz https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-1.1.1w.tar.gz
cd /usr/local/src; tar -xzf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
./config --prefix=/usr/local/openssl-1.1.1 --openssldir=/usr/local/openssl-1.1.1 shared
make
make install

Tip

Check the OpenSSL download page for more versions

If compilation is a success, you'll find the following generated files:

/usr/local/openssl-1.1.1/include/openssl/*.h
/usr/local/openssl-1.1.1/lib/libcrypto.so.1.1
/usr/local/openssl-1.1.1/lib/libssl.so.1.1

Set OpenSSL paths

Set the OpenSSL path for this session.

export CPPFLAGS="-I/usr/local/openssl-1.1.1/include"
export LDFLAGS="-L/usr/local/openssl-1.1.1/lib"
export LD_LIBRARY_PATH="/usr/local/openssl-1.1.1/lib:$LD_LIBRARY_PATH"

Add the library to the system loader permanently.

Add /usr/local/openssl-1.1.1/lib to the /etc/ld.so.conf.d/openssl-1.1.conf file.

Reload with ldconfig command.

Update build options

Navigate to WebAdmin Console > Tools > Compile PHP. Select PHP Version 7.4.33 and click Next.

Change the Configure Parameters from this:

--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

to this:

--with-mysqli --with-zlib --enable-gd --enable-shmop --enable-sockets --enable-sysvsem --enable-sysvshm --enable-mbstring --with-iconv --with-pdo-mysql --enable-ftp --enable-zip --with-curl --enable-soap --enable-xml --enable-json --with-openssl=/usr/local/openssl-1.1.1 --enable-bcmath

Click Next when you're finished.

Then follow the Download Source Code step above to complete the build process.