Downgrading to php7.3 on Amazon Linux 2

Installing an up to date version of PHP on Amazon Linux 2 is straightforward. You can follow this tutorialarrow-up-right, which makes use of the amazon-linux-extras command.

I found myself, however, in the unusual position of needing to run run an out of date version of PHP on AWS. The issue is that one of my clientsarrow-up-right is developing a WordPress plugin, and this plugin must run on PHP 7.3. The standard on Amazon Linux 2 these day is PHP 7.4.

Here are the steps I went through to coax my system from PHP 7.4 down to 7.3. I hope you don't find yourself needing these instructions, but if you do, enjoy!

# Grab a list of all the PHP modules currently installed
$ rpm -qa |grep php > all.installed
$ cat all.installed
php-common-7.4.26-1.amzn2.x86_64
php-fpm-7.4.26-1.amzn2.x86_64
php-json-7.4.26-1.amzn2.x86_64
php-pdo-7.4.26-1.amzn2.x86_64
php-cli-7.4.26-1.amzn2.x86_64
php-xml-7.4.26-1.amzn2.x86_64
php-mbstring-7.4.26-1.amzn2.x86_64
php-mysqlnd-7.4.26-1.amzn2.x86_64

# The 'remi' repo offers access to specific version of PHP.
# Here, I'm installing PHP 7.3 using the remi-php73 repo.
$ sudo yum install  http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ sudo  yum-config-manager --enable remi-php73

# Bye-bye up to date version of PHP.
$ sudo yum -y remove php*
$ sudo amazon-linux-extras disable php7.4

# Hello old, crufty version of PHP.
# Note: to access PHP modules the prefix is now 'php73-'
# So php-pdo is installed as php73-php-pdo.
$ sudo yum install php73
$ sudo yum install $(cat all.installed  | grep ^php-| sed 's/-7.4.*//' | sed 's/^/php73-/')

# Properly install php73 as /usr/bin/php
$ sudo update-alternatives --install /usr/bin/php php /usr/bin/php73 10

# Enable and start the php-fpm service
$ sudo systemctl enable php73-php-fpm
$ sudo systemctl start php73-php-fpm


# Where the heck are the config files for php-fpm? Let's ask rpm.
$ rpm -ql php73-php-fpm
/etc/logrotate.d/php73-php-fpm
/etc/opt/remi/php73/php-fpm.conf
/etc/opt/remi/php73/php-fpm.d
/etc/opt/remi/php73/php-fpm.d/www.conf
/etc/opt/remi/php73/sysconfig/php-fpm
/etc/systemd/system/php73-php-fpm.service.d
/opt/remi/php73/root/usr/sbin/php-fpm
/opt/remi/php73/root/usr/share/doc/php73-php-fpm-7.3.33
/opt/remi/php73/root/usr/share/doc/php73-php-fpm-7.3.33/php-fpm.conf.default
/opt/remi/php73/root/usr/share/doc/php73-php-fpm-7.3.33/www.conf.default
/opt/remi/php73/root/usr/share/fpm
/opt/remi/php73/root/usr/share/fpm/status.html
/opt/remi/php73/root/usr/share/licenses/php73-php-fpm-7.3.33
/opt/remi/php73/root/usr/share/licenses/php73-php-fpm-7.3.33/fpm_LICENSE
/opt/remi/php73/root/usr/share/man/man8/php-fpm.8.gz
/usr/lib/systemd/system/php73-php-fpm.service
/var/opt/remi/php73/lib/php/opcache
/var/opt/remi/php73/lib/php/session
/var/opt/remi/php73/lib/php/wsdlcache
/var/opt/remi/php73/log/php-fpm
/var/opt/remi/php73/run/php-fpm

# Found it. Now, where php-fpm listening?
$ cat /etc/opt/remi/php73/php-fpm.d/www.conf |grep ^listen
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1

# Use this info to create /etc/httpd/conf.d/php.conf
# so that Apache can talk to php-fpm and support PHP.
$ cat /etc/httpd/conf.d/php.conf
<FilesMatch "\.php$">
    # Note: The only part that varies is /path/to/app.sock
    SetHandler  "proxy:fcgi://localhost:9000"
</FilesMatch>

DirectoryIndex index.php

# Restart httpd and php-fpm
$ sudo systemctl restart httpd php73-php-fpm

And browsing to my server shows me this all worked. Amazing. Uh, I mean, I never had a doubt.

arrow-up-right

Last updated

Was this helpful?