Per-User php.ini¶
To enable a per-user php.ini, you can use either PHPRC
or PHP_INI_SCAN_DIR
. If using CloudLinux and CL PHP Selector, please refer to CloudLinux documentation.
To apply per-user php.ini to all cPanel virtual hosts globally, you can use PHPRC
or PHP_INI_SCAN_DIR
in LiteSpeed PHP Environment
configuration. To apply per-user php.ini to any particular apache virtual host, you can use PHPRC
or PHP_INI_SCAN_DIR
in that cPanel apache virtual host include file.
To apply per-user php.ini to all virtual hosts globally¶
To apply per-user php.ini to all virtual hosts globally, you can use either PHPRC
or PHP_INI_SCAN_DIR
at LSWS Web Admin Console > PHP > Environment as well as LSWS Web Admin Console > External App > lsphpxx -> Environment(need to apply to all lsphpxx). PHPRC
will replace your ea-phpxx php.ini with a new php.ini at specified user's location, while PHP_INI_SCAN_DIR
will load default ea-phpxx php.ini as well as aditional *.ini
.
PHPRC in the WebAdmin Console¶
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 a control panel environment such as cPanel, but it will modify the behavior of any virtual hosts using this external application. Therefore, adding an 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 > lsphp), enter: PHPRC=variable/php.ini/directory
Example:
PHPRC=$VH_ROOT/public_html
The variables available for use are:
$VH_ROOT
: the virtual host's home directory$VH_NAME
: the virtual host's domain$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
is found, LSWS will still use the global php.ini
.
Starting from LSWS v5.3.x, LSWS may automatically configure external applications and script handlers for control panels, hence it may not have external applications or script handlers anymore. If you want to define the PHPRC
environment variable for all external applications, you can use the PHP tab:
PHP_INI_SCAN_DIR in the WebAdmin Console¶
Using the PHP_INI_SCAN_DIR
environment variable allows you to set a standard location for the php.ini
file for 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
.
On cPanel, ea-phpxx will normally load the main php.ini
, then scan additional .ini
files, like in this example with ea-php73:
To avoid missing any additional folders when scanning from /opt/cpanel/ea-php73/root/etc/php.d
, you should specify multiple additional scanning folders in PHP_INI_SCAN_DIR
, separating them with :
.
In your external application Environment setting (WebAdmin Console > Server > External App > lsphp73), enter:
PHP_INI_SCAN_DIR=/opt/cpanel/ea-php73/root/etc/php.d:$VH_ROOT/public_html
or simply:
PHP_INI_SCAN_DIR=:$VH_ROOT/public_html
After you save the change and restart LSWS, the phpinfo page of the accounts using lsphp73 should change to something similar to the following by scanning additional .ini
for additional folders from $VH_ROOT/public_html
:
The variables available for use are:
$VH_ROOT
: the virtual host's home directory$VH_NAME
: the virtual host's domain$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.
Starting from LSWS v5.3.x, LSWS may automatically configure external applications and script handlers for control panels, hence it may not have external applications or script handlers anymore. If you want to define the PHPRC
environment variable for all external applications, you can use the PHP tab.
To apply per-user php.ini to a particular virtaul hosts¶
To define PHPRC
or PHP_INI_SCAN_DIR
for a particular domain/virtual host on cPanel, 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 an extra Apache module first:
$ sudo yum install ea-apache24-mod_env
or something similar, otherwise Apache may return an error like the following:
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 the file
/etc/apache2/conf.d/userdata/std/2_4/$USER/yourdomain.com/customphpini.conf
add:
PHP_INI_SCAN_DIR=/home/$USER/public_html/
SetEnv PHPRC /home/$USER/public_html/
Then make it virtual host include file enabled:
$ sudo vi /etc/apache2/conf/httpd.conf Include "/etc/apache2/conf.d/userdata/std/2_4/$USER/yourdomain.com/*.conf"
php.ini
when the PHPRC
is set. It won't read EA4 original php.ini
and modules in the scan folder. If the user-specified php.ini
doesn't include a complete set of modules, it may lead to errors, for example, MySQL missing.
Please refer to The cPanel PHPRC PHP Patch for EasyApache 4.