Wiki

Overview of LiteSpeed and PHP

LiteSpeed Web Server comes configured for PHP 4 and PHP 5. Normally, there is no need to even change the default settings (though users should compile a newer version of PHP than the one that comes with LiteSpeed Web Server). Users may, however, wish to set up special configurations for PHP at either a server or virtual host level. This wiki reviews how PHP is configured with LiteSpeed Web Server.

Unlike Apache's mod_php, which embeds the PHP engine inside web server processes, LiteSpeed Web Server talks to standalone PHP engine processes via a PHP SAPI interface. This allows the web server to delegate processes to different processors and efficiently handle multiple tasks. Two types of PHP SAPI interfaces are supported by LiteSpeed: LiteSpeed and FastCGI. LiteSpeed SAPI (LSAPI) has similar architecture to the FastCGI SAPI with two major enhancements:

  1. up to 50% better performance
  2. support for dynamic PHP configuration changes through web server configuration and .htaccess files.

Requirements for PHP

A pre-built PHP executable with minimum features configured is installed in {cmd}[lsws_home]/fcgi-bin/php{/}. You should, however, replace this with a newer, customized PHP executable (if only for security reasons). You can compile PHP from the command line (be sure to include “–with-litespeed” in your configurations if you want to use LSAPI), using a control panel, or with the Compile PHP feature in the WebAdmin console (Actions > Compile PHP).

To use PHP, the server must have two features set up:

  1. a PHP external application (WebAdmin console > Configuration > External App > Add)</li>
  2. a script or context handler which maps to the PHP external application (WebAdmin console > Configuration > Script Handler > Add or WebAdmin console > Configuration > Virtual Hosts > any virtual host > Context > Add)

(As noted before, LiteSpeed Web Server comes preconfigured with basic settings for both PHP 4 and PHP 5. You will notice that external applications and script handlers have already been set up at the server level. There is no need to modify these, though you may wish to.)

The external application

Defining a external application in LSWS's settings tells the server how to handle dynamic content. (In this case you are defining a PHP external application to tell the server how to handle PHP scripts.) When adding an external application, you will be first asked to choose the “Type”. This refers to which SAPI (either LSAPI or FastCGI, in the case of PHP) will be used to communicate with the application.

If you are unsure which SAPI you have compiled PHP for, you can check this using the following command:

[lsws_home]/fcgi-bin/php -v

The script or context handler

Script and context handlers tell the server which files go to a certain application. A script handler uses a file's suffix (and associated MIME types). Script handlers differentiate content based on the file’s suffix (and the coressponding MIME type). Setting up an external application as a script handler (in the Script Handler tab at either the server or virtual host level) will cause the server to send certain types of files to that external application. When configured as a context handler, an external application will be used for content based on its location, not its file type. The web server will send content to the external application as long as the request’s URL matches the URI specified in the context settings. Context handlers can only be configured at the virtual host level (Configuration > Virtual Hosts > your virtual host > Context).

Environment variables

Once configured, you can also use environment variables to further customize PHP via LSAPI and FCGI. For detailed information on environment variables, please refer to the What Environment Variables Can I Use to Configure a PHP fCGI Application? wiki and the README file in the php/sapi/litespeed directory.

 
litespeed_wiki/how_do_i_configure_lsws_for_php.txt · Last modified: 2013/05/24 10:31 (external edit)