Jesús Amieiro

Update Debian to PHP 7.4

PHP 7.4 has been published on 28 Nov 2019.

To update the active version of PHP to this one in a Debian system, you can follow the next steps.

This tutorial works on:

# Install these packages
$ sudo apt install apt-transport-https lsb-release
# Download the signing key 
$ sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
# Add Ondrej's repo to the sources list 
$ sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' 
# Update the list of available packages
$ sudo apt update 

You can check the PHP packages that you have installed in your server with a previous PHP version to install the same packages with PHP 7.4. To do this, you have to use the command:

$ sudo php -m

To search the packages that you can install, you have to use the command:

$ sudo apt search php7.4

To install the PHP 7.4 core you have to use the command:

$ sudo apt install php7.4 php7.4-common php7.4-cli

Then you have to install the extensions. All the extensions have the prefix “php7.4”. To do this, you have to use the command:

$ sudo apt install php7.4-fpm php7.4-bcmath php7.4-curl php7.4-xml php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-readline php7.4-soap php7.4-xsl php7.4-opcache php7.4-zip

The default CLI version becomes PHP 7.4.

$ php -v
 PHP 7.4.0 (cli) (built: Nov 28 2019 08:38:49) ( NTS )
 Copyright (c) The PHP Group
 Zend Engine v3.4.0, Copyright (c) Zend Technologies
     with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies

If you need to change the default version for other, you can use the command:

$ sudo update-alternatives --config php
Existen 5 opciones para la alternativa php (que provee /usr/bin/php).
   Selección   Ruta             Prioridad  Estado
 0            /usr/bin/php7.4   74        modo automático
 1            /usr/bin/php7.2   72        modo manual
 2            /usr/bin/php7.3   73        modo manual
 3            /usr/bin/php7.4   74        modo manual 

Pulse  para mantener el valor por omisión [*] o pulse un número de selección: 2
 update-alternatives: utilizando /usr/bin/php7.3 para proveer /usr/bin/php (php) en modo manual

If you check the default PHP version, now you can see that has changed to PHP 7.3:

$ php -v
PHP 7.3.12-1+0~20191128.49+debian8~1.gbp24559b (cli) (built: Nov 28 2019 08:32:01) ( NTS )
Exit mobile version