PHP Troubleshooting (How to find important information)


(Craig) #1

It’s quite common to run into a PHP issue when setting up a server. Luckily, debugging the issue is usually pretty simple. But before you can start to fix the issue, you’ll need to be able to carry out some checks.

The following checks will provide extremely useful information when debugging a PHP issue or when seeking assistance.

1. Check your PHP version
Sometimes, you can run into an issue where your Web Application thinks you’re running a different version of PHP than what you have installed. This is more common on servers that come with Plesk or cPanel - As they’re usually setup to allow multiple instances of PHP. On an unrelated note, it’s also possible to run into this issue if you attempt to install PHP when another version is already installed.

To check if this is the issue, you should first run php -v from the Command Line in order to check what version your Operating System says you have installed.

If it is different to what you think should be installed, make a note of this as it could be significant.

2. Listing critical PHP information
This next step will provide you with a plethora of information that will assist you in narrowing down the issue. The information given, will be from the perspective of anything running in the web directory where the file (below) will be created. You can find information such as:

  • Which php.ini file is in use
  • Which php version is in use
  • Which php extensions are installed
  • and lots more…

To start, you will need to create a file. You can call this whatever you like, but for the sake of this example lets called it phpinfo.php. You could either create this file directly from the Command Line or on your PC. Whichever method you choose, just make sure you save/upload it in the web directory once you’re done. So, assuming that your web directory is /var/www/html/ then the file would be put in there. The end result would be /var/www/html/phpinfo.php.

Once you’ve created the file, you’ll want to copy and paste this snippet of code into the file:

<?php phpinfo(); ?>

The code simply tells the file that you just created to display all the PHP information being read from that web directory, once opened in a web browser. Just put in your IP address of your web server or your domain, followed by /phpinfo.php. For example:

  • example.com/phpinfo.php
  • 123.123.123.123/phpinfo.php

Recap

  1. Create phpinfo.php file
  2. Add snippet of code to the file
  3. Save/Upload file to your web directory
  4. Open the file from your browser to get the PHP information

The file you load should look something like this:

Keep this file to hand, in case you get asked questions about it. You should also check if the version listed on the page matches what your OS says (php -v) and make a note.

When running a Production Server, don’t leave this file sitting in the Web Directory. Instead, you should delete the file once you’re finished with it. Leaving it accessible is deemed a security risk as anyone can see the intricacies of your web server and might be able to exploit it.


(Craig) #2