This is an old revision of the document!


Allowing Per-User php.ini

This document lists the options for allowing use of a per-user php.ini. The document assumes that you are running LiteSpeed Web Server (LSWS) off of Apache. (This applies to users using control panels.) Some of the methods mentioned here can also be used if you are running off LSWS-native configs.

Per-user php.ini files are not compatible with suEXEC Daemon mode. Our two other PHP suEXEC setups both support per-user php.ini.

Some of the following methods can be used together.

Defining PHPRC 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.

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.

Defining PHPRC in Apache 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 /path/to/php.ini.

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 only supported in LSWS 4.2.13 and up.

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 PHPRC, 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, PHPRC is recommended.
  • PHP_INI_SCAN_DIR is available for PHP 5.2.7 and up.

This can be done if only one vhost (user) needs its own php.ini (not for every vhost or multiple vhosts under one main account), “PHPIniDir” can be used.

  - Add entry "PHPIniDir /path/to/custom_ini/directory" to httpd.conf vhost section or a conf file included by vhost httpd.conf
  - Create custome ini file '/path/to/custom_ini/directory/php.ini' 
  - Restart LSWS 'service lsws restart' (i.e. on CentOS) to make the change effective.

Note:

  • PHPIniDir directive at vhost level is supported since LSWS 4.0.2
  • PHPIniDir directive is effective ONLY IF placed in the 1st (or main domain) vhost OF THE ACCOUNT (USER). The one placed in subdomain vhost will be ignored even though it is just for that vhost.
  • PHP suEXEC MUST BE ENABLED. Otherwise, only the PHPIniDir defined in server's global vhost (catch-all vhost) is effective.
  • Changes in the php.ini will not be picked up until new PHP process starts. This is because php.ini is read the first time when a php process starts.

Tips

  • Make sure the php.ini file is readable by the suEXEC user.
  • Option 3 could be used along with option 1, 2, or 4 without conflicts. However, it should rarely be needed in the per user setup.
  • Option 4 takes precedence over options 1 and2 should they be used at the same time.
  • PHP suEXEC MUST BE ENABLED in LSWS.
  • Admin
  • Last modified: 2014/07/29 19:32
  • by Michael Armstrong