How do I Set Up Virtual-Host-Specific PHP?

By default virtual hosts inherit the version of PHP that is set at the server level. You may wish to use a different PHP version for certain virtual hosts. Follow the steps below to set up virtual-host-level PHP. Here we will use the PHP version 7.4 as an example.

Install PHP 7.4 and commonly used PHP extensions:

apt-get install lsphp74 lsphp74-common lsphp74-curl lsphp74-imagick lsphp74-imap lsphp74-json lsphp74-memcached lsphp74-mysql lsphp74-opcache lsphp74-redis -y

Navigate to WebAdmin console > Server Configuration > External App > Add > Type > LiteSpeed SAPI App to set up a server-level external application. Set the following values:

  • Namelsphp74
  • Addressuds://tmp/lshttpd/lsphp74.sock
  • Max Connections35
  • EnvironmentLSAPI_AVOID_FORK=200M
  • Initial Request Timeout (secs)60
  • Retry Timeout (secs)0
  • Command/usr/local/lsws/lsphp74/bin/lsphp
  • Instances1

Navigate to WebAdmin console > Virtual Hosts > your vhost > Script Handler > Add to add a virtual-host-level PHP handler. Set the following values:

  • Suffixesphp
  • Handler TypeLiteSpeed SAPI
  • Handler Name[Server Level]:lsphp74

OpenLiteSpeed come with php detached mode by default, so need to restart php with command killall -9 lsphp to make settings take effect.

Category: OpenLiteSpeed