Using custom php.ini settings without restart on hosting provider
For more information on PHP, visit spacewalk.redhat.com
Recently I came across an caching issue when updating my MediaWiki installation which resides on my hosting provider. After the upgrade I was getting error messages about bad magic words, and the solution was to rebuild the local language caches, which MediaWiki generously provides a script in their maintenance directory for you, that does exactly that. Easy, no problem, I have shell access to the server, however can not do anything outside of my public_html directory, but I only need to run a php file residing in my public_html directory so easy peasy right.. wrong.. Upon executing the script with a little
php rebuildLocalisationCache.php --force
I received the error:
Cannot get command line arguments, register_argc_argv is set to false email@example.com [~/www/mywebsite/wiki/maintenance]#
Use Custom php.ini file:
I needed to change the value of register_argc_argv in the php.ini file in order to rebuild my LocalisationCache. I do have a local copy of a modified php.ini file sitting in the root of my public_html directory, but generally speaking making a change in the php.ini file usually requires an apache restart which I don't have access to do. Also my local php.ini file, isn't the one being used by apache, so it doesn't really help even if I could restart apache. To resolve the issue, I was able to redirect php to use the php.ini file of my choice with the -c switch.
php -c ../../../php.ini rebuildLocalisationCache.php --force
then resulted in:
Rebuilding ab... Rebuilding ace... ....
Wonderful !! Issue resolved !! So long story short if your running a site on a hosting provider and have to execute a php file using parameters or variables that may not be set in their production php.ini file, you can put a copy of the php.ini file in a directory within your project and access it with the php -c switch !!