Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:how_do_i_configure_lsws_for_php [2015/05/11 21:07]
Jackson Zhang [Overview of LiteSpeed and PHP]
litespeed_wiki:how_do_i_configure_lsws_for_php [2015/07/27 20:34]
Michael Alegre removed
Line 2: Line 2:
  
  
-LiteSpeed Web Server comes configured for PHP 4 and PHP 5. Normally, there is no need to even change the default settings (though users should compile from source code or install from RPMs a newer version of PHP than the one that comes with LiteSpeed Web Server). ​Users may, however, wish to set up special configurations for PHP at either ​server or virtual host level. This wiki reviews how PHP is configured with LiteSpeed Web Server.+LiteSpeed Web Server comes pre-configured for PHP 4 and PHP 5. Normally, there is no need to change the default settings (though users should compile from source code or install from RPMs a newer version of PHP than the one that comes with LiteSpeed Web Server). ​However, users may, wish to set up special configurations for PHP at either ​the server or virtual host level. This wiki reviews how PHP is configured with LiteSpeed Web Server.
  
-Unlike Apache'​s mod_php, which embeds the PHP engine inside web server processes, LiteSpeed Web Server talks to standalone PHP engine processes via a PHP SAPI interface. This allows the web server to delegate processes to different processors and efficiently handle multiple tasks. Two types of PHP SAPI interfaces are supported by LiteSpeed: LiteSpeed and FastCGI. LiteSpeed SAPI (LSAPI) has similar architecture to the FastCGI SAPI with two major enhancements:​ +Unlike Apache'​s mod_php, which embeds the PHP engine inside web server processes, LiteSpeed Web Server talks to standalone PHP engine processes via a PHP SAPI interface. This allows the web server to delegate processes to different processors and efficiently handle multiple tasks. Two types of PHP SAPI interfaces are supported by LiteSpeed: LiteSpeed and FastCGI. LiteSpeed SAPI (LSAPI) has similar architecture to FastCGI SAPI with two major enhancements:​ 
-  - up to 50% better performance +  - Up to 50% better performance 
-  - support ​for dynamic PHP configuration changes through web server configuration and .htaccess files.+  - Support ​for dynamic PHP configuration changes through web server configuration and .htaccess files.
    
-For cPanel, PHP must have been built with EasyApache and is working fine with Apache. LiteSpeed will build its matching PHP (with LSAPI) based on this build of PHP through WHM/cPanel plugin. ​see [[litespeed_wiki:​cpanel:​auto-installer|cPanel installlation Guild]].+For cPanel, PHP must have been built with EasyApache and should be working fine with Apache. LiteSpeed will build its matching PHP (with LSAPI) based on this build of PHP through WHM/cPanel plugin. ​See [[litespeed_wiki:​cpanel:​auto-installer|cPanel installlation Guild]].
  
-For DirectAdmin,​ we recommend [[litespeed_wiki:​directadmin:​custombuild:installation|DA CustomBuild 2.0]] to build matching PHP.+For DirectAdmin,​ we recommend [[litespeed_wiki:​directadmin:​custombuild-installation|DA CustomBuild 2.0]] to build matching PHP.
  
