Skip to content

Configure via External App

By default, OpenLiteSpeed launches lsphp processes by using server-level PHP, which runs as nobody:nobody with the global php.ini settings. This means that all of your virtual hosts that are running the same PHP version will all be using the same PHP settings and the same user:group.

For a shared hosting environment, you may prefer PHP to run as user:usergroup. In order to set up each virtual host to run PHP as SuEXEC instead of nobody:nobody you will need to set three settings in each virtual host:

  • External App Set UID Mode
  • suEXEC User
  • suEXEC Group

[

In the WebAdmin Console, navigate to Virtual Host configuration > Basic, and set the following values:

  • External App Set UID Mode: DocRoot UID
  • suEXEC User: $VH_USER
  • suEXEC Group: $VH_USER

Once these values are set, the virtual host will run PHP as SuEXEC based on the server-level lsphp external app settings.

Use a virtual-host-level external app

Using a virtual-host-level external lsphp app will give you the ability to change PHP settings for that virtual host or domain instead of using server-level external lsphp apps. This is not necessary in most cases, so virtual-host-level external apps are not created automatically during the initial OLS installation. If you have a need for such an app, you must create it manually.

There are three steps involved: - Creating the external app - Creating a script handler - Overriding the global php.ini (optional)

In the following example, we'll work within the Example virtual host, and create and configure a virtual-host-level external app called lsphp-example.

Create the external app

Navigate to Virtual Host configuration > External App and create a new app. The name and address of the external app you create should be unique, different than any other server-level or virtual-host-level external apps.

Set the following:

  • Name: lsphp-example
  • Address: uds://tmp/lshttpd/lsphp-example.sock

To ensure that the app runs as SuEXEC, set the following to the appropriate user's username. In our example, the username is john.

  • Run As User: john
  • Run As Group: john

Create a script handler

Navigate to Virtual Host configuration > Script Handler. Create a new script handler and give it the following settings:

  • Suffixes: php
  • Handler Type: LiteSpeed SAPI
  • Handler Name: [VHost Level]: lsphp-example

Override the global php.ini

If your global PHP settings are not appropriate for the newly created virtual-host-level external app, you can override them. There are two different approaches you can take:

  • Override individual settings
  • Use an entirely different php.ini file

The easiest way is to override individual settings in the virtual host configuration, but if you have many settings to override, you may prefer to have the virtual host use a completely different php.ini.

Override individual settings

Navigate to Virtual Host configuration > General, then click the Edit button in the php.ini Override section.

Here're some examples of overrides you can add:

php_value include_path ".:/usr/local/lib/php"
php_admin_flag engine on
php_admin_value open_basedir "/home"
php_admin_flag log_errors On
php_admin_value error_log logs/php_error_log
php_value memory_limit 1024M

Use a new php.ini file

Create a new php.ini by copying the contents of the global php.ini. This is important so that all of the modules are loaded.

cat /usr/local/lsws/lsphp73/etc/php.ini > /home/example.com/public_html/php.ini

Tip

Remember to change the new php.ini's path to match your vhost's actual web root.

Edit the new php.ini file to change any settings that you wish to change.

Optionally, you may want to use a .user.ini file for some users. This option can be used on a single directory when it's necessary for a particular setting to be different from the vhost-level or the server-level setting.

Navigate to the user's subdirectory and a create a new .user.ini file. Add only the settings you wish to be different. For example, if you wanted to give this user a memory limit of 768M, you would add the following line to the file:

memory_limit = 768M

Edit the external app you created earlier in the WebAdmin Console, and add the following line to Environment:

PHP_INI_SCAN_DIR=/home/example.com/public_html

If you also want to use .user.ini, also add the following line to Environment:

LSPHP_ENABLE_USER_INI=on

Save your changes and restart OpenLiteSpeed.