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:php:configuring-lsws-for-php [2016/07/25 16:23]
Jackson Zhang [Overview of LiteSpeed and PHP]
litespeed_wiki:php:configuring-lsws-for-php [2019/06/20 13:41] (current)
Jackson Zhang [Step 2: Set the external application]
Line 1: Line 1:
-===== Overview of LiteSpeed ​and PHP =====+===== Configuring ​LiteSpeed ​Web Server for PHP =====
  
-LiteSpeed Web Server comes pre-configured for PHP 5, /​usr/​local/​lsws/​fcgi-bin/​lsphp5,​ however it is for  testing only and can not be used for real applications. Users should install php binary through "yum install"​ or "​apt-get"​ lsphp packages from LiteSpeed Repositories ​or compile from source code to set up special configurations for PHP at either the server or virtual host level. PHP external application and  script or context handler should be setup before PHP can be used. This wiki reviews how PHP is configured with LiteSpeed Web Server.+LiteSpeed Web Server comes pre-configured for PHP 5, ''​/​usr/​local/​lsws/​fcgi-bin/​lsphp5''​, however it is for  testing only and can not be used for real applications. Users should install php binary through "yum install"​ or "​apt-get"​ lsphp packages from LiteSpeed Repositories. PHP external application and script or context handler should be setup before PHP can be used. 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 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: ​LSAPI 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, if you are using EasyApache 3, PHP should be built and working fine with Apache through EA3, then LiteSpeed builds matching PHP (with LSAPI) through LiteSpeed WHM/cPanel plugin. See [[litespeed_wiki:​cpanel:​auto-installer|cPanel installation Guide]]. For EA4, no php build any more and please refer [[litespeed_wiki:​cpanel:​easyapache4-config|here]] instead+For cPanel, if you are using EasyApache 3, PHP should be built and working fine with Apache through EA3, then LiteSpeed builds matching PHP (with LSAPI) through LiteSpeed WHM/cPanel plugin. See [[litespeed_wiki:​cpanel:​auto-installer|cPanel installation Guide]]. For EA4, PHP no longer needs to be built, ​please refer [[litespeed_wiki:​cpanel:​easyapache4-config|here]] instead.
  
 For Plesk, please refer [[litespeed_wiki:​plesk:​php_guide|here]]. For Plesk, please refer [[litespeed_wiki:​plesk:​php_guide|here]].
Line 13: Line 13:
 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 CloudLinux PHP Selecor, please refer [[litespeed_wiki:​cloudlinux:​php-selector|here]].+For CloudLinux PHP Selector, please refer [[litespeed_wiki:​cloudlinux:​php-selector|here]].
  
-If no control panel php or no CloudLinux ​php used, we suggest to install ​php packages through rpms/​apt-get packages. PHP source code compiling is another alternative option but it is not recommend unless there is special ​requirement.+If no control panel PHP or no CloudLinux ​PHP is used, we suggest to install ​PHP packages through rpms/​apt-get packages. PHP source code compiling is another alternative option but it is not recommend unless there are special ​requirements.
  
-If you PHP runs 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 necessary steps to diagnose and fix these errors.+If your PHP runs 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 necessary steps to diagnose and fix these errors.
  
 +===== Step 1: Install LSPHP through repositories =====
 +If you are not using a Control Panel or CloudLinux, you may need to install the LSPHP Binary through rpms/​apt-get packages. ​
  
 +|[[litespeed_wiki:​php:​rpm|Installing LSPHP via RPM]]|The fastest way to get PHP for CentOS|
 +|[[litespeed_wiki:​php:​apt|Installing LSPHP via APT]]|The fastest way to get PHP for Debian/​Ubuntu|
  
  
  
  
-===== The external application ===== 
  
