This article will explain what the phpinfo() function does and how to use it to get information about the PHP environment on your system.
Many PHP packages and platforms (like WordPress, Laravel, and Symfony) have system requirements beyond what is included in the base PHP installation on most systems.
These required modules include things like support for encryption, database support, and the ability to make HTTP requests from within PHP.
To ensure that your PHP environment meets these conditions before trying to run the software, you need to know a bit about it.
That’s what phpinfo() is for – it tells you all about your PHP installation – what modules are installed, where the configuration file is located (should you want to edit it), version information, and so on.
Here’s how to use the phpinfo function:
Pretty simple. Navigate to your hosted PHP script, which contains the call to phpinfo(), and you will see a formatted page containing everything you would want to know about your PHP installation.
Using phpinfo() from the Command Line
phpinfo() can also be used from the command line:
php -r 'phpinfo();'
Above, the -r option is used when calling PHP from the command line to execute the quoted code and print it to the terminal, bypassing the need for a browser. This is useful if you want to quickly check your PHP configuration without creating a file and navigating to it in a web browser.
You can limit which information is output by phpinfo() by passing one of the following values:
|INFO_GENERAL||General information – Configuration line, php.ini location, build date, configured web server, operating system, etc.|
|INFO_CONFIGURATION||Current Local and Master values for PHP directives/configuration values|
|INFO_MODULES||Loaded modules and their settings|
|INFO_ENVIRONMENT||Environment Variable information|
|INFO_LICENSE||PHP License information|
|INFO_ALL||Shows everything (the default)|
…Would print only the information on PHP modules.