Enable PHP opcode cache for LiteSpeed

Choosing an opcode cache

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 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.

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 LSPHP SuEXEC mode.

For shared hosting environments:PHP SuEXEC

For shared hosting environments such as cPanel or Plesk, you should use the PHP SuEXEC mode. LSWS Web Admin → Server → General → Using Apache Configuration File → PHP suEXEC → Yes. When you check a user's phpinfo page, it may show that Zend Opcode Cache is installed and enabled. However there are three PHP SuEXEC modes for LiteSpeed: suEXEC Worker Mode, suEXEC Daemon Mode and suEXEC ProcessGroup Mode.

You may follow 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. If using opcode cache, you will need to change to suEXEC Daemon Mode or suEXEC 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:

Set Auto Start to "Yes".
Set Run On Start Up to "suEXEC Daemon".

To set up 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.

Example configuration:

<IfModule LiteSpeed>
LSPHP_ProcessGroup on
LSPHP_Workers 15
</IfModule>

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.

More details about PHP SuEXEC or non-SuEXEC here.

 
litespeed_wiki/php/enable_opcode_cache.txt · Last modified: 2017/12/08 19:09 by Jackson Zhang