As you've probably heard, JPC is moving from the Apache Module of PHP to the CGI version for increased security. With this change we will lose the ability to override PHP sttings in .htaccess and will instead have to use our own copies of php.ini instead.
Here is the php.ini merging script that I said I was writing. It will allow you to keep your php.ini changes separate from those of the server-wide php.ini, which should make it easier to track and apply changes. Feel free to use it on any of your sites.
Installation:Code:#!/usr/bin/php -q <?php /********************************************************************** * phpinimerge * * By Jason Pitoniak <jason@interbrite.com> * * Copyright (c) 2006 Interbrite Communications. All rights reserved. * * * * This program allows you to merge local changes to php.ini with the * * server-wide settings. * * * * Usage: * * phpinimerge [-h] [-s serverfile] localfile outputfile * * * * -h Print help message * * -s Allows the path to the server-wide php.ini to be * * specified. If not set the default will be used. * * localfile The path to the file containing php.ini directives * * intended to override server-wide settings * * outputfile The new php.ini file that contains the original * * server-wide settings merged with those of localfile * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * **********************************************************************/ //shift off the path used to call the program from the args list array_shift($argv); if(count($argv) < 2) { //not enough arguments passed, show help showUsage(); } else { //collect the output file path and remove it from the args $output_ini = $argv[count($argv) - 1]; unset($argv[count($argv) - 1]); //collect the localfile path and remove it from the args $local_ini = $argv[count($argv) - 1]; unset($argv[count($argv) - 1]); while(count($argv) > 0) { //search for command line options and handle them $cmd = array_shift($argv); if($cmd == '-s') { //server-wide path override if(count($argv) > 0) { $server_ini = array_shift($argv); } else { echo("-s option must be followed by a path\n\n"); showUsage(); } } else if($cmd == '-h') { //show help showUsage(); } else { //bad option echo("Unsupported Option: $cmd\n\n"); showUsage(); } } } //if no server-wide file path was specified, use th default $server_ini = isset($server_ini) ? $server_ini : '/usr/local/Zend/etc/php.ini'; //parse the two ini files into arrays $server = parse_ini_file($server_ini); $local = parse_ini_file($local_ini); //check for errors if($server === false) { echo("Unable parse server php.ini file ($server_ini)\n\n"); showUsage(); } if($local === false) { echo("Unable to parse local php.ini file ($local_ini)\n\n"); showUsage(); } //if we get here we should have two arrays with the contents of the two ini files $merged = array_merge($server, $local); //write the new file $fp = fopen($output_ini, 'w'); flock($fp, 2); foreach($merged as $key => $value) { fputs($fp, "$key=$value\n"); } flock($fp, 3); fclose($fp); exit(); function showUsage() { //show useage instructions $usage =<<<EOF phpinimerge - Merge local changes to php.ini with the server's settings. Usage: phpinimerge [-h] [-s servercopy] localcopy outputfile Options: -h Print this help message -s Force the use of "servercopy" as the server's php.ini EOF; echo("$usage\n"); exit(); } ?>
1. Copy the above code to a file called phpinimerge (no php extension necessary) somewhere in your site. It should be outside of your public_html directory.
2. Chmod the file to 700 (executable by you, and only you)
Use:
NOTE: This is a command line tool, therefore it requires SSH access.
1. Create a local php ini file. For simplicity, put it in the same directory as the phpinimerge script. I recommend calling this file php.ini.local, but the name is not important. This file should be in the form of "setting=value" where setting is the PHP setting you want to override and value is the new value. Place each directive on its own line. For example:
2. Grab the server-wide php.ini file from http://chamaeleon.nocdirect .com/php.ini. The script should be able to use the php.ini file that's installed on your server, but JailShell prevents users from accessing it. I call this file php.ini.server, but again the name is unimportant.Code:register_globals=off magic_quotes_gpc=off
3. Run the script (in an SSH session).
If all goes well you should get a new JailShell prompt with no other messages and there should be a new file called php.ini.merged (or whatever you specified for the last argument to the script) in your current directory.Code:./phpinimerge -s php.ini.server php.ini.local php.ini.merged
If you open the new file you will see that it does not contain any sections (in square brackets, ie [PHP]) or comments (delimited by ";"). PHP ignores these, so they aren't necessary.
To see if your new merged file works, run the command
which will output the same information as the phpinfo() command, using your new merged php.ini. (Note that you may see some errors because the Zend libraries are not available through JailShell.) You can pipe the results through grep to quickly find your overrides:Code:php -c ./php.ini.merged -i
You will need to change the merged file to php.ini and copy it to any directories inside public_html that have PHP scripts in them for these changes to take effect.Code:php -c ./php.ini.merged -i | magic_quotes
IMPORTANT: If you make changes to your local php.ini after running phpinimerge, the new changes will NOT take effect automatically. You will need to run phpinimerge and recopy the file to your public_html folder and subfolders each time you change settings.
This is the first of a few scripts that I plan to write to ease the transition to the CGI version of PHP. The others will come as I have time to write them. Some ideas include a tool to manage php.ini symlinks in public_html subfolders and perhaps a tool to parse .htaccess files for php_value and php_flag directives to build the php.ini.local file. If anyone has any suggestions or comments, I'm all ears.
I hope everyone finds this useful.
--Jason


LinkBack URL
About LinkBacks



Reply With Quote

Bookmarks