-For other control panels, ​or Apache standalone migration to LSWS, or even LSWS native configuration,​ you can [[litespeed_wiki:​php:​lsapi|complie your PHP]] by matching it to your existing Apache PHP configuration or [[litespeed_wiki:​php:​lsapi|configure and compile PHP]] for your native LSWS need. You can also [[litespeed_wiki:​php:​rpm|install LSPHP through RPMS]] if your system is CentOS, or [[litespeed_wiki:​php:​lsapi_ubuntu_debian|install packages]] for your Debian/​Ubuntu System. We have LiteSpeed CentOS RPM repository updated regularly, though, no Ubuntu package repository ​yet at the time of this writing. For CloudLinux ​System, you can [[litespeed_wiki:​cl_phpselector_how_to|setup PHP Selector]] since it works well with LiteSpeed.+For other control panels, Apache standalone migration to LSWS, or even LSWS native configuration,​ you can [[litespeed_wiki:​php:​lsapi|complie your PHP]] by matching it to your existing Apache PHP configuration or [[litespeed_wiki:​php:​lsapi|configure and compile PHP]] for your native LSWS need. You can also [[litespeed_wiki:​php:​rpm|install LSPHP through RPMS]] if your system is CentOS, or [[litespeed_wiki:​php:​lsapi_ubuntu_debian|install packages]] for your Debian/​Ubuntu System. We have LiteSpeed CentOS RPM repository updated regularly, though, ​there is no Ubuntu package repository ​available ​at the time of this writing. For CloudLinux ​Systems, you can [[litespeed_wiki:​cl_phpselector_how_to|setup PHP Selector]] since it works well with LiteSpeed.
  
 +[[litespeed_wiki:​multiple_phps_in_control_panel_lsws|Multi Versions of PHP]] can be setup for different Virtual Hosts.[[http://​open.litespeedtech.com/​mediawiki/​index.php/​Help:​Multiple_PHPs|A multiple PHPs guild for Open LiteSpeed]] is also worth looking into since it is applied to Enterprise as well.
 +
 +If you run into 503 errors, this is often indicative of a problem with PHP. Please see our [[litespeed_wiki:​php_503_error|503 troubleshooting guide]] for the necessary steps to diagnose and fix these errors.
  
  
Line 33: Line 36:
 If you are unsure which SAPI you have compiled PHP for, you can check this using the following command: If you are unsure which SAPI you have compiled PHP for, you can check this using the following command:
   [lsws_home]/​fcgi-bin/​lsphp -v   [lsws_home]/​fcgi-bin/​lsphp -v
 +
 +{{ litespeed_wiki:​lsphp5-external-app.png?​800 }}
 +
 +If you like the command line, you can set or modify the external application from LSWS configuration file:
 +  vi /​usr/​local/​lsws/​conf/​httpd_config.xml
 +  ​
 +Some example configuration:​
 +    <​extProcessor>​
 +      <​type>​lsapi</​type>​
 +      <​name>​lsphp5</​name>​
 +      <​address>​uds://​tmp/​lshttpd/​lsphp5.sock</​address>​
 +      <​note></​note>​
 +      <​maxConns>​35</​maxConns>​
 +      <​env>​PHP_LSAPI_MAX_REQUESTS=500</​env>​
 +      <​env>​PHP_LSAPI_CHILDREN=35</​env>​
 +      <​initTimeout>​60</​initTimeout>​
 +      <​retryTimeout>​0</​retryTimeout>​
 +      <​persistConn>​1</​persistConn>​
 +      <​pcKeepAliveTimeout></​pcKeepAliveTimeout>​
 +      <​respBuffer>​0</​respBuffer>​
 +      <​autoStart>​1</​autoStart>​
 +      <​path>​$SERVER_ROOT/​fcgi-bin/​lsphp5</​path>​
 +      <​backlog>​100</​backlog>​
 +      <​instances>​1</​instances>​
 +      <​runOnStartUp></​runOnStartUp>​
 +      <​extMaxIdleTime>​10</​extMaxIdleTime>​
 +      <​priority>​0</​priority>​
 +      <​memSoftLimit>​2047M</​memSoftLimit>​
 +      <​memHardLimit>​2047M</​memHardLimit>​
 +      <​procSoftLimit>​400</​procSoftLimit>​
 +      <​procHardLimit>​500</​procHardLimit>​
 +    </​extProcessor>​
 +
 +Make sure the external app binary path set to the right location.
 +
  
 ===== The script or context handler ===== ===== The script or context handler =====
Line 38: Line 76:
 Script and context handlers tell the server which files go to a certain application. A script handler uses a file's suffix (and associated MIME types). Script handlers differentiate content based on the file’s suffix (and the coressponding MIME type). Setting up an external application as a script handler (in the Script Handler tab at either the server or virtual host level) will cause the server to send certain types of files to that external application. When configured as a context handler, an external application will be used for content based on its location, not its file type. The web server will send content to the external application as long as the request’s URL matches the URI specified in the context settings. Context handlers can only be configured at the virtual host level (Configuration > Virtual Hosts > your virtual host > Context). Script and context handlers tell the server which files go to a certain application. A script handler uses a file's suffix (and associated MIME types). Script handlers differentiate content based on the file’s suffix (and the coressponding MIME type). Setting up an external application as a script handler (in the Script Handler tab at either the server or virtual host level) will cause the server to send certain types of files to that external application. When configured as a context handler, an external application will be used for content based on its location, not its file type. The web server will send content to the external application as long as the request’s URL matches the URI specified in the context settings. Context handlers can only be configured at the virtual host level (Configuration > Virtual Hosts > your virtual host > Context).
  
 +{{ litespeed_wiki:​lsphp-script-handler-1.png?​800 }}
  
 +{{ litespeed_wiki:​lsphp-script-handler-2.png?​800 }}
 ===== Environment variables ===== ===== Environment variables =====
  
 Once configured, you can also use environment variables to further customize PHP via LSAPI and FCGI. For detailed information on environment variables, please refer to the [[litespeed_wiki:​php_fcgi_environment_variables|What Environment Variables Can I Use to Configure a PHP fCGI Application?​]] wiki and the README file in the php/​sapi/​litespeed directory. ​ Once configured, you can also use environment variables to further customize PHP via LSAPI and FCGI. For detailed information on environment variables, please refer to the [[litespeed_wiki:​php_fcgi_environment_variables|What Environment Variables Can I Use to Configure a PHP fCGI Application?​]] wiki and the README file in the php/​sapi/​litespeed directory. ​