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:enable_opcode_cache [2016/06/29 13:45]
Rob Holda [How to enable PHP opcode cache for litespeed?]
litespeed_wiki:php:enable_opcode_cache [2019/05/17 21:18] (current)
Kacey Schroeder [For Shared Hosting Environments: PHP SuEXEC]
Line 1: Line 1:
-====== Enable PHP opcode cache for LiteSpeed ======+====== Enable PHP Opcode Cache for LiteSpeed ======
  
-===== Which opcode cache to choose? ​=====+===== Choosing an Opcode Cache =====
  
-Since php 5.5, Zend Opcode ​cache has been included in php main packages ​distribution. You can easily ​install it through yum or apt-get. For php 5.4 and lower, you may choose ​[[litespeed_wiki:​php:​apc|APC cache]]. APC cache already ​include php opcode cache and user cache. ​ To use user/​variable cache for php 5.5 and up with zend opcode ​cache only, you may add apcu as addition+Since PHP 5.5, Zend Opcode ​Cache has been included in the PHP main package ​distribution ​and can be easily ​installed ​through yum or apt-get. For PHP 5.4 and lower, you can use [[litespeed_wiki:​php:​apc|APC cache]]. APC cache already ​includes PHP opcode cache and user cache. To use user/​variable cache for PHP 5.5 and up with Zend Opcode ​cache only, you may also add apcu. 
  
 +Xcache may also be used with PHP up to version 5.6, but not 7.0.
  
-For Xcache, it can be used upto php 5.6, but not 7.0.+===== How to Enable Opcode Cache for LiteSpeed =====
  
-===== How to enable opcode ​cache for LiteSpeed =====+Opcode ​cache can be easily installed through yum or apt-get. To see if it has been enabled, check the corresponding phpinfo page. If you use the PHP non-EXEC mode you may be finished at this point, however when using PHP SuEXEC mode for shared hosting environments such as cPanel or Plesk, you also have to choose the right PHP process mode. 
  
-You can install opcode cache through yum or apt-get easily. Check corresponding phpinfo page to see if it has been enabled. Don't think it is done at this point. It may be done when you use PHP non-EXEC mode, however when using PHP SuEXEC mode for shared hosting environment,​ such as cPanel or plesk, you have to choose right LSPHP SuEXEC ​mode. +==== For Shared Hosting Environments: ​PHP SuEXEC ​====
  
