This is an old revision of the document!


Enabling Per-User php.ini

This document lists the options for enabling a per-user php.ini when you are not running CloudLinux. For CloudLinux and CL PHP Selector has been used, you should refer to "substitute global php.ini for individual customer".

The following steps show you how to do it when you are running off LSWS-native configs or running LiteSpeed Web Server (LSWS) off of Apache configurations. If running LSWS using native configs, please take a look at the Notes section.

To Define PHPRC or PHP_INI_SCAN_DIR for a particular domain/virtual host on a control panel, such as cPanel server, you will need to create an include file and define PHPRC or PHP_INI_SCAN_DIR in it.

Most likely you will need to install extra apache module for it:

yum install ea-apache24-mod_env

or someting simliar, otherwise apache may return error like:

Apr 05 16:21:46 cptest.com restartsrv_httpd[21931]: AH00526: Syntax error on line 1 of /etc/apache2/conf.d/userdata/std/2_4/wpuser99/wpuser99.com/ini.conf:
Apr 05 16:21:46 cptest.com restartsrv_httpd[21931]: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration

For example, on an EA4 CentOS 7 server, to enable custom php.ini for yourdomain.com, create file

/etc/apache2/conf.d/userdata/std/2_4/$USER/yourdomain.com/customphpini.conf

add:

PHP_INI_SCAN_DIR=/home/$USER/public_html/

or

SetEnv PHPRC /home/$USER/public_html/

then make it virtual host inlcude file enabled:

vi /etc/apache2/conf/httpd.conf
Include "/etc/apache2/conf.d/userdata/std/2_4/$USER/yourdomain.com/*.conf"

Please be aware that you need to be very careful before you set the above up. cPanel EA4 only reads this specified php.ini when the PHPRC is set and won't read EA4 originally php.ini and modules in the scan folder. If user specified php.ini doesn't inlcude complete set of modules, it may lead to errors, for example, mysql missing.

Please refer: The cPanel PHPRC PHP Patch for EasyApache 4

“If you set the suPHP_ConfigPath directive, the specified php.ini file must be a complete .ini file.”

“To ensure that your users receive a complete php.ini file, run the following command to combine your existing files:”

cat /opt/cpanel/ea-php##/root/etc/php.ini /opt/cpanel/ea-php##/root/etc/php.d/*.ini > /path/to/specified/php.ini

Defining the PHPRC environment variable in the WebAdmin console allows you to use a variable that can set a standard location for the php.ini file in each virtual host. This method is also applicable to control panel environment such as cPanel, but it will modify the behavior of any virtual hosts using this external application, hence adding individual include file for that host apache configuration is normally recommended as described as above.

In your external application Environment setting (WebAdmin console > Server > External App > lsphp5), enter: PHPRC=variable/php.ini/directory

Example:

PHPRC=$VH_ROOT/public_html

The variables available for use are:

  1. $VH_ROOT: the virtual host's home directory
  2. $VH_NAME: the virtual host's domain
  3. $VH_USER: the virtual host's user

Note:

  • Using this method will cause LSWS to ignore any global php.ini files and only use the user-defined php.ini. However, if no user-defined php.ini found, LSWS will still use global php.ini

Using the PHP_INI_SCAN_DIR environment variable allows you to use a variable that can set a standard location for the php.ini file in each virtual host. Unlike the PHPRC environment variable, though, PHP_INI_SCAN_DIR allows the use of the global php.ini file with the addition of a per-user php.ini.

In your external application Environment setting (WebAdmin console > Server > External App > lsphp5), enter: PHP_INI_SCAN_DIR=variable/php.ini/directory

Example:

PHP_INI_SCAN_DIR=$VH_ROOT/public_html

The variables available for use are:

  1. $VH_ROOT: the virtual host's home directory
  2. $VH_NAME: the virtual host's domain
  3. $VH_USER: the virtual host's user

Note:

  • This method is not recommended if you replace Apache with suPHP. When replacing Apache with suPHP, the PHPRC environment variable is recommended.
  • The PHP_INI_SCAN_DIR environment variable is available for PHP 5.2.7 and up.

Defining the PHPRC environment variable in Apache's virtual host configurations allows you to set a php.ini location for a specific virtual host.

In the Apache virtual host configuration file, add SetEnv PHPRC /php.ini/directory.

Note:

  • Using this method will cause LSWS to ignore any global php.ini files and only use the user-defined php.ini.
  • This method is supported in LSWS 4.2.13 and up.

Using the PHPIniDir directive in Apache's virtual host configurations allows you to set a php.ini location for the main virtual host of a specific user.

In the Apache virtual host configuration file, add PHPIniDir /path/to/php.ini/directory

Note:

  • The PHPIniDir directive at the vhost level has been supported since LSWS 4.0.2.
  • The PHPIniDir directive is effective ONLY IF placed in the 1st (or main domain) vhost of the user. Placing this directive in a subdomain vhost will be cause it to be ignored.

To make .user.ini to work with lsphp, you need to change lsphpX external app configuration by adding environment variable:

LSPHP_ENABLE_USER_INI=on

This directive is supported since PHP LSAPI version V6.10.

  • PHP suEXEC MUST BE ENABLED IN LSWS.
  • Make sure the php.ini file is readable by the suEXEC user.
  • Option 3 can be used along with options 1, 2, or 4 without conflicts. However, this should rarely be needed.
  • Option 4 takes precedence over options 1 and 2 should they be used at the same time.
  • Changes in the php.ini will not be picked up until new PHP process starts. The php.ini is read for the first time when a PHP process starts.
  • Per-user php.ini files are not compatible with suEXEC Daemon mode. Our two other PHP suEXEC setups both support per-user php.ini.
  • For native LSWS installs, these variables ($VH_ROOT, $VH_NAME, $VH_USER, etc.) need to be inside of a Virtual Host External App Environment Section, and not inside the general Server External App Environment Section. This is because the variables are expanded on start up, so the VH_* variables cannot be expanded during server level configurations.
  • Some PHP extension missing after loaded with per user php.ini, for example Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

This is because once custom php.ini is loaded , the default php.ini will be ignored , therefore extensions will not be loaded.

To resolve this problem , the easier way to go is copy the content of default php.ini into custom php.ini by following command:

cat /opt/cpanel/ea-phpXX/root/etc/php.ini /opt/cpanel/ea-phpXX/root/etc/php.d/*.ini > /path/to/php.ini

Please replace ea-phpXX and /path/to/php.ini to corresponding version and path.

Verify the php.ini content and restart lsws if necessary, as change in php.ini will not take effect until new PHP process starts. The php.ini is read for the first time when a PHP process starts.

  • Admin
  • Last modified: 2018/07/02 11:17
  • by qtwrk