Jump to content

How to standardize php configuration files?


Recommended Posts

I have inherited ( 8 ) servers on an intranet using various versions of php as main programming language. Most of these are not web servers.


I've been tasked to consolidate and standardize on one (1) php.ini configuration file to be used on all ( 8 ) servers


Some of these use odd locations for php.ini


For example, a Solaris 10 host uses this configuration file:



# /usr/bin/php --info | grep -i php\.ini
Configuration File (php.ini) Path => /usr/local/php-5.2.17/lib
Loaded Configuration File => /usr/local/php-5.2.17/lib/php.ini

# php-config | grep -i ini

# php-config | grep -i with-config-file-path

[ NO compile time options returned ... ]


NONE of the user accounts running php have PHPRC set.


Current working directory is whatever directory the user is in at execution time


One thing that I need to do is get ALL of these servers using /etc/php.ini - even if that is a symbolic link


How can I accomplish this standardization of /etc/php.ini?


Please, advise. Thank you.

Edited by helices
Link to comment
Share on other sites

1. One php.ini means one PHP version too. At the very least the same major+minor (eg, 5.2.x). So there's that.

2. Then figure out what the various installations need. Find a common denominator.

3. Test.


And yes, you can symlink /etc/php.ini to wherever the actual file is.

Link to comment
Share on other sites

Thank you; but, that's not my problem here.


The example installation is looking here: /usr/local/php-5.2.17/lib/php.ini


HOW can I get that instance to always look here: /etc/php.ini ???


NO, I cannot do: php -c path|file  -NOR- php --php-ini path|file


Yes, I can make a symbolic link; but, I'm looking to understand HOW this example installation knows to look here: /usr/local/php-5.2.17/lib/php.ini


When I understand why it's looking there, then I will know what to do in other cases.


The manual appears to be incorrect when it states:


php.ini is searched for in these locations (in order):

  • SAPI module specific location (PHPIniDir directive in Apache 2, -c command line option in CGI and CLI, php_ini parameter in NSAPI, PHP_INI_PATH environment variable in THTTPD)
  • The PHPRC environment variable. Before PHP 5.2.0, this was checked after the registry key mentioned below.
  • As of PHP 5.2.0, the location of the php.ini file can be set for different versions of PHP. The following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z], [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x], where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in any of these keys, the first one found will be used as the location of the php.ini (Windows only).
  • [HKEY_LOCAL_MACHINE\SOFTWARE\PHP], value of IniFilePath (Windows only).
  • Current working directory (except CLI).
  • The web server's directory (for SAPI modules), or directory of PHP (otherwise in Windows).
  • Windows directory (C:\windows or C:\winnt) (for Windows), or --with-config-file-path compile time option.
Link to comment
Share on other sites

If you compile your own PHP, the I'd imagine you could just used the configure option to set the path. If you want to use the version from the system's package management tools, then probably you'd just have to symlink the location it stores the ini file in to /etc/php.ini


I would store the actual php.ini file in /etc/php.ini in all cases, and then if necessary, symlink the necessary location to that. Eg /usr/local/php-5.2.17/lib/php.ini would be the symlink which points to /etc/php.ini


From a CLI perspective, another potential option would be to replace the php binary with a shell script which sets the PHPRC env var then runs php, eg:


export PHPRC

# assuming you rename the php binary to __php
exec /usr/bin/__php "$@"
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.