OpenLiteSpeed: How to recompile PHP (LiteSpeed SAPI PHP)
OpenLiteSpeed like it’s commercial brother, LiteSpeed has it’s own PHP handler, LiteSpeed SAPI PHP bundled into the web server. But it seems the default OpenLiteSpeed SAPI PHP isn’t optimally compiled. It’s missing MySQL support out of the box and points to a non-existent php.ini path directory at /tmp/lib. Luckily, it’s very easy to recompile OpenLiteSpeed SAPI PHP with your own custom PHP configuration options.
Update: you can even add your own PHP versions via editing buildconf.inc.php – for when a new PHP version is released before OpenLiteSpeed has a chance to update their offered PHP versions. Read how to edit buildconf.inc.php to update PHP versions selectable.
Below I will outline how to recompile OpenLiteSpeed PHP (same method used for my OpenLiteSpeed vs Nginx benchmarks). Apparently, you can also setup multiple PHP versions according to their blog.
Step 1. Log into OpenLiteSpeed Admin Console via your web browser. Admin Console needs to be accessed from https:// version of your server’s IP address and off port 7080. For example https://localhost:7080
Step 2. Click on Actions menu drop down and find Compile PHP option and click on it. You’ll be greeted with 2 options to either install and compile PHP 5.x or PHP 4.x and have a drop down menu to choose a specific PHP version to install, upgrade, downgrade or re-install. For this example, I picked PHP 5.3.24 which is latest stable PHP 5.3.x build and hit the next button.
Step 3. Here you’ll be greated with Configure Parameters box where you enter in your custom PHP configuration options. Leave Extra PATH environment and Install Path Prefix as is. You also have option to User Configuration from a Previous Build or Restoring OpenLiteSpeed Defaults. There’s also options to compile APC Cache or Xcache or eAccerlator PHP opcode cachers, or memcache PHP extension or PHP mail Header Patch. I usually install APC, Xcache or Memcache via my own custom bash shell scripts, so leave these unchecked. The choice is yours :)
I’m using the following PHP configure options with MySQL and MySQLi support via MySQL Native Driver to be independent of MySQL server’s own client libraries. Note: you can remove ‘–with-config-file-scan-dir=/openlitespeed/php.d’ option as it doesn’t seem to work properly – OpenLiteSpeed isn’t picking it up properly for additional *.ini files. Update: OpenLiteSpeed 1.2.4 tested works fine with ‘–with-config-file-scan-dir=/openlitespeed/php.d’ option.
'--with-mcrypt' '--with-mhash' '--with-zlib' '--with-gettext' '--enable-exif' '--enable-zip' '--with-bz2' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-shmop' '--with-pear' '--enable-mbstring' '--with-openssl' '--with-mysql=mysqlnd' '--with-libdir=lib64' '--with-mysqli=mysqlnd' '--with-mysql-sock' '--with-curl' '--with-gd' '--with-xmlrpc' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-gd-native-ttf' '--with-freetype-dir=lib64' '--with-jpeg-dir=lib64' '--with-png-dir=lib64' '--with-xpm-dir=lib64' '--enable-pdo' '--with-pdo-sqlite' '--with-pdo-mysql=mysqlnd' '--enable-inline-optimization' '--with-imap' '--with-imap-ssl' '--with-kerberos' '--enable-posix' '--enable-xml' '--with-libexpat-dir=/usr' '--with-config-file-scan-dir=/openlitespeed/php.d' '--with-litespeed' |
Once you entered your configuration parameters for PHP, hit Build PHP 5.3.24 button. OpenLiteSpeed will save the configuration so you can retrieve it in future builds.
Step 4. Once you hit Build PHP 5.3.24 button, you’ll be greeted with below screen where OpenLiteSpeed will proceed to download the appropriate PHP tarball archive, patches and any additional files needed to compile PHP. Once Preparation finished successfully is show, hit the Next button.
Step 5. Now you’ll see below screen which prompts you to start an SSH Telnet session as root user to initiate and start PHP compile via a custom bash shell script (/usr/local/lsws/phpbuild/buildphp_manual_run.sh). DO keep both the OpenLiteSpeed Admin Console browser window open throughout the PHP compile as well as keep your SSH Telnet window session open.
You will see the live update progress of PHP compile within your OpenLiteSpeed Admin Console browser window.
Step 6. Once, PHP compile is complete, you’ll see the following screenshot prompting you to Apply Changes.
Step 7. First time you compile PHP, there is no default php.ini in place. So you will need to only do this once or whenever you move to a major PHP upgrade. Find the default PHP downloaded version’s php.ini-production file and copy and rename it to the default OpenLiteSpeed php.ini path at /usr/local/lsws/lsphp5/lib/php.ini. Not sure if there is a php.ini file in place if you choose to install APC, Xcache, Memcache Extensions via the prompted checkbox options though ?
Via SSH Telnet as root user copy over php-ini-production to correct php.ini path. Take note of PHP version in the source path if you chose a different PHP version.
cp -a /usr/local/lsws/phpbuild/php-5.3.24/php.ini-production /usr/local/lsws/lsphp5/lib/php.ini |
Optional step I usually do is tweak and customise the php.ini out of the box, I use sed to replace some defaults with my custom settings.
sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/lsws/lsphp5/lib/php.ini sed -i 's/;realpath_cache_size = 16k/realpath_cache_size = 1024k/g' /usr/local/lsws/lsphp5/lib/php.ini sed -i 's/;realpath_cache_ttl = 120/realpath_cache_ttl = 180/g' /usr/local/lsws/lsphp5/lib/php.ini sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 15M/g' /usr/local/lsws/lsphp5/lib/php.ini sed -i 's/post_max_size = 8M/post_max_size = 15M/g' /usr/local/lsws/lsphp5/lib/php.ini sed -i 's/expose_php = On/expose_php = Off/g' /usr/local/lsws/lsphp5/lib/php.ini |
Step 8. Then go back to Actions drop down menu and hit Graceful restart, to restart OpenLiteSpeed to allow PHP changes to take effect.
Sample PHP Info output.
Edit OpenLiteSpeed buildconf.inc.php
buildconf.inc.php has an array listing all PHP versions available. All you need to do is add the new PHP versions to the array list i.e. for PHP 5.4.15 and PHP 5.3.25. Then refresh Compile PHP page above and you should see the new PHP versions to choose from.
Change from
$PHP_VER = array('5'=> array( '5.4.14', '5.4.13', '5.4.12', '5.4.11', '5.4.10', '5.4.9', '5.4.8', '5.4.7', '5.4.6', '5.4.5', '5.3.24', '5.3.23', '5.3.22', '5.3.21', '5.3.20', '5.3.19', '5.3.18', '5.3.17', '5.3.16', '5.3.15', '5.3.8', '5.3.6', '5.2.17', '5.2.9', '5.1.6'), '4'=> array('4.4.9', '4.4.8')); |
Change to
$PHP_VER = array('5'=> array( '5.4.15', '5.4.14', '5.4.13', '5.4.12', '5.4.11', '5.4.10', '5.4.9', '5.4.8', '5.4.7', '5.4.6', '5.4.5', '5.3.25', '5.3.24', '5.3.23', '5.3.22', '5.3.21', '5.3.20', '5.3.19', '5.3.18', '5.3.17', '5.3.16', '5.3.15', '5.3.8', '5.3.6', '5.2.17', '5.2.9', '5.1.6'), '4'=> array('4.4.9', '4.4.8')); |