Placement of custom php.ini within Moodle

Re: Placement of custom php.ini within Moodle

by Dakota Duff -
Number of replies: 0

In some cases you can place a php.ini file in your main /moodle directory and it will cascade down to other directories (I believe). My host (Hostgator) allows you to make over-rides with a php.ini file, but it must reside in the same directory as the script being ran.

I modified a script to scan each Moodle directory and creates a symbolic link to a single php.ini file. I manually run whenever I upgrade/add a directory. I put mine in /moodle/local, so you may need to change paths if you're running it from somewhere else.

<?php

require_once(dirname(__FILE__) . '/../config.php');

function getDirectory($path = '.') {
 $ignore = array('cgi-bin','.','..','chat');
 $dh = @opendir($path);
 while(false !== ($file = readdir( $dh ))) {
 if(!in_array($file,$ignore)) {
 if(is_dir("$path/$file")) {
 getDirectory("$path/$file");
 }
 }
 }
 if (glob("$path/*.php")||glob("$path/*.css")||glob("$path/*.js")) {
 exec('ln -s /path/to/php.ini '.$path.'/php.ini');
 }
 closedir($dh);
}

getDirectory($CFG->dirroot);

echo "Done!";

?>

Make sure to set /path/to/php.ini to your desired "source" file. You may also want to change the glob line — ours is set up to create a symlink in directories that contain CSS and JS files as well, since we run them through PHP for compression reasons. And last, but not least, you can "ignore" certain directory names with the $ignore array. We had some trouble with Moodle's chat when using GZIP, so we just turned off the ini linking for that entire directory.