Upgrading from PHP 7.2 to PHP 7.4 with Red Hat Universal Base Image

Today, I noticed that the WordPress Admin Console was complaining that I was using PHP 7.2 which is getting old. I was kind of dreading upgrading because upgrades are a nightmare, but then I realized I had put everything in containers. One of the things that makes containers awesome is how easy it is to upgrade software once you have everything blueprinted with container image builds. While it took a lot of work to get all of my services into containers (see also: A Hacker’s Guide To Moving Linux Services Into Containers).

Here’s what I did to upgrade from PHP 7.2 to PHP 7.4 with Red Hat Universal Base Image at a high level:

  1. Rebuilt the PHP container
  2. Killed my internal MediaWiki instance to test the new version (systemd restarted the container perfectly)
  3. Killed my WordPress instance (systemd restarted the container perfectly)
  4. Clicked on a page in the WordPress Admin page and noticed that it was much faster

 

Going one layer deeper, here’s what I did. First, I added a new line to my Containerfile:

vim Containerfile-httpd-php

Then, I added the following line right before my YUM install command. This highlights the magic of Application Streams in RHEL. It’s super easy to go from PHP 7.2, the default installed on RHEL, to PHP 7.4 which is packaged as a module in RHEL 8:

RUN yum module enable -y php:7.4

The total Container file ended up looking like this:

FROM registry.access.redhat.com/ubi8/ubi-init
MAINTAINER fatherlinux <[email protected]>
RUN yum module enable -y php:7.4
RUN yum install -y mariadb-server mariadb php php-apcu php-intl php-mbstring php-xml php-json php-mysqlnd crontabs cronie iputils net-tools;yum clean all
RUN systemctl enable mariadb
RUN systemctl enable httpd
RUN systemctl disable systemd-update-utmp.service
ENTRYPOINT ["/sbin/init"]
CMD ["/sbin/init"]

Next, I rebuilt the image:

podman build -f Containerfile-httpd-php -t localhost/httpd-php

When the build completed, I killed my private MediaWiki instance to test. If the MediaWiki instance would have failed, I would have troubleshooted before killing my public site:

podman kill learn.fatherlinux.com

I tested it in a browser:

https://learn.fatherlinux.com

It worked like a charm, so I got brave enough to kill my public WordPress instance:

podman kill wordpress.crunchtools.com

Then I tested it:

https://crunchtools.com

Final step, commit the change to git:

git commit Containerfile-httpd-php
git push

That’s it. Now my rebuilds will always happen with PHP 7.4. When an Application Stream Comes out for PHP 7.5+ I’ll just perform this same process but bump the number. So easy, so nice. The stability of the RHEL userspace combined with the convenience of containers makes this upgrade painless.

One comment on “Upgrading from PHP 7.2 to PHP 7.4 with Red Hat Universal Base Image”

Leave a Reply

Your email address will not be published. Required fields are marked *