OpenLiteSpeed (OLS) is a high-performance web server that supports PHP and other scripting languages, and RunCloud provides OLS as one of the web server options for your web apps.

However, if you try to define a custom configuration, you may encounter some issues with the OLS php settings, such as:

  • The custom phpIniOverride block on the OLS conf file will replace all the RunCloud PHP config. This means that you lose some of the default settings that RunCloud provides for you.
  • The disable_function directive in the phpIniOverride block will not work properly with lsphp. Even though the phpinfo page shows that the function is disabled, it can still be executed by lsphp.

These issues will affect both the performance and security of your web apps. To solve this problem, you can create a custom php.ini file for each web app with its own phpIniOverride block. By doing this, you can override the php settings without affecting either the global php.ini file or the RunCloud php config. You will also need to make some changes to both the OLS conf files and the extprocessor env settings to make this work.

In this post, we will show you how to use the custom php.ini file for each web app on OLS.

Before you start, you’ll need to have the following:

  • A RunCloud account with an OLS server and at least one web app.
  • SSH access to your server.
  • Basic understanding of how to use a text editor such as nano.

Adding phpIniOverride in RunCloud

To use the custom php.ini file for each web app on OLS, follow these steps:

  1. Log in to your server via SSH as the owner of the web application and navigate to ~/lsphp/<app-name>. In this folder, you will find a custom php.ini file that RunCloud uses for this web app. This file will contain the php settings that you want to override for that web app. Here you can also create a new file with your desired settings. 

For example, you can change the memory limit, disable some functions, or enable some extensions. Although you can change some of these settings directly from the RunCloud dashboard, having complete access to the entire configuration file provides more flexibility. 

In the above example, the location of the configuration file is /home/runcloud/lsphp/app-wyman/php.ini.

  1. Next we need to add a new general setting on the web app config. Go to the RunCloud dashboard and navigate to the OpenLiteSpeed config page of your web application.
  1. We will edit this configuration file to alter the extprocessor block and add a new environment variable named PHP_INI_SCAN_DIR that will contain the location of your custom configuration file.
    PHP will load all files in the provided directory as configuration files. This setting will tell OLS to scan the custom php.ini file for the web app and apply the settings. The value of this setting will be <web app ini folder>:<mods-available folder for the php version>.

Note: On RunCloud OLS, the mods-available directory is located at /usr/local/lsws/<phpversion>/etc/php/<phpnumber>/mods-available, where PHP version and PHP number is the PHP version that you are using. For example, for PHP 8.1, it would look something like /usr/local/lsws/lsphp81/etc/php/8.1/mods-available.

  1. Finally, we need to restart lsphp for the web app to update the php settings. This is a necessary step to make the changes take effect. However, this may cause some issues with the web app performance or availability. We need to be careful and plan ahead when we do this. You can kill lsphp by using the killall command:
killall lsphp

Troubleshooting

If you encounter any problems with using the custom php.ini file for each web app on OLS, here are some tips to troubleshoot them:

  • Check the phpinfo page for the web app to see if the php settings are applied correctly. You can access the phpinfo page by creating a file named phpinfo.php in the web app root directory with the following content:
<?php phpinfo(); ?>

Then, visit the URL of the file in your browser, such as https://<webappname>/phpinfo.php.

  • Check the OLS error log for any errors or warnings related to the PHP settings.