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:
- Remove current PHP versions
- Add Remi's RPM repo for Centos 7
- Install PHP 8
- Install PHP 8 additional libraries
- 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
Once you're confident you can reinstall everything, start by removing old PHP packages.
sudo yum remove php*
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
3. Install PHP 8
Now this is quite easy:
sudo yum install php80
Verify PHP is installed correctly by running
php80 -v
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)
Failed in
sodo yum install php80
:Have you added the optional epel repo? You might have other external repo that conflict with higher priority.
when i try to check the version after instalation php8 wasn't found php -v
-bash: /usr/bin/php: No such file or directory
The new binary is php80
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
What's the new Apache module?
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
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).
You wouldn't have any warnings until you remove all the code which is not compatible with PHP 8.
No package php80 available.
how can i fix it
How to Install or enable PHP's mbstring extension????
sudo yum install php80-php-mbstring
More in general, if you do
sudo yum search php80
You will see all available extension/modules
When I run my php file the php code appears written on the screen
How do you configure php8 with apache?