set up PHP SuEXEC for virtual host and Change PHP Settings by through virtual host external app

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. How to setup virtual host to run PHP as SuEXEC instead of “nobody:nobody”?

To do this, you will need to set three settings in each virtual host.

How to setup OLS virtual hosts to run PHP as SuEXEC?

Virtual Host configuration -> Basic, there are three settings. Once they are set, the virtual host will run PHP as SuEXEC based on server level lsphp external app settings.

External App Set UID Mode ->DocRoot UID
suEXEC User -> $VH_USER
suEXEC Group -> $VH_USER

When to create 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 instead of using server-level external lsphp apps, but this might not be needed at most of the cases. If you have such need for some reason, this virtual host level external 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.”

Setup Virtual Host PHP external app to run 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 through Virtual Host external app

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 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 External App in WebAdmin Console, and add the following code to Environment:


(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/

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 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:

setup virtual host external app to use .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 External App in WebAdmin Console, and add the following code to Environment:


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.

Next Configure PHP by Directory or File
Table of Contents