Troubleshooting PHP

While Updating PHP on Ubuntu I had a problem and jumped into trouble shooting mode. I was documenting my steps so I wouldn’t get lost or start trying random things, those steps turned into this blog post.

Troubleshooting is something that I just start doing when I have an issue with almost anything. I don’t think that was always the case for me however my time in the Navy “taught” me how to think. Many people that I have meet never developed a formal approach to troubleshooting or problem solving. My process varies depending on the issue and my knowledge of the subject however the basic steps are usually very similar.

  1. Define the problem
  2. Confirm the problem
  3. Think
  4. Formulate a plan
  5. Follow the plan
  6. Find the solution
  7. Confirm the solution

The following are the detailed steps I used to to switch my test website from PHP 7.1.33 to PHP 7.4.16

My Troubleshooting Steps:

  • Define the problem:
    • I upgraded to PHP 7.4 and the WordPress dashboard is giving me a warning that I am using PHP 7.1.33
  • Confirm the problem:
    • From the terminal the php -v command confirms that PHP 7.4.16 is installed
    • I need to confirm that WordPress is not displaying an old error so I added WP PHP Version Display plugin to display this window in my dashboard:
Screenshot from the WP PHP Version Display Plugin - showing PHP 7.1.33 is running.
  • Review of what I already tried:
    • Restarted Apache2 server
    • Closed and reloaded the browser
    • Rebooted the computer
    • Generated a list of PHP versions installed
      • karl@StanLee:~$ apt list –installed | grep “php*”
    • Read the link with the warning
  • Think and drink coffee:
    • When I have an issue like this it hard for me to let it go. This is like the Rubik’s Cube I had when I was in the 6th grade. I didn’t want to put it down. Eventually my English teacher took it from me. Not surprisingly I lost access to the cube for a while because after going to the school to get it back my parents didn’t return it to me immediately. If I don’t figure this out now, I will be thinking about this while mowing the grass this afternoon, while walking the dog and everything else I do. I learned to try and let it go but be ready to make a note on my phone if something comes to me when I don’t have access to my computer.
  • Recap what I know:
    • PHP 7.4 is installed on the computer
    • WordPress is not using the latest version
    • The LAMP is between the computer and WordPress
  • List possible solutions or random things to try next:
    • Does Apache2 have a PHP configuration?
    • Format the computer and start over.
    • Remove old version of PHP.
    • Does WordPress have a PHP configuration?
    • Do nothing and move on?
  • Evaluate the list and put it in a reasonable order:
    1. Apache2 configuration
      • I am going to start here because I really think this is the most likely the problem. I did some quick searches but didn’t find anything yet.
    2. Check WordPress for a configuration
      • This just occurred to me while creating the list so I didn’t research it. I doubt this is the case because I never had to change things on my hosted sites when PHP was upgraded.
    3. Remove old versions of PHP
      • This holds some risk because it is working now and I don’t want to mess up the computer that I use for all my work. This is something I would try sooner if I was using a test machine that would not impact me as much if I crashed it.
    4. Do nothing and move on
      • This is an option because I am I am doing this for fun right now. I will need to solve this problem eventually however it isn’t critical right now and I believe that just being aware of the issue will help me see the solution eventually because my brain will be processing this even if I am not actively working on it.
    5. Format the computer and start over
      • Although this would solve the problem it isn’t an option. This is on the computer that I use everyday. Although I think everything is backed up and could be recovered if this computer crashed that would be a major disruption.
  • Step though the list until the solution is found
    • I am following these steps to configure apache2
      • karl@StanLee:~$ sudo apt install libapache2-mod-fcgid
      • karl@StanLee:~$ sudo apt install php7.4-fpm
      • Just to test switching between 7.4 and 7.1 I ran the following command:
      • karl@StanLee:~$ sudo apt install php7.1-fpm
      • The following shows what was installed:
      • karl@StanLee:~$ lsLink will go here /var/run/php
        • Here is the result:
        • php7.1-fpm.pid
        • php7.1-fpm.sock
        • php7.4-fpm.pid
        • php7.4-fpm.sock
        • php-fpm.sock
      • karl@StanLee:~$ sudo a2enmod actions alias proxy_fcgi fcgid
      • karl@StanLee:~$ sudo service php7.4-fpm start
      • karl@StanLee:~$ sudo service php7.1-fpm start
      • karl@StanLee:~$ sudo systemctl restart apache2
      • I added the following lines to my site.conf file in apache2 and restarted Apache2
<FilesMatch \.php> # Apache 2.4.10+ can proxy to unix socket
        SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
</FilesMatch> 
  • This crashed my test site. I received a MySQL extension missing error.
    • At least this was an easy fix.
    • karl@StanLee:~$ sudo aLink will go herept install php7.4-mysql
    • karl@StanLee:~$ sudo systemctl restart apache2
    • Refresh the site and check the php version
Screen shot showing PHP 7.4 is running.

I now have WordPress running PHP7.4. To test this was able to change the site.conf file and restart Apache2 and switch between PHP7.1 and PHP7.4. Now I can set up a new site and test PHP8.0.3.

I don’t fully understand all the steps that got me to this point. I will look into those later when I have time or need to learn more.

Thank you for joining me on my learning adventure. Hopefully this was helpful. Please contact me with any questions or comments.

karl@karlsclipboard.com


Notes:

I used this Article from PHP.Watch as a basis for my PHP upgrade.

This is the reference that I used to configure Apache2