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:detached_mode [2018/08/20 15:31]
Jackson Zhang [PHP Auto Configuration for different Control Panels]
litespeed_wiki:php:detached_mode [2020/02/26 22:53] (current)
Lucas Rolff Bump to PHP 7.4
Line 1: Line 1:
 ====== PHP Detached Mode in LiteSpeed Web Server ====== ====== PHP Detached Mode in LiteSpeed Web Server ======
  
-===== What'​s ​PHP detached mode? ===== +===== What is PHP Detached Mode? ===== 
-PHP Detached Mode is a big feature available in LSWS 5.3 and later. ​+PHP Detached Mode is a big feature available in LSWS 5.3 and later. OpenLiteSpeed supports PHP detached mode starting from 1.5.6.
  
 In previous versions (LSWS 5.2.x and below), all PHP processes were attached to LiteSpeed Web Server processes. As such, when LiteSpeed Web Server restarted, so would the PHP processes. In PHP Detached Mode, the PHP processes will continue running independently,​ even when LiteSpeed Web Server restarts.  ​ In previous versions (LSWS 5.2.x and below), all PHP processes were attached to LiteSpeed Web Server processes. As such, when LiteSpeed Web Server restarted, so would the PHP processes. In PHP Detached Mode, the PHP processes will continue running independently,​ even when LiteSpeed Web Server restarts.  ​
  
-When you run in PHP Process Group Mode, PHP process groups are still started by the ''​litespeed''​ process. When the first request for a specific PHP process group comes in, if PHP is not running it, it will be started by LiteSpeed. ''​pstree''​ will show that PHP process is child of the ''​litespeed''​ process. That's normal. What's new is that, as of 5.3, once the ''​litespeed''​ process exits, the PHP process won't quit. It will become independent.+When you run in PHP ProcessGroup ​Mode, PHP process groups are still started by the ''​litespeed''​ process. When the first request for a specific PHP process group comes in, if PHP is not running it, it will be started by LiteSpeed. ''​pstree''​ will show that PHP process is child of the ''​litespeed''​ process. That's normal. What's new is that, as of 5.3, once the ''​litespeed''​ process exits, the PHP process won't quit. It will become independent.
  
-===== Benefit of PHP detached mode? =====+===== Benefit of PHP Detached Mode =====
  
 PHP Detached Mode provides an advantage, especially when hundreds of accounts are hosted on the same shared hosting server, with new accounts being rapidly added to it. In cases like this, there is no need to restart all PHP processes during the web server restart. Also, when a user is heavily relying on opcode to reduce the server load, PHP Detached Mode avoids an opcode cache reset during the server restart. ​ PHP Detached Mode provides an advantage, especially when hundreds of accounts are hosted on the same shared hosting server, with new accounts being rapidly added to it. In cases like this, there is no need to restart all PHP processes during the web server restart. Also, when a user is heavily relying on opcode to reduce the server load, PHP Detached Mode avoids an opcode cache reset during the server restart. ​
  
-===== How to restart ​detached PHP processes? ​=====+ 
 +===== How to Enable PHP Detached Mode ===== 
 +If you are using a control panel, LSWS 5.3 will enable PHP detached ​mode automatically.  
 + 
 +If you are using LSWS 5.3 (native), and explicitly configured an external application for each virtual host, you will need to set **Run on Startup** to ''​PHP Detached Mode''​. ​  
 +===== Restart Detached ​PHP Processes ​=====
 In the past, if there were any ''​php.ini''​ changes, you would probably want to restart LSWS to apply the changes(since LSWS will restart PHP processes). ​ In the past, if there were any ''​php.ini''​ changes, you would probably want to restart LSWS to apply the changes(since LSWS will restart PHP processes). ​
  
-As of LSWS 5.3, PHP will be running as detached mode and won't be restarted during LSWS restart. If you want to make You can make  ​''​php.ini''​ changes effective immediately,​ there are a few ways to start php processes.+**As of LSWS 5.3, PHP runs in detached mode and won't be restarted during LSWS restart.** If you want to make ''​php.ini''​ changes effective immediately,​ there are a few ways to restart PHP processes.
  
-==== Restart detached PHP processes for user ==== +==== For User ==== 
-To restart detached PHP processes for account (vhost) level, you can touch a **".lsphp_restart.txt"​** ​file under user's home directory:+To restart detached PHP processes for the account (vhost) level, you can touch a ''​.lsphp_restart.txt'' ​file under the user's home directory, for example ''/​home/​USER1/''​ on a cPanel/WHM server:
  
