How to create phpinfo.php page

PHP developers and web server admins can use the phpinfo function to quickly see information about their installation of PHP. This can assist in debugging, seeing what version of PHP is installed, or seeing various configuration options.

On Linux systems, it’s common to make a phpinfo.php page after installing a LAMP server or LEMP server to make sure that PHP is working and to verify settings.

In this tutorial, we’ll guide you through the creation of a phpinfo.php page on your own system, as well as how to access this file afterwards.

In this tutorial you will learn:

  • How to create phpinfo.php page

phpinfo page on a Linux system

phpinfo page on a Linux system

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software PHP
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Create phpinfo page

The phpinfo function outputs a lot of information about your server and its configuration. You definitely don’t want a potential attacker to gain this information, so be sure to obfuscate your file name and delete this file after it’s fulfilled its purpose.

You can use nano, vim, or any command line or GUI text editor to create a new file. For easy identification, we’ll call it phpinfo.php, but you can name it anything you want.

$ nano phpinfo.php

In this file, the only thing we need to do is call upon the phpinfo function, which can be done with the following line of code.

<?php phpinfo(); ?>

You can exit and save this file. Now, it will need to be placed where your web files are stored. This can vary depending on which Linux distribution you’re using and which web hosting software (i.e. Apache, NGINX, etc) is installed, as well as how you’ve configured the system. But, generally, the files are stored inside /var/www or one of its subdirectories.

Once the php file has been placed there, you can access it in a web browser as seen below. Use or your server’s fully qualified domain name to access the page.

phpinfo page on a Linux system

phpinfo page on a Linux system

This page outputs a lot of information. If you’re only looking for certain details, there are some options you could pass to this function to produce a more concise output. Check the list below.

INFO_GENERAL gives some of the most basic information, such as configuration line, the location of php.ini and other .ini files, build date, web server and system type, plus some other things.

<?php phpinfo(INFO_GENERAL); ?>

INFO_CONFIGURATION shows the values for all PHP directives.

<?php phpinfo(INFO_CONFIGURATION); ?>

INFO_MODULES shows loaded modules and their configured settings.

<?php phpinfo(INFO_MODULES); ?>

You can also use INFO_ENVIRONMENT to show environment variables or INFO_VARIABLES to show all variables, including environment.

<?php phpinfo(INFO_ENVIRONMENT); ?>
<?php phpinfo(INFO_VARIABLES); ?>

That’s all there is to it. The phpinfo function contains all relevant information about your server and its config. If you have direct access to your server via command line, you could also obtain the same information by using PHP’s interactive shell.

$ php -a
Interactive shell

php > phpinfo();

phpinfo command inside PHP interactive shell

phpinfo command inside PHP interactive shell

Closing Thoughts

In this guide, we saw how to create a phpinfo.php page on a Linux system. We also learned about security recommendations and an alternative method for obtaining the same information.

PHP provides us with a very easy way to quickly ascertain all the information we could need. While convenient, this information is helpful to potential hackers, so be careful to secure this file and delete it when it’s no longer needed.

Comments and Discussions
Linux Forum