DEV Community

Cover image for Upgrading to PHP8.1 on CentOS 7.x
Ken Ng
Ken Ng

Posted on • Updated on

Upgrading to PHP8.1 on CentOS 7.x

Laravel 9 which has been released recently dropped the support for PHP7.x, and now it can only run on PHP8.0-PHP8.1.

PHP8.1 is shipped with a few nice features like Enums, readonly class property and etc. The introduction of the Enums finally allows you to type-hint permissible values accepted by a variable than resort to using docblock typehints, or third-party “fake enum” packages.

Let's dive into how to upgrade our server to PHP8.1 from PHP8.0.

sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install yum-utils

sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php81

sudo yum install -y php81-php php81-php-fpm php81-php-mysql php81-php-gd php81-php-curl php81-php-mbstring php81-php-xml php81-php-bcmath php81-php-sqlite3 php81-php-zip
Enter fullscreen mode Exit fullscreen mode

Two issues encountered during the upgrade

1. Conflicts of library

file /usr/lib64/libzip.so.5 from install of libzip5-1.8.0-2.el7.remi.x86_64 conflicts with file from package libzip-1.3.2-1.amzn2.0.1.x86_64

Solution: remove the existing package then run the installation of php81 again
$ yum remove libzip-1.3.2-1.amzn2.0.1.x86_64

2. php-fpm is not enabled and started properly

Check using systemctl

$ systemctl list-unit-files | grep fpm
php81-php-fpm.service                         disabled
Enter fullscreen mode Exit fullscreen mode

Let's enable and starts it, then check its status

$ systemctl enable php81-php-fpm.service
$ systemctl start php81-php-fpm.service

$ systemctl status php81-php-fpm.service
● php81-php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php81-php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-05-06 18:21:15 +08; 6min ago
 Main PID: 16011 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 6
   Memory: 8.9M
   CGroup: /system.slice/php81-php-fpm.service
           ├─16011 php-fpm: master process (/etc/opt/remi/php81/php-fpm.conf)
           ├─15897 php-fpm: pool www
           ├─15898 php-fpm: pool www
           ├─15899 php-fpm: pool www
           ├─15900 php-fpm: pool www
           └─15901 php-fpm: pool www
Enter fullscreen mode Exit fullscreen mode

Another issue noticed is php-fpm does not read php-fpm config that we have setup in /etc/php-fpm.d. From the output of systemctl status command, we can see that configuration read is located at /etc/opt/remi/php81/php-fpm.conf.

Edit this file to update the conf directory to be read

;include=/etc/opt/remi/php81/php-fpm.d/*.conf
include=/etc/php-fpm.d/*.conf
Enter fullscreen mode Exit fullscreen mode

Now restart the php-fpm service again

$ systemctl restart php81-php-fpm.service 
$ systemctl status php81-php-fpm.service 
● php81-php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php81-php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-05-06 18:30:07 +08; 32min ago
 Main PID: 16296 (php-fpm)
   Status: "Processes active: 0, idle: 21, Requests: 30, slow: 0, Traffic: 0req/sec"
    Tasks: 22
   Memory: 118.6M
   CGroup: /system.slice/php81-php-fpm.service
           ├─16296 php-fpm: master process (/etc/opt/remi/php81/php-fpm.conf)
           ├─16297 php-fpm: pool app.xxx.com
           ├─16298 php-fpm: pool app.xxx.com
Enter fullscreen mode Exit fullscreen mode

Instead of the www pool, we can see that it's now serving the pool for the website app.xxx.com that we have set up in the pool configuration.

That's all for it!

Top comments (1)

Collapse
 
leslieeeee profile image
Leslie

If you are a macOS user, ServBay.dev is worth to try. You don't need to spend some time or couple of days to setup anything. Just download it and you can use it immediately. You can run multiple PHP versions simultaneously and switch between them effortlessly.
Honestly, this tool has greatly simplified my PHP development and is definitely worth trying!