-  touch <​user_home_dir>​/​.lsphp_restart.txt+  touch /home/USER1/​.lsphp_restart.txt 
 +   
 +Once ''​.lsphp_restart.txt''​ is created, the user's PHP will be restarted when next request comes in.  The file ''​.lsphp_restart.txt''​ won't be removed. LSWS will check the timestamp of the file to decide if the user's detached PHP needs to be restarted or not. You can manually remove it if you want to but it's not necessary. Every time you want to restart that user's detached PHP, you can just touch the file again, whether it already exists or not, in order to refresh the timestamp. ​
  
-==== Restart detached PHP processes for the server ​==== +To maintain CloudLinux mod_lsapi CRIU feature compatibility, ​the server ​will restart PHP if it finds ''​mod_lsapi_reset_me''​ file as well 
-To restart ​detached ​PHP processes for server level, you can touch **".lsphp_restart.txt"​** file under  **"<lsws_server_root>/admin/​tmp/"​** directory:​**,​ usually, is "/​usr/​local/​lsws/​admin/​tmp/"​** directory+   
 +  touch <user_home_dir>/mod_lsapi_reset_me
  
-  touch /​usr/​local/​lsws/​admin/​tmp/​.lspohp_restart.txt+The user may also restart detached PHP processes from the **Advanced** page of the [[litespeed_wiki:​cpanel:​cpanel-plugin|LiteSpeed Web Cache Manager cPanel plugin]], accessible from within the cPanel dashboard.
  
-Running ​detached PHP processes ​will be restartednot immediatelyinstead, as soon as server need use that PHP handler.+==== For the Server ==== 
 +To restart ​detached PHP processes ​for the server levelyou can touch a ''​.lsphp_restart.txt''​ file under the ''<​lsws_server_root>/​admin/​tmp/''​ directory. Usually, that is ''/​usr/​local/​lsws/​admin/​tmp/''​.
  
