How to Customize PHP Flag Settings Without Using Apache and Htaccess

Create a Custom Php.ini File and Customize All PHP Settings

I recently purchased a web hosting account and tried to move my old website to the new server. At first I was a bit perturbed when I couldn't access anything - every file on the server resulted in an "Internal Server Error 500."

I narrowed the problem down to the .htaccess file - when I renamed it, everything worked fine. I assumed that there was an error with the way .htaccess was using modrewrite to change the URLs of my
 pages.

Turned out it was something far simpler. When I eventually commented out the line
"php_flag register_globals Off"
everything worked fine. Why did it do this?

PHP Can Be Run Through Apache or CGI

Often, PHP is run as an Apache module. Many web hosts, including my old web host, use this set up. A single php.ini file is created for the system, and individual users can tailor the settings with the .htaccess file.

It is possible, though, to run PHP as a CGI executable. In this case, Apache has nothing to do with PHP - so putting a "php_flag" line in the .htaccess file will yield the internal server error. If you want to change any settings in PHP, you'll have to find another way to do it.

Why Would I Want to Alter the php.ini Settings?

There are a number of settings in the php.ini file that you shouldn't have on. For some reason, web hosts leave them on by default and open your page to security holes and inefficiencies.

For security purposes, "register_globals" should be off. This helps prevent some hacking attempts, whereby a user can send his or her own variables to a user.

For consistency and performance, it helps to turn off "magic_quotes_gpc." This setting automatically escapes certain characters so that they're ready to go into a database - but not every piece of form information is intended to go into a database.

You may also want to customize the maximum file upload size, the level of output buffering, and other niceties.

Ok, Then How Do I Do It?

Simple. You create your own php.ini file.

If PHP is launched as a CGI executable, you've got two simple methods to get PHP working the way you want it.

Related information