How to Add Phpinfo File On Your Site?
Hosting a website on PHP based platforms needs many basic things to be understood in order to quickly troubleshoot and resolve the problems. Most of the activities on the admin dashboard and site will trigger a PHP script to output expected result. For example, when you upload a demo theme or extracting an addon file, there should be sufficient memory limit and script execution time set on the server to complete the activity. Otherwise you will be seeing different types of errors like memory exhausted, page not found, etc. In all such error scenarios the first thing you need is to know the current PHP configurations of the server. In this article we will explain how to view the PHP configurations of the server using phpinfo file.
What is Phpinfo File?
Generally the configuration can be viewed by using the php.ini file located on the server. There can be a individual php.ini file for individual folder to control the parameters of only that folder. But most of the hosting companies will not allow users to view or modify the file to protect server information. In such scenarios you can view the current PHP settings of the folder by uploading a phpinfo.php file on the folder.
This will help you to troubleshoot easily like increasing memory limit or execution time.
How to Create phpinfo.php File?
It is very easy to create phpinfo.php file. Just open a Notepad in Windows or TextEdit in Mac and paste the following code:
<?php // Show all PHP settings phpinfo(); ?>
Save the file in a plain text format with the name as “phpinfo.php”. Ensure to save the file in UTF-8 encoding format especially when you are using Mac.
Uploading phpinfo.php File to Server
The next step is to upload the phpinfo.php file to your server. You need to have a FTP account in order to upload the files to your server. Learn more on FTP and FileZilla FTP client. Open youyou FTP client and upload the file to the required folder.
If you are looking for the detail of a subdomain or directory then upload the file under that folder on the server.
Viewing PHP Configurations
Now open the URL “yourdomain.com/phpinfo.php” on a browser and you will be showing all PHP related information of the folder. Below is how the display will look like on a localhost site viewed with the URL “localhost/phpinfo.php”.
There will be huge set of information on the page, you may need to search with parameter to find the correct line and the value for that parameter. For example, you can search “memory” to find the “memory_limit” which is available under “Core” section. The first column is the parameter, second column is the local value applicable for that folder and the last column is the master value for that folder set in php.ini file.
If you want to edit any of the parameter then you need to login to your hosting account and modify the php.ini file on that folder. Some hosts allows you to create your own php.ini file similar to phpinfo.php file and upload it on the server. Hosts like SiteGround allows you to set the parameters for individual folder using “PHP Variable Manager” option.
Delete the File
Finally after your troubleshooting is completed, ensure to delete the phpinfo.php file from the server. Otherwise anyone can look into the PHP details of your site and try to hack using that data.