-==== Stop all lsphp processes immediately ​==== +  touch /​usr/​local/​lsws/​admin/​tmp/​.lsphp_restart.txt 
-To stop all lsphp processes immediately,​ you can manually kill all PHP processes ​from command line:+ 
 +This can also be accomplished from the '​Actions'​ page of the LiteSpeed WebAdmin Console or by using the '​Restart Detached PHP Processes'​ button in the [[litespeed_wiki:​cpanel#​whm_plugin|LiteSpeed cPanel/WHM plugin]]. 
 + 
 +All running detached PHP processes will be restarted, but not immediately. Instead, they will restart as soon as the server needs to use that PHP handler. 
 + 
 +==== Stop All Immediately ​==== 
 +To stop all lsphp processes immediately,​ you can manually kill them from the command line:
 <​code>​killall lsphp</​code>​ <​code>​killall lsphp</​code>​
  
 +===== PHP Processes Won't Run Forever =====
 +PHP Detached Mode doesn'​t mean that PHP will run forever. It will still follow the [[https://​www.litespeedtech.com/​docs/​webserver/​config/​extapps/​lsapi#​extMaxIdleTime |Max Idle Time]] setting. If you want to make PHP live longer, just increase **Max Idle Time**. ​ Never set it to ''​-1''​ to indicate "​unlimited"​ since, in process group mode, values under ''​30''​ will be automatically converted to the default of 30 seconds. If you want PHP to be running longer, try to enter a large number, such as ''​3600''​.
  
-===== Will PHP processes running forever in detached mode ===== +===== When Changes Become Effective ​===== 
-PHP Detached Mode doesn'​t mean that PHP will run forever. It will still follow ​the [[https://​www.litespeedtech.com/​docs/​webserver/​config/​extapps/​lsapi#​extMaxIdleTime |"Max Idle Time"​]] setting. If you want to make PHP live longer, just increase **Max Idle Time**+Changes to Detached Mode will be effective when the app restarts.
  
-===== PHP Auto Configuration for different ​Control Panels ===== +Remember, the Detached Mode app isn't started when the server starts up. It only starts when there is traffic hitting the external app. It will be started on demand, and remain running even if LSWS restarts. 
-In previous ​version lower than LSWS 5.2.x, ​there is a "​External App" section to setup PHP external apps and a "​Script Hander"​ section to setup PHP handlers. ​+ 
 +The same for the restart. Only if an external application is about to serve a request, will it be checked and restarted if needed. 
 +===== PHP Auto Configuration for Different ​Control Panels ===== 
 +In previous ​versions of LSWS (5.2.x and earlier), external apps and PHP handlers ​are set up via the **External App** and **Script Hander** sections, respectively.
  
 {{ :​litespeed_wiki:​php:​lsws5.3-php-detached-mode-php-externalapp.png?​800 |}} {{ :​litespeed_wiki:​php:​lsws5.3-php-detached-mode-php-externalapp.png?​800 |}}
  
-On LSWS 5.3,  PHP external app and PHP script handler ​configurations are not required ​anymore ​and they will be autoconfigured by the web server. If you run upgrade from 5.2.x or previous ​version, external apps settings will be carried over. Actually ​you can delete all PHP external apps and PHP handlers and LSWS will still be working ​fine. If you install a new fresh LSWS 5.3 installation,​ most likely you won't see any PHP external apps and PHP handlers defined there anymore. If you see such, don't worry and it is normal for LSWS 5.3. If you still want to define external apps manually, it is ok, and LSWS will honor the settings which actually override the LSWS 5.3 built-in external apps definition. ​+On LSWS v5.3 and abovethese configurations are no longer ​required. External apps and script handlers ​will be autoconfigured by the web server. If you upgrade ​to v5.3 from an earlier ​version, ​the external apps settings will be carried over. (However, ​you could delete all PHP external apps and PHP handlers and LSWS would still work fine.)
  
 +If you install a new fresh LSWS 5.3 installation,​ you probably won't see any PHP external apps or PHP handlers defined there. Don't worry. This is normal. If you still want to define external apps manually, you can do so. LSWS will honor these settings, and they will override the built-in external apps definition. ​
  
-How to configure PHP setting then if there are no external apps defined there anymore? ​While a new "PHP" ​tab has been created ​in LSWS Web Admin Console and you can set configuration there to detached ​PHP.+Currently, LSWS auto-detects apps and handlers up to PHP 7.4. Two handlers: ''​application/​x-httpd-ea-php71''​ and ''​application/​x-httpd-alt-php71''​ now point to separate handlers, where prior to 5.3, both pointed to the lsphp71 handler configuration.  
 + 
 +So, how do you configure PHP settings ​if there are no external apps defined there anymore? ​See the new **PHP** tab in the Web Admin console to adjust the configuration
 + 
 +Configurations set under the **PHP** tab or in the ''<​phpConfig>''​ section, serve as the default for auto-detected PHP handlers, so the memory limit set there will apply to all detected ​PHP handlers. An explicitly configured PHP handler will still use its own configuration.
    
 {{ :​litespeed_wiki:​php:​lsws5.3-php-detached-mode-php-tab.png?​800 |}} {{ :​litespeed_wiki:​php:​lsws5.3-php-detached-mode-php-tab.png?​800 |}}
  
-===== How to override ​default PHP handler binary path? =====+===== Override the Default PHP Handler Binary Path ===== 
 + 
 +On a WHM/cPanel and CloudLinux environment,​ ''​ea-phpxx''​ is the default handler pointing ​to the Easy Apache PHP binary, and ''​alt-phpxx''​ is the default ​handler pointing to the CloudLinux ​PHP selector binary. ​ If you have any need to override the default ​handler ​binary, for example, to direct ''​ea-php72''​ to ''/​opt/​alt/​php72/​usr/​bin/​lsphp'',​ you can create or modify an internal app. 
 + 
 +Create or modify existing ''​lsphp''​ to ''​ea-php72'':​ 
 +{{ :​litespeed_wiki:​php:​lsws53-php-override1.png?​800 |}} 
 + 
 +Change the PHP binary path
 +{{ :​litespeed_wiki:​php:​lsws53-php-override2.png?800 |}} 
 + 
 + 
 +===== Troubleshooting ​===== 
 + 
 +  * [[litespeed_wiki:​php:​detached_mode:​handlers | Managing ea-phpxx and alt-phpxx differences between LSWS v5.3 and previous versions]]
  
-On a WHM/cPanel and CloudLinux environment,​ ea-phpxx is default handler pointing to easy apache php binary and alt-phpxx is default handler pointing to CloudLinux PHP selector binary. ​ If you have any need to override the default handler binary, for example, you would like to direct ea-php72 to /​opt/​alt/​php72/​usr/​bin/​lsphp,​ you can create/​modify internal app for such override. ​ 
  • Admin
  • Last modified: 2018/08/20 15:31
  • by Jackson Zhang