How can I make a phpinfo file?
Occasionally, while troubleshooting issues with a site, it can be useful to see all in one place all the current configuration for php affecting a particular folder or file. This can be done with the php function phpinfo. Among other things, this function can tell you the currently loaded php modules, the currently loaded php settings, and predefined and environment variables.
Getting or Creating the File
In its most basic form, a phpinfo file needs only one command:
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
Here, we add a comment and a couple of blank lines to help make it easier to read. You will need to copy and paste this text into a plain text file.
If creating the file yourself, make sure the whole file contains only the exact text in the code box above. Make sure there are no extra invisible characters. Sometimes text editors such as Notepad might include extra characters in files. If you are using a Windows machine to create the file, you may want to use a different text editor such as Notepad++. It is also very important that the filename end in .php
and not .php.txt
. Depending on your operating system, you may need to check if your file manager is configured to show file extensions, in order to check this.
Uploading the File
Once the file has been created, it can be uploaded to somewhere within the documentroot of the site. For cPanel servers, the cPanel File Manager is probably one of the easiest ways to do this. If you are more comfortable with FTP or Web Disk for example, those should also work. Make sure the file has the user and group ownership both set to the cPanel user, and that the file permissions are 644. How to check and adjust this will vary depending on the method used to upload the file.
Accessing the File
Once the file has been uploaded with the correct permissions and ownership, you can view your new phpinfo page with your web browser. For example, if the file was placed at /home/cpuser/public_html/phpinfo.php
within the server, then its url might be http://domain.tld/phpinfo.php
. If it was uploaded correctly, it should look like several tables, with setting/variable names in the left column, and values in the right one or two columns. If there is a specific setting you are looking for, you can use your web browser’s search function to help you find it.
Removing the File
It is very important not to leave the phpinfo file active any longer than necessary. The information it provides can be very useful to you during troubleshooting, but it can also be very useful to potential attackers who may be trying to get information from your server about what versions or modules might be installed, which could give them clues for what types of attacks to try. Using a phpinfo file for a short period of time to get php environment information during the troubleshooting process is usually safe, but it is important to remove it (or block access to it) as soon as you are finished using it. There are a variety of ways to accomplish this.
Advanced Usage
Advanced users may wish to instruct the phpinfo function to only print some of the information. The function has a parameter for this which you can read more details about in the php documentation. For most users, the default should work fine.
Another thing advanced users may occasionally have cause to try, is using the phpinfo function within existing scripts. Because php scripts can sometimes change some of the php functions, it might be useful while debugging specific scripts to add phpinfo lines inside those specific scripts, to check if the environment still has the same settings and variable values as expected, at the specific places within the script where the debugging is needed. If doing this, make sure to remove these extra debugging function calls when you are finished with them.