Read More

PHP LSAPI Administration

Using LiteSpeed PHP with LiteSpeed Web Server

PHP support has been configured out of box for PHP 4 and PHP 5. Many users will want to compile their own PHP version, though. If you compile PHP using LSWS's Compile PHP feature (WebAdmin console > Actions > Compile PHP), this new PHP will be automatically accessed by the default PHP configurations.

Below are brief instructions for creating new implementations of LSPHP yourself: (More complete guides can be found in our wiki.)

  1. Add an external application: Log into the WebAdmin console. Go to Server > External App. Add an external application of type "LSAPI app". "Command" should be set to the path of the PHP binary. "Instances" should be set to "1". Add an "LSAPI_CHILDREN" environment variable to match the value of "Max Connections". Do not set it to a large value. "20" is a good value to start with.
  2. Create a script handler: Go to Server > Script Handler. Add a script handler and set "suffix" to "php" or "php5", depending on the suffix of your PHP scripts. "Handler Type" should be set to "LiteSpeed SAPI". "Handler Name" should be the name of external application you just added.
  3. Graceful restart to apply changes: (WebAdmin console > Actions > Graceful Restart) Scripts with the suffix you defined in the script handler will now use the external application you created.

Generate formatted PHP source code in html

Since PHP LiteSpeed SAPI 4.3, PHP LSAPI has been capable of generating formatted PHP source code in html. This can be turned on for a process using the command line option -s. If you want LSWS to generate PHP source code for files with certain suffix, "phps" for example, add a dedicated external application with "-s" at the end of the "Command" setting. Then add a script handler for the suffix "phps".

Start LSPHP from the command line

Usually, LSPHP is managed by LiteSpeed Web Server. In a clustered environment, though, with one LiteSpeed Web Server or LiteSpeed Load Balancer at the front load balancing LSPHP processes running on multiple backend servers, it may be necessary to start LSPHP processes manually. LSPHP is an executable and can be started manually and bound to IPv4, IPv6, or Unix domain socket addresses with the command line option -b socket_address


Have LSPHP bind to port 3000 on all IPv4 and IPv6 addresses:

./lsphp -b [::]:3000

Have LSPHP bind to port 3000 on all IPv4 addresses:

./lsphp -b *:3000

Have LSPHP bind to address :

./lsphp -b

Have LSPHP accept requests on Unix domain socket "/tmp/lsphp_manual.sock":

./lsphp -b /tmp/lsphp_manual.sock