Checking Whether PHP is in Module Mode or CGI

It can be handy to know whether your web server is running PHP as an Apache Module or CGI. Sometimes that simple factor can be the root of major headaches when trying to get to the root of a problem with a script. When file permissions become a problem, or keys in the $_SERVER superglobal are returning unexpected result, this is a good place to start debugging.

Finding out whether PHP is being run as a module or CGI is not terribly difficult. Here is one way to find out.

First, create a new PHP file with the following lines of code:

<?php
phpinfo();
?>

Save it to your webserver, and run the script. Look for the line near the top that says “Server API.” If it has “CGI” for the server API then you are in CGI mode, and if it has something similar to “Apache Handler” then you are in module mode. That’s it!

Leave a Reply