Website Administrator

    delivering administrator solutions for your website...


Mod Date: 04 Feb 2012
initial date: 16 Sep 2010
© 2010 Steve Campisi

Website Administrator Know How Articles

Solved. Does my website use PHP Apache 2.2.x Module or Apache CGI?

Some Web Hosting Sites come with PHP already installed and setup for use. This is not always evident when looking at the Website's directory structure on the server. You might want a quick answer as to what is the actual configuration of the PHP setup, or want to find out if PHP is setup up at all.

Questions like: Which version or sort of PHP is my Host Website Server running? Is it Apache CGI (installed as a CGI Binary so that Apache uses Php as a Cgi Interpreter) or is it Apache 2.2.x Module (installed as an integral part of Apache structure)? can be expected by the Website Administrator from his more tech savvy clients (if they look to install PHP5.3 on a local computer and want to match their server with the same type of setup).

Knowing the answer to this question can be particularly useful before uploading your scripts to a web server. Code can differ between the two PHP types (CGI & Module). Like coding password entry for example. So it is a good idea the Website Administrator knows a couple of tricks to distinguish between them.

Let's first cut to the chase with this list. It is explained further at the bottom of the page, but for those of you who already know what you are looking for, this will resolve the question:

Quick Thread Safety (and) Server API Inspection Chart
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Thread Safety = Disabled    
  PHP is a NonThreadSafe install (and therefore installed as Other-CGI)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Thread Safety = Enabled (+) Server API = CGI/FastCGI
  ThreadSafe installer used with PHP installed as Apache-CGI)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Thread Safety = Enabled (+) Server API = Apache 2.0 Handler
  ThreadSafe installer used with PHP installed as a Apache 2.2.x Module.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Otherwise, lets explore a couple of methods to get at this data....

If you're using a Windows environment for your test server, you can have httpd.exe spit out your loaded modules. You might want to know if the rewrite_module is installed for SearchEngineFriendly urls in joomla or some such, then you simply run a dos session (run / cmd) and then change to your apache bin directory: "cd C:\Program Files\Apache Software Foundation\Apache2.2\bin" will get you there in a standard 2.2 installation. Then simply type "httpd -t -D DUMP_MODULES" or "httpd -M" if you want to type less (note: If your list goes off the page, add "|more" at the end of this command to slow things down). You will be presented with a list of your loaded modules. Type "exit" to close the window. This list should match your httpd.conf file.

Another simple two step process can perhaps solve this common question (if PHP is indeed installed on that Website).

Perhaps you are unable to get at the system command prompt to type -t -D DUMP_MODULES or their is no access to the apache conf directory to check the config directly. You can then point novice user to this Web page and have them follow these steps to help them resolve their question. This simple code can be easily copied and pasted by anyone that understands how to upload a file (with ftp or another file transfer method) and type a Website Address into their Website browser. That should answer the question for many.

First, to check that php is actually enabled on the host website, we use a common php information code which will gives us lots of data on our PHP setup. We also wrap the script in some HTML5 just for fun.


The PHP Code to display php information on your server.

A truncated example of how the phpinfo configuration data is presented to you
PhpInfo example

Ok, to view your own config data, the first step is to copy/paste/save/upload/run this from your website:

<!DOCTYPE html>
<title>Code to display in depth PHP information</title>




Make sure you save this script file and call your file with a .php extension.

For example; Save the file as phpinfo.php and after uploading, call it in your website browser by typing www.MySite.com/phpinfo.php (replace MySite.com with the website location you loaded the file to). If it displays a bunch of information in the tell tale black on PHP purple and gray background, why then, PHP is setup and running on your server and it is safe to progress to the next step to test if it is running as an Apache 2.2.x Module or check the data against the chart above. Hint: if using firefox, the ?/ key is the shortcut key for page search.

Also, if this page of information came up for you, you can check to see if the configuration here uses the threadsafe (enabled) or non-threadsafe (disabled) installer.


How to test your Website for the PHP Apache 2.2.x Module. (Two methods)

Secondly, we can use this next script to copy/paste/save/upload/run to show us if PHP is one of the Apache modules our host server is using. This will be evident in the name of one of the modules.

Your PHP install is a Threadsafe / Apache 2.2.x  Module if 
a list of installed items appear down the screen. The last 
item in the Array shows we are using the mod_php5 module.

    [0] => core
    [1] => mod_win32
... (etc.)
    [6] => mod_alias
... (etc.)
    [16] => mod_cgi
... (etc.)
    [25] => mod_php5

Here is your copy / paste code...

<!DOCTYPE html>
<title>How to Show Installed Apache Modules on My Sever Using PHP Code</title>

This HTML code assumes PHP is tested and working correctly on your site.

Save this file as show_apache_mods.php (NOT .html). Up load this file to
your website and call it. (eg. www.MySite.com/show_apache_mods.php)

The numbered array below shows which Apache Modules are installed on the
server. PHP5 users will find mod_php5 in the list which tells you PHP is
installed as a Version 5 module in your Apache configuration etc.

Else, if you return a page error or get squat below this statement, you
are most likely using PHP setup as Apache-CGI.


Again, we make ensure that we save, upload and call this same file using our .php extension. eg. Save the file as show_apache_mods.php and call it in your website browser by typing www.MySite.com/show_apache_mods.php (replace MySite.com with the website location you loaded the file to)

The function apache_get_modules() will only work if you have PHP installed as a module. If this script worked, and you wished to setup a test server on your home system with Apache and PHP, you would install PHP as a module. Else, choose Apache CGI in the server type configuration section. Refer to our Installing Php 5.3.3 Guide for more data on setting up Php with Apache on Ms Windows.

Another method is check the output our first PHPinfo script displays to see if Server API: is equal to Apache 2.0 Handler or CGI/FastCGI. Apache 2.0 Handler is only used in a Threadsafe / Apache 2.2.x Module install. You can also find a section near the top named apache2handler which will also show you what modules are installed in your setup. Other sections that show up only in a Threadsafe / Apache 2.2.x Module install are: Apache Environment HTTP and Headers Information. It's just not quite as much fun to do it this way. View Chart.


| downloads | home | articles index |