How to change php configuration on shared servers ?
by Gabi SolomonSometimes your application might require one or more specific php configurations changed from its current value in order to work properly. The most common of this is the requires global_registers flag off ( i have no idea why some servers keep it on ).
If you are talking about a local sever running on your computer or a server to witch you have root rights, the solution is quite simple : you just modify the PHP configuration file (php.ini) to your needs, restart the server … and voila job done.
But what if you are on a shared server. You cant just go and ask the servers support team to modify the configuration for you ( they couldnt even if they wanted to, because that will affect all the websites on there server and then there would be some angry folks on the chat really fast
). Luckily the nice folks that designed the software running the server ( apache most of the time ) have thought of you and this situation and added a 2 possibilities for you to change the php configuration only localy without affecting the other websites hosted on the server.
1. Creating a local PHP.ini file
You just create a php.ini file in your domain root and add your configuration as if it was the php.ini from the actual server settings. This will overwrite the settings just for your domain. Getting back to our example where you want to disable register_globals flag off you would add a line to the file like :
“register_globals = off”
2. Using a .htaccess file
The second way would be to use a .htaccess file ( some of you used to do URL rewrite with it ). Now for this you have to know a certain syntax :
# to modify a flag attribute
php_flag [name] [value]# to modify a value attribute
php_value [name] [value]
Again returning to our example : php_flag register_globals off
To check if your configuration has been changed you can use the phpinfo() function. Your new setting will appear on the local column.
You should know that that not all servers support this methods of modifying the php configuration, some will only support one of them, so you might want to check this would your server support if it doesnt seem to work.
On another note not all php configuration can be changed locally. A full list of php configuration variables can be found on php official website at :
http://www.php.net/manual/en/ini.php#ini.list
The options that can be overwriten localy have the PHP_INI_PERDIR or PHP_INI_ALL Changeable column. The ones with PHP_INI_SYSTEM can only be changed by the php.ini from the php instalation directory.