-==== For shared hosting ​environment:​PHP SuEXEC ==== +For shared hosting ​environments ​such as cPanel ​or Plesk, you should use PHP SuEXEC mode as your execution method**Configuration ​> Server > General > Using Apache Configuration File > PHP suEXEC** to ''​Yes''​. When you check a user'​s ​phpinfo page, it may show that Zend Opcode Cache is installed and enabled. ​ 
-For shared hosting environment, ​such cpanel ​or plesk, you should use PHP SuEXEC mode. LSWS Web Admin -> Server ​-> General ​-> Using Apache Configuration File -> PHP suEXEC ​-> Yes.  When you check a phpinfo page for a user, it may have installed and enabled ​Zend opcode cache. However ​There are three PHP SuEXEC mode for LiteSpeed: ​suEXEC ​Worker ​ModesuEXEC ​Daemon ​Mode and suEXEC ​ProcessGroup ​Mode. You may follow [[litespeed_wiki:​php:​which_php_setup_am_i_using#​which_suexec_mode_am_i_using|this wiki]] to check which SuEXEC ​mode you are using. suEXEC Daemon Mode and suEXEC ProcessGroup Mode support opcode cache while the default suEXEC Worker Mode does not.  Please change to suEXEC Daemon Mode or suEXEC ProcessGroup Mode if required.+However ​there are also three PHP process modes for LiteSpeed: Worker ​mode, Daemon ​mode and ProcessGroup mode. 
  
-To set up suEXEC ​Daemon mode, you need only adjust your server-level LSPHP external application settings in the WebAdmin console > Configuration > External App > your LSPHP external application:​+You may follow [[litespeed_wiki:​php:​which_php_setup_am_i_using#​which_suexec_mode_am_i_using|this wiki]] to check which PHP process mode you are using. ​Daemon mode and ProcessGroup mode support opcode cache while Worker mode does not. If using opcode cache, you will need to change to Daemon mode or ProcessGroup mode.
  
-  ​Set Auto Start to "​Yes"​. +=== How to Set up Daemon mode === 
-  Set Run On Start Up to "​suEXEC ​Daemon".+To set up Daemon ​mode, you need only adjust your server-level LSPHP external application settings in the WebAdmin console > Configuration > External App > your_LSPHP_external_app:​
  
-To setup ProcessGroup,​ you need to place the directive LSPHP_ProcessGroup in an httpd.conf file. This can be done at the server or virtual host level. If done at the server level, all virtual hosts will use ProcessGroup. If done at the virtual host level, only that virtual host will use ProcessGroup.+  Set Start By Server to "​Yes"​. 
 +  Set Run On Start Up to "Yes (Daemon mode)"​. 
 + 
 +=== How to Set up ProcessGroup Mode === 
 +To set up ProcessGroup ​mode, you need to place the directive LSPHP_ProcessGroup in an httpd.conf file. This can be done at the server or virtual host level. If done at the server level, all virtual hosts will use ProcessGroup. If done at the virtual host level, only that virtual host will use ProcessGroup.
  
 Example configuration:​ Example configuration:​
Line 29: Line 34:
   </​IfModule>​   </​IfModule>​
  
-==== For non-shared hosting environment:​PHP non-SuEXEC ==== +=== ProcessGroup Mode vs. PHP-FPM ​=== 
-For non-shared hosting ​environment,​ you should use PHP non-exec mode. (LSWS Web Admin -> Server ​-> General ​-> Using Apache Configuration File -> PHP suEXEC ​-> No). LSPHP just runs as workgroup mode as "​nobody"​ user for default. For this situation, as long as you see opcode cache in phpinfo page, opcode cache has been enabled ​already.+ 
 +ProcessGroup Mode is similar to Apache php-fpm mode. The difference is: with Apache, the parent process of php-fpm is not controlled by Apache, and it keeps running; with LiteSpeed, LiteSpeed uses LSAPI, and the PHP will exit if idle for a while (in a shared hosting environment ​and set at [[https://​www.litespeedtech.com/​docs/​webserver/​config/​extapps/​lsapi#​extMaxIdleTime|"​Max Idle time"​]]). ​ For LSWS 5.2.8 and lower versions, PHP processes will stop when LSWS restarts, and the opcode cache will be reset. Starting from LSWS 5.3RC2 and above, LSPHP will run in detached mode and an LSWS restart //​won'​t//​ stop PHP processes. The LSPHP parent will just follow the timeout where [[https://​www.litespeedtech.com/​docs/​webserver/​config/​extapps/​lsapi#​extMaxIdleTime|"​Max Idle time"​]] is set. 
 + 
 +Please keep in mind that keep idle PHP process running longer will occupy server resources and there is a risk to overload the server if there is not enough resources.  
 + 
 +=== Sharing Opcode Cache Between Multiple CPU Processes === 
 +For LSWS Web Host Professional and above licenses, you have an option to [[litespeed_wiki:​cpanel:​multi-litespeed-processes|configure LSWS to use multi CPU cores]]. For LSWS 5.2.x and below, When a domain is served by multi-CPU cores, Opcode cache cannot be shared between CPU cores. ​ So, when you test a ''​phpinfo.php''​ page, you might see cache hits like the following upon refresh: 
 + 
 +  http://​example.com/​phpinfo.php 
 +     
 +  505 
 +  0 
 +  1 
 +  506 
 +  507 
 +  1 
 +  2 
 + 
 +As of LiteSpeed Web Server v5.3RC2 and above, LSWS //can share opcache between Multi CPU processes//​. 
 + 
 +==== For Non-Shared Hosting Environments: PHP non-SuEXEC ==== 
 + 
 +Non-shared hosting ​environments ​should use PHP non-exec mode. (**LSWS Web Admin > Server > General > Using Apache Configuration File > PHP suEXEC** = ''​No''​). LSPHP just runs in ''​workgroup'' ​mode as the "​nobody"​ user by default. For this situation, as long as you see opcode cache in the phpinfo page, opcode cache has already ​been enabled.
   ​   ​
-Check details about [[litespeed_wiki:​php:​which_php_setup_am_i_using|PHP SuEXEC or non-SuEXEC here]].+More details about [[litespeed_wiki:​php:​which_php_setup_am_i_using|PHP SuEXEC or non-SuEXEC here]].
  
  
  • Admin
  • Last modified: 2016/06/29 13:45
  • by Rob Holda