Change PHP Settings by Vhost/User and set up PHP SuEXEC

You are here:
< Back

By default, OpenLiteSpeed launches lsphp processes by using server-level PHP running as nobody:nobody with the global php.ini settings. This means your ten virtual hosts 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 with customized PHP settings per vhost.

To do this, you will need to create a virtual-host-level external app and script handler.

Creating a Virtual-Host-Level External App

Creating a virtual-host-level external lsphp app will give you the ability to change PHP settings for that virtual host/domain. This app won’t be created automatically during the initial OLS installation. You will need to create it manually. 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, and should have the proper settings assigned to it. For this example, we can call the app “lsphp-example.”

Set Up Virtual Host Script Handler

Set up a virtual-host-level script handler with the suffix php, pointing to the newly created virtual-host-level “lsphp-example.”

Run Virtual Host PHP as SuEXEC

To ensure “lsphp-example” runs as user:usergroup, specify “Run As User” and “Run As Group.”

Override Global php.ini With Local php.ini

Let’s say you have Memory Limit set to 128M in your global php.ini. The following phpinfo page illustrates this:

If you have one virtual host (call it example.com) that needs the limit set to 512M you can set a vhost-level php.ini for that virtual host. Here’s how:

Step 1

Edit the example.com External App in WebAdmin Console, and add the following code to Environment:

PHP_INI_SCAN_DIR=/home/example.com/public_html

(Please remember to change the path to match your vhost’s actual web root.)

Restart OpenLiteSpeed.

Step 2

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

Change the Memory Limit to 512M in the new php.ini.

[root@test public_html]# cat php.ini | grep memory_limit
memory_limit = 512M

Step 3

Reload the phpinfo page for the example.com virtual host, and you should see the changed memory limit. If you don’t see it, restart OpenLiteSpeed again to force lsphp to restart.

As you can see, the memory limit has been raised to 512M:

.user.ini

.user.ini can be used on a single directory when it’s necessary to change a particular setting to be different than the vhost-level or global-level setting. We’ll use Memory Limit again in this example.

Edit the example.com External App in WebAdmin Console, and add the following code to Environment:

LSPHP_ENABLE_USER_INI=on

Like so:

Save it and restart OpenLiteSpeed.

Create a separate subdirectory and a new .user.ini:

[root@test test]# cat .user.ini
memory_limit = 768M

Set Memory Limit to 768M to distinguish it from the previous vhost PHP setting.