DEV Community

Andrea Olivato
Andrea Olivato

Posted on • Updated on • Originally published at andreaolivato.Medium

Install PHP 8 on AWS Amazon Linux 2

PHP 8 is finally here, and it's time to upgrade our DEV environments to start resolving all those Warnings :)

At Lnk.Bio we use the official AWS Amazon Linux 2 AMI, and usually rely on the library Amazon Linux Extras to update/switch php version, but PHP 8 is yet to be included (and I couldn't find any timeline anywhere).

Therefore, I found the best way to install PHP 8 is to rely on Remi's RPM repository which features all major PHP versions for RHEL/Centos (on which Amazon Linux 2 AMI is sort of based).

The steps are quite easy:

  1. Remove current PHP versions
  2. Add Remi's RPM repo for Centos 7
  3. Install PHP 8
  4. Install PHP 8 additional libraries
  5. Paths/Configuration Notes

Please note that this guide is not intended for those who want to run multiple PHP versions at the same time. It will replace the current PHP version with PHP 8.

Let's go

1. Remove current PHP version

If you don't have a formal documentation (you should!) of which additional PHP packages you need for your app, you can get a list by running.

sudo yum list installed | grep php
Enter fullscreen mode Exit fullscreen mode

Once you're confident you can reinstall everything, start by removing old PHP packages.

sudo yum remove php*
Enter fullscreen mode Exit fullscreen mode

2. Add Remi's RPM repo for Centos 7

You will also need EPEL for Centos 7 for dependencies. I guess most people have this already enabled on Amazon Linux 2 AMI, but I am adding it anyway for clarity:

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php80
Enter fullscreen mode Exit fullscreen mode

3. Install PHP 8

Now this is quite easy:

sudo yum install php80
Enter fullscreen mode Exit fullscreen mode

Verify PHP is installed correctly by running

php80 -v
Enter fullscreen mode Exit fullscreen mode

4. Install PHP 8 Additional libraries

If you use additional modules/libraries, you can now install them. Naming convention remained the same, but they have the prefix php80-php-{library}

For example, if you use php-fpm you'll run sudo yum install php80-php-fpm; if you need mysqlnd you'll run sudo yum install php80-php-mysqlnd etc...

5. Paths/Configuration notes

Please note that Remi's PHP will be installed under /opt and the binary is php80. Here are a few locations you need to know:

  • PHP configuration files (php.ini, php-fpm.d etc..): /etc/opt/remi/php80/
  • PHP logs: /var/opt/remi/php80/log/
  • PHP Binary: /usr/bin/php80

You can of course create symlinks if you prefer.

Top comments (14)

Collapse
 
abtfur profile image
Richard Fu

Failed in sodo yum install php80:

Error: Package: php80-runtime-1.0-3.el7.remi.x86_64 (remi-safe)
           Requires: scl-utils
 You could try using --skip-broken to work around the problem
** Found 5 pre-existing rpmdb problem(s), 'yum check' output follows:
4:perl-5.16.3-294.43.amzn1.x86_64 is a duplicate with 4:perl-5.16.3-286.38.amzn1.x86_64
perl-Getopt-Long-2.40-3.6.amzn1.noarch is a duplicate with perl-Getopt-Long-2.40-2.5.amzn1.noarch
1:perl-Pod-Escapes-1.04-294.43.amzn1.noarch is a duplicate with 1:perl-Pod-Escapes-1.04-286.38.amzn1.noarch
4:perl-libs-5.16.3-294.43.amzn1.x86_64 is a duplicate with 4:perl-libs-5.16.3-286.38.amzn1.x86_64
4:perl-macros-5.16.3-294.43.amzn1.x86_64 is a duplicate with 4:perl-macros-5.16.3-286.38.amzn1.x86_64
Enter fullscreen mode Exit fullscreen mode
Collapse
 
andreaolivato profile image
Andrea Olivato

Have you added the optional epel repo? You might have other external repo that conflict with higher priority.

Collapse
 
ed_olii profile image
Eduardo Oliveros • Edited

when i try to check the version after instalation php8 wasn't found php -v
-bash: /usr/bin/php: No such file or directory

Collapse
 
andreaolivato profile image
Andrea Olivato

The new binary is php80

Collapse
 
alanondra profile image
Alan Ondra

This new binary name also means tools like composer will not work. Before you go to install it, you'll need to alias PHP so the environment resolves it:

ln -s /usr/bin/php80 /usr/bin/php

Collapse
 
alanondra profile image
Alan Ondra

What's the new Apache module?

Collapse
 
andreaolivato profile image
Andrea Olivato

I don't use the Apache module, which is not the most performing integration.

You can use php80-php-fpm as cgi wrapper, with either apache or nginx.

Not sure about the built-in module

Collapse
 
alanondra profile image
Alan Ondra

Turns out the new mod_php is php80-php in this repo.

I haven't really been in an environment where a more performant server is needed, until you're just doing a completely different architecture altogether (i.e. microservices).

Collapse
 
malwarebo profile image
Irfan

You wouldn't have any warnings until you remove all the code which is not compatible with PHP 8.

Collapse
 
hisampala profile image
hisampala

No package php80 available.
how can i fix it

Collapse
 
ed_olii profile image
Eduardo Oliveros

How to Install or enable PHP's mbstring extension????

Collapse
 
andreaolivato profile image
Andrea Olivato

sudo yum install php80-php-mbstring

More in general, if you do
sudo yum search php80
You will see all available extension/modules

Collapse
 
kaiksilva profile image
Kaik Silva

When I run my php file the php code appears written on the screen

Collapse
 
donvitocodes profile image
donvitocodes

How do you configure php8 with apache?