6.15 How to get information about PHP using phpinfo script

PHPBanner EN

The phpinfo script is a simple and convenient tool for obtaining complete information about the current PHP installation on the server. Below we will consider the step-by-step process of its creation and use.

Main uses of phpinfo
  • Checking the PHP version for application compatibility.
  • Diagnostics of modules and extensions - find out if the necessary libraries are installed.
  • Configuration analysis - identify which settings may require changes.
  • Debugging the environment - help with configuration and troubleshooting.

Creating a phpinfo.php file

To execute the script, we will need to create a file in the .php format. Its name can be arbitrary, but to avoid unnecessary confusion, we will call it phpinfo.php.

1. Connect to your server via FTP or file manager of the hosting control panel.

2. Go to the directory where your site is located (usually it is /www/yoursite.com/ or similar).

3. Create a new file named phpinfo.php.

4. Add the following code to the file and save the changes:

<?php
phpinfo();
?>

The file is created. Now you need to open it in your browser.

Opening the file and interpreting the information

In the address bar, enter the file URL, for example, https://example.com/phpinfo.php, where example.com is your domain.

You will see a page with detailed information about PHP:

Phpinfo.php
Appearance of the open page phpinfo.php

The phpinfo page contains many sections. The key ones are:

  • PHP Version. Shows the current actual version of PHP. Useful for checking script compatibility with the server:

Phpinfo.php, PHP version

  • Configure Command. List of PHP extensions, such as mysqli, curl, mbstring. Helps to make sure that the necessary modules are active:

Configure Command

  • Core. Contains configuration parameters, such as memory_limit, upload_max_filesize, max_execution_time. Also provides a lot of information about PHP variables in the current environment, for example the line disable_functions lists functions that are prohibited for execution. Useful for customizing server settings for your project:
Phpinfo.php, Core
Beginning of Core section

Additional: as you can see, the information in this section is divided into Local Value and Master Value columns. Master in this context is a global setting predefined on the server and is used to execute all scripts until the execution settings are overridden locally using methods such as ini_set() or .htaccess directives (depending on the web server).

Tip: the issue of PHP limitations such as memory_limit and others is discussed in detail in a separate article.

  • Environment. Information about the server environment, including PATH variables. Can be useful for diagnosing some problems.

  • PHP Variables. Displays headers sent by the server:

Important: After using the phpinfo.php file, it is advisable to remove it from the server. Leaving such a file publicly accessible is dangerous, as attackers can use information about your server against you.

Alternative methods

You may find yourself in a situation where you cannot create and execute the phpinfo script on your server - due to some restrictions or lack of rights.

For such cases, there are many alternative ways to obtain the necessary information about the state of PHP on the server.

Additionally: when using multiple different versions of PHP on one server, the commands below should be modified to specify the path to the PHP version you want to obtain data about. In practice, this means using the command /usr/bin/php7.4 -i instead of php -i or /usr/bin/php7.4 -m instead of php -m.

php -i

A direct alternative to creating a file with a script and executing it in the browser is the php -i command.

Executing it will display all the same information directly in the terminal:

Output of php -i

Since its output is very voluminous, it makes sense to immediately use it in combination with grep to search for the desired value. For example:

php -i | grep memory_limit

Which will return us information about the specified PHP limit:

Output
memory_limit => 1024M => 1024M

php -m

If the task is to check the presence or absence of a particular module, there is a much faster way to check than the phpinfo script.

Namely, the php -m command. Using it will return you a list of all active PHP modules. This is important, since the module may be installed on the server, but not activated in the current PHP load.

Output of php -m
[PHP Modules] bz2 calendar Core ctype curl date dom exif FFI fileinfo filter ftp gd gettext hash iconv igbinary imagick imap ionCube Loader json libxml mbstring msgpack mysqli mysqlnd openssl pcntl pcre PDO pdo_dblib pdo_mysql PDO_ODBC pdo_pgsql pdo_sqlite pgsql Phar posix readline Reflection session shmop SimpleXML sockets sodium SPL standard sysvmsg sysvsem sysvshm tidy tokenizer xml xmlreader xmlrpc xmlwriter xsl Zend OPcache zip zlib [Zend Modules] Zend OPcache the ionCube PHP Loader + ionCube24

It can also be combined with grep:

php -m | grep pdo
Output
pdo_dblib pdo_mysql pdo_pgsql pdo_sqlite

If the required module is installed but does not load, make sure that the module is enabled in php.ini or in the PHP settings in the panel.