$ cat /notes/quick-php-configuration-check-with-phpinfo

Quick PHP Configuration Check with phpinfo()

Create a temporary phpinfo() page to verify the PHP version, loaded extensions, configuration, and php.ini in use.

Need to know what PHP configuration the web server is actually using?

A temporary phpinfo() page is one of the quickest ways to find out. PHP’s phpinfo() function displays extensive information about the current PHP configuration, including the PHP version, loaded extensions, configuration values, server information, environment information, paths, and the location of php.ini. PHP documents it as both a configuration-checking and debugging tool.

On a typical Debian/Apache installation with /var/www/html as the document root, create a temporary file:

sudo nano /var/www/html/info.php

Add:

<?php
phpinfo();
?>

Save the file and open it in a browser:

http://your-server/info.php

That gives you a quick answer to questions such as:

  • Which PHP version is actually running?
  • Which extensions are loaded?
  • Which php.ini is PHP using?
  • What are the current local and master configuration values?
  • What server and environment information is PHP seeing?

The important word here is temporary.

phpinfo() exposes a substantial amount of information about the PHP and server environment, including configuration, paths, environment information, HTTP headers, and predefined variables. Once you’re finished troubleshooting, remove the file:

sudo rm /var/www/html/info.php

Leaving a diagnostic page full of system information sitting on a public web server is an excellent way to turn a five-minute troubleshooting tool into a long-term documentation service for people you weren’t trying to help.

Create it. Check it. Remove it.