Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
litespeed_wiki:php:lsapi [2015/10/20 13:58] Jackson Zhang |
litespeed_wiki:php:lsapi [2018/09/17 19:52] (current) Michael Alegre created |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Compile PHP for LSWS (with LSAPI) ====== | + | #REDIRECT archive:php:lsapi |
- | + | ||
- | 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 [[http://www.litespeedtech.com/products/control-panel-plugins/cpanel-whm-plugin|WHM Plugin]] and [[litespeed_wiki:directadmin:custombuild-installation|DirectAdmin's CustomBuild integration]] offer more convenient methods for compiling PHP to match your Apache installation. | + | |
- | + | ||
- | [[http://www.litespeedtech.com/products/litespeed-sapi/overview|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 [[http://www.litespeedtech.com/products/litespeed-web-server/benchmarks/php-hello-world|faster and more efficient than FastCGI]]. PHP LSAPI also contains functionality, like [[http://www.litespeedtech.com/products/litespeed-sapi/php|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 [[https://www.litespeedtech.com/products/litespeed-sapi/download|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 through WedAdmin Console ===== | + | |
- | + | ||
- | === Access the Compile PHP utility === | + | |
- | + | ||
- | PHP can be compiled from the WebAdmin console. Under the Actions menu, go to Compile PHP. | + | |
- | + | ||
- | {{php_compile_menu.png?700px}} | + | |
- | + | ||
- | 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''. | + | |
- | + | ||
- | {{php_compile_version.png?700px}} | + | |
- | + | ||
- | === 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. | + | |
- | + | ||
- | {{php_compile_options.png?700px}} | + | |
- | + | ||
- | === 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. | + | |
- | + | ||
- | {{php_compile_prepare.png?700px}} | + | |
- | + | ||
- | You will now be asked to log into your server and run the stipulated command as root. This is required for security reasons. | + | |
- | + | ||
- | {{php_compile_command.png?700px}} | + | |
- | + | ||
- | 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.) | + | |
- | + | ||
- | {{php_compile_started.png?700px}} | + | |
- | + | ||
- | If the build completes successfully, you will be asked to restart LSWS to apply the new PHP build. | + | |
- | + | ||
- | {{php_compile_complete.png?700px}} | + | |
- | + | ||
- | This can be done under the Actions menu. | + | |
- | + | ||
- | {{php_compile_restart.png?700px}} | + | |
- | + | ||
- | ===== 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. | + | |
- | + | ||
- | 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 | + | |
- | + | ||
- | === 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 [[litespeed_wiki:php:lsapi-troubleshooting|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 | + | |
- | 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 | + | |
- | + | ||
- | === 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. | + | |
- | + | ||
- | + | ||
- | ===== 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: | + | |
- | + | ||
- | 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 | + | |
- | + | ||
- | 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 [[litespeed_wiki:php:lsapi-troubleshooting|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 [[litespeed_wiki:php:503-errors|503 troubleshooting guide]] for the steps to diagnosing and fixing these errors. | + |