Placement of custom php.ini within Moodle

Placement of custom php.ini within Moodle

by Jesus Padro -
Number of replies: 1
Last night I revamped my site to the latest 1.9.4+. While performing the install process I was prompted to switch one of the php.ini values to off for security reasons. I contacted my hosting company and asked that they make a modification ot the php.ini. They informed me that my best course of action would be to create a custom php.ini to override the one that they have. They said to place it within each and every page that needs these custom modifications.

My question to all of you is there a certain folder within the structure in which I can place this php.ini folder so as to provide it to the entire site without having to place it within every folder of the site.

Also on another note I noticed that I could add course categories but I can not remove/delete an empty category. I am wondering if perhaps it has to do with my hosting company php.ini. If so then where would I place my php.ini so as to correct this problem as well.

Thank you all for your prompt response to this issue.

Jesus
Average of ratings: -
In reply to Jesus Padro

Re: Placement of custom php.ini within Moodle

by Dakota Duff -

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.