-Defining a external application in LSWS's settings tells the server how to handle dynamic content. (In this case you are defining a PHP external application to tell the server how to handle PHP scripts.) When adding an external application,​ you will be first asked to choose the "​Type"​. This refers to which SAPI (either LSAPI or FastCGI, in the case of PHP) will be used to communicate with the application. ​ + 
 +===== Step 2: Set the external application ===== 
 + 
 +Defining a external application in LSWS's settings tells the server how to handle dynamic content. (In this case you are defining a PHP external application to tell the server how to handle PHP scripts.) When adding an external application,​ you will be first asked to choose the "​Type"​. This refers to which SAPI (either LSAPI or FastCGI, in the case of PHP) will be used to communicate with the application. ​
  
 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
 +  ​
 +An external application can be added from the WebAdmin Console under **Server > External App**. Here a new external application of type ''​LSAPI''​ should be created with **Command** being set to the path of the PHP binary you intend to use. It is also recommended to set **Instances** to ''​1''​ and add an ''​LSAPI_CHILDREN''​ environment variable to **Environment** equal to the value set for **Max Connections**.
  
 {{ litespeed_wiki:​lsphp5-external-app.png?​800 }} {{ litespeed_wiki:​lsphp5-external-app.png?​800 }}
Line 43: Line 51:
       <​note></​note>​       <​note></​note>​
       <​maxConns>​35</​maxConns>​       <​maxConns>​35</​maxConns>​
-      <​env>​PHP_LSAPI_MAX_REQUESTS=500</​env>​+      <​env>​PHP_LSAPI_MAX_REQUESTS=5000</​env>​
       <​env>​PHP_LSAPI_CHILDREN=35</​env>​       <​env>​PHP_LSAPI_CHILDREN=35</​env>​
       <​initTimeout>​60</​initTimeout>​       <​initTimeout>​60</​initTimeout>​
Line 63: Line 71:
     </​extProcessor>​     </​extProcessor>​
  
-Make sure the external app binary path set to the right location.+Make sure the **external app binary path** set to the installed php binary or other right location.
  
 +For example: update command path to **/​usr/​local/​lsws/​lsphp56/​bin/​lsphp**.
  
-===== The script or context handler ===== 
  
-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).+===== Step 3: Configure the script or context handler ===== 
 + 
 +Script and context handlers tell the server which files go to a certain application. Script handlers differentiate content based on the file’s suffix (and the corresponding ​MIME type). Setting up script handler for an external application (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 ​instead ​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. 
 + 
 +Both handler types can be configured in the WebAdmin Console with script handlers configured under **Configuration > Server > Script Handler** or **Configuration >Virtual Hosts > your_virtual_host > Script Handler**, and context handlers ​configured at the virtual host level under **Configuration > Virtual Hosts > your_virtual_host ​> Context**. 
 + 
 +To create a server level script handler for LSPHP, first got to **Configuration > Server > Script Handler** in the WebAdmin Console. Here, add a new script handler and set **Suffix** to ''​php''​ or ''​php5''​ for example, depending on the suffix of your PHP scripts. **Handler Type** should be set to ''​LiteSpeed SAPI''​ and **Handler Name** set to the name of your previously created external application.
  
 {{ litespeed_wiki:​lsphp-script-handler-1.png?​800 }} {{ litespeed_wiki:​lsphp-script-handler-1.png?​800 }}
  
 {{ litespeed_wiki:​lsphp-script-handler-2.png?​800 }} {{ litespeed_wiki:​lsphp-script-handler-2.png?​800 }}
-===== 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+===== Step 4: Perform a Graceful Restart ===== 
 +Perform a graceful restart to apply these changes and begin using the defined external application for scripts matching the suffix set in the related script handler. This can be done in the WebAdmin Console under **Actions > Graceful Restart**. 
 + 
 + 
 +===== How to enable PHP SuEXEC on LSWS native ===== 
 +If you want to run PHP as user:group instead of webserver user such as ''​nobody''​, you will need to create external apps (name should be unique and different than server level external apps and other virtual host external apps, for example, lsphp_$vhost; ​also set it to run as username:​usergroup to implement ​PHP SuEXEC) ​and script handler pointing ​to the newly created external app under each virtual host. 
 +{{ :litespeed_wiki:​php:​lsws-navie-php-suexec.png?800 |}}
  • Admin
  • Last modified: 2016/07/25 16:23
  • by Jackson Zhang