Updating PHP on Ubuntu

Screenshot of PHP warning in WordPress
PHP warning in WordPress

I am beta testing the WordPress FSE (Full Site Editor). I got tired of switching between my test machine and my main computer. (I know I really need to figure out how set up a real home network) So, I am dusting off the LAMP on my laptop. WordPress is giving me a warning that I am running an insecure version of php. At the time I wrote this I was running PHP 7.1.33 and the latest release is PHP 8.0.3. I don’t need to run the latest so I will be upgrading to PHP 7.4.16. I have no clue how to do this so I will be documenting my steps in the post as I learn.

I am getting a list of PHP packages with the following command.

karl@StanLee:~$ dpkg -l | grep php | tee packates.txt

This created a list in my terminal and created a packages.txt file in the directory that I am currently working in.

To install PHP 7.4 the following command was used:

karl@StanLee:~$ sudo apt install php7.4 php7.4-common php7.4-cli

This installed the minimum parts of PHP. I will now install the other parts of PHP I used when installed the LAMP:

karl@StanLee:~$ sudo apt install php-mysql php7.4-cgi php7.4-cli php7.4-gd libapache2-mod-php7.4

Next step check the version of the PHP:

karl@StanLee:~$ sudo php -version
PHP 7.4.16 (cli) (built: Mar 5 2021 07:54:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.16, Copyright (c), by Zend Technologies

I think it worked.

I have a test PHP file at 127.0.0.1/test.php. I put that into my browser and it worked. My last step is to restart Apache and check WordPress.

OK – WordPress is still showing the PHP7.1.22 error message. Since I am the site admin for my development server I can’t call anyone so, Google here I come to trouble shoot.

My trouble shooting steps turned into a full blog post that I will link to after I edit it. So if you want to see my trouble shooting philosophy and the details read my Troubleshooting PHP post.

Although PHP 7.4.16 was installed on my machine Apache was not using it. I needed to install additional PHP packets so I could configure Apache. I also added some packets to Apache.

  • karl@StanLee:~$ sudo apt install libapache2-mod-fcgid
  • karl@StanLee:~$ sudo apt install php7.4-fpm
  • So I can test by switching between 7.4 and 7.1 I also installed more PHP7.1 packages
  • karl@StanLee:~$ sudo apt install php7.1-fpm
  • Because WordPress is using the MySQL database
  • karl@StanLee:~$ sudo apt install php7.4-mysql

The following steps were needed prior to configuring the Apache server.

  • 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> 
  • 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. Eventually I will repeat these steps so I can 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