Este artículo demuestra cómo cambiar la versión de PHP en un servidor Debian desde paquete. Por ejemplo, actualizar a PHP 7.4 en Debian Buster. Veamos el proceso de actualización de versión de PHP desde 7.3 a 7.4 en un servidor Debian que utiliza FPM y el CLI de PHP.

La versión de PHP disponible en un servidor Debian varía de acuerdo a la versión del sistema operativo instalada. Por ejemplo en Debian Buster (10) se dispone de PHP 7.3. La siguiente página de la Wiki de Debian detalla la versión de PHP disponible en cada versión de Debian: PHP - Debian Wiki.

Si se necesita una versión superior, por ejemplo PHP 7.4, es posible recurrir al repositorio DEB.SURY.ORG. Se trata de un repositorio de paquetes de PHP para Debian y Ubuntu provisto por Ondřej Surý, desarrollador de Debian desde 2000. Podría decirse que se trata de un repositorio de paquetes semi-oficial de Debian, y una fuente confiable de versiones actualizadas de PHP para Debian.

Veamos el proceso de actualización de versión de PHP desde 7.3 a 7.4 en un servidor Debian que utiliza FPM y el CLI de PHP.

Preparación

Obtener la lista de paquetes de la versión actual de PHP instalados:

root@debian:~#  apt list --installed | grep "^php7.3" | cut -d'/' -f1

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

php7.3
php7.3-bz2
php7.3-cli
php7.3-common
php7.3-curl
php7.3-dev
php7.3-fpm
php7.3-gd
php7.3-intl
php7.3-json
php7.3-mbstring
php7.3-mysql
php7.3-opcache
php7.3-readline
php7.3-soap
php7.3-xml
php7.3-zip

Convertir "7.3" por "7.4" para pegar en apt-get:

root@debian:~# apt list --installed | grep "^php7.3" | cut -d'/' -f1 | tr '\n' ' ' | sed 's/7.3/7.4/g'; echo

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

php7.4 php7.4-bz2 php7.4-cli php7.4-common php7.4-curl php7.4-dev php7.4-fpm php7.4-gd php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-soap php7.4-xml php7.4-zip

Simular la instalación (-s):

root@debian:~# apt-get -s install php7.4 php7.4-bz2 php7.4-cli php7.4-common php7.4-curl php7.4-dev php7.4-fpm php7.4-gd php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-soap php7.4-xml php7.4-zip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
php7.4-common is already the newest version (7.4.13-1+0~20201130.33+debian9~1.gbpd59941).
php7.4-common set to manually installed.
php7.4-zip is already the newest version (7.4.13-1+0~20201130.33+debian9~1.gbpd59941).
php7.4-zip set to manually installed.
The following additional packages will be installed:
  libonig4
The following NEW packages will be installed:
  libonig4 php7.4 php7.4-bz2 php7.4-cli php7.4-curl php7.4-dev php7.4-fpm php7.4-gd php7.4-intl php7.4-json php7.4-mbstring
  php7.4-mysql php7.4-opcache php7.4-readline php7.4-soap php7.4-xml
0 upgraded, 16 newly installed, 0 to remove and 0 not upgraded.
Inst libonig4 (6.1.3-2+deb9u1 Debian-Security:9/oldstable [amd64])
Inst php7.4-json (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-opcache (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-readline (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-cli (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-fpm (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4 (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [all])
Inst php7.4-bz2 (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-curl (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-dev (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-gd (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-intl (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-mbstring (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-mysql (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-soap (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Inst php7.4-xml (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf libonig4 (6.1.3-2+deb9u1 Debian-Security:9/oldstable [amd64])
Conf php7.4-json (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-opcache (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-readline (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-cli (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-fpm (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4 (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [all])
Conf php7.4-bz2 (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-curl (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-dev (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-gd (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-intl (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-mbstring (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-mysql (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-soap (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])
Conf php7.4-xml (7.4.13-1+0~20201130.33+debian9~1.gbpd59941 packages.sury.org [amd64])

Actualización

Si se está de acuerdo con el resultado, instalar:

# apt-get install php7.4 php7.4-bz2 php7.4-cli php7.4-common php7.4-curl php7.4-dev php7.4-fpm php7.4-gd php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-soap php7.4-xml php7.4-zip

Diferencias en módulos de PHP de la versión 7.3 a la 7.4:

root@debian:/var/log/apt# ls -1 /etc/php/7.3/mods-available/ > /tmp/php7.3-mods
root@debian:/var/log/apt# ls -1 /etc/php/7.4/mods-available/ > /tmp/php7.4-mods
root@debian:/var/log/apt# diff /tmp/php7.3-mods /tmp/php7.4-mods 
6a7
> ffi.ini
32d32
< wddx.ini

El módulo wddx deja de estar disponible y aparece el módulo ffi.

Configuración de la nueva versión

Actualización de alternatives

Cambiar los enlaces simbólicos de PHP para que apunten a la versión 7.4:

# update-alternatives --config php
# update-alternatives --config phar
# update-alternatives --config phar.phar
# update-alternatives --config phpize
# update-alternatives --config php-config

Resultado:

root@debian:~# update-alternatives --config php
There are 4 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
  0            /usr/bin/php7.4   74        auto mode
  1            /usr/bin/php7.0   70        manual mode
  2            /usr/bin/php7.2   72        manual mode
* 3            /usr/bin/php7.3   73        manual mode
  4            /usr/bin/php7.4   74        manual mode

Press <enter> to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in manual mode
root@debian:~# update-alternatives --config phar
There are 4 choices for the alternative phar (providing /usr/bin/phar).

  Selection    Path              Priority   Status
------------------------------------------------------------
  0            /usr/bin/phar7.4   74        auto mode
  1            /usr/bin/phar7.0   70        manual mode
  2            /usr/bin/phar7.2   72        manual mode
* 3            /usr/bin/phar7.3   73        manual mode
  4            /usr/bin/phar7.4   74        manual mode

Press <enter> to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/phar7.4 to provide /usr/bin/phar (phar) in manual mode
root@debian:~# update-alternatives --config phar.phar
There are 4 choices for the alternative phar.phar (providing /usr/bin/phar.phar).

  Selection    Path                   Priority   Status
------------------------------------------------------------
  0            /usr/bin/phar.phar7.4   74        auto mode
  1            /usr/bin/phar.phar7.0   70        manual mode
  2            /usr/bin/phar.phar7.2   72        manual mode
* 3            /usr/bin/phar.phar7.3   73        manual mode
  4            /usr/bin/phar.phar7.4   74        manual mode

Press <enter> to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/phar.phar7.4 to provide /usr/bin/phar.phar (phar.phar) in manual mode
root@debian:~# update-alternatives --config phpize
There are 4 choices for the alternative phpize (providing /usr/bin/phpize).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/phpize7.4   74        auto mode
  1            /usr/bin/phpize7.0   70        manual mode
  2            /usr/bin/phpize7.2   72        manual mode
* 3            /usr/bin/phpize7.3   73        manual mode
  4            /usr/bin/phpize7.4   74        manual mode

Press <enter> to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/phpize7.4 to provide /usr/bin/phpize (phpize) in manual mode
root@debian:~# update-alternatives --config php-config
There are 4 choices for the alternative php-config (providing /usr/bin/php-config).

  Selection    Path                    Priority   Status
------------------------------------------------------------
  0            /usr/bin/php-config7.4   74        auto mode
  1            /usr/bin/php-config7.0   70        manual mode
  2            /usr/bin/php-config7.2   72        manual mode
* 3            /usr/bin/php-config7.3   73        manual mode
  4            /usr/bin/php-config7.4   74        manual mode

Press <enter> to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/php-config7.4 to provide /usr/bin/php-config (php-config) in manual mode

Comprobar:

root@debian:/etc/php/7.4/fpm# ll /etc/alternatives/ | grep 7.3
root@debian:/etc/php/7.4/fpm# ll /etc/alternatives/ | grep 7.4
lrwxrwxrwx 1 root root  16 Dec  4 09:38 phar -> /usr/bin/phar7.4
lrwxrwxrwx 1 root root  32 Dec  4 09:38 phar.1.gz -> /usr/share/man/man1/phar7.4.1.gz
lrwxrwxrwx 1 root root  21 Dec  4 09:38 phar.phar -> /usr/bin/phar.phar7.4
lrwxrwxrwx 1 root root  37 Dec  4 09:38 phar.phar.1.gz -> /usr/share/man/man1/phar.phar7.4.1.gz
lrwxrwxrwx 1 root root  15 Dec  4 08:39 php -> /usr/bin/php7.4
lrwxrwxrwx 1 root root  31 Dec  4 08:39 php.1.gz -> /usr/share/man/man1/php7.4.1.gz
lrwxrwxrwx 1 root root  22 Dec  4 09:38 php-config -> /usr/bin/php-config7.4
lrwxrwxrwx 1 root root  38 Dec  4 09:38 php-config.1.gz -> /usr/share/man/man1/php-config7.4.1.gz
lrwxrwxrwx 1 root root  24 Dec  4 08:20 php-fpm.sock -> /run/php/php7.4-fpm.sock
lrwxrwxrwx 1 root root  18 Dec  4 09:38 phpize -> /usr/bin/phpize7.4
lrwxrwxrwx 1 root root  34 Dec  4 09:38 phpize.1.gz -> /usr/share/man/man1/phpize7.4.1.gz
root@debian:~# php -v
PHP 7.4.13 (cli) (built: Nov 30 2020 20:40:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies
Actualización de FPM

Primero actualizar los pooles de FPM. Copiar la configuración de pooles desde 7.3 a 7.4:

root@debian:~# cd /etc/php/7.3/fpm/pool.d/
root@debian:/etc/php/7.3/fpm/pool.d# cp -a *linuxito* /etc/php/7.4/fpm/pool.d/
root@debian:/etc/php/7.3/fpm/pool.d# ll /etc/php/7.4/fpm/pool.d/
total 100
-rw-r--r-- 1 root root 18389 May  9  2019 wiki.linuxito.com.conf
-rw-r--r-- 1 root root 18381 May  9  2019 testing.linuxito.com.conf
-rw-r--r-- 1 root root 19683 Nov 30 17:40 www.conf

Si se modificó el pool por defecto (www.conf) será necesario copiarlo también.

Copiar php.ini:

root@debian:/etc/php/7.3/fpm# grep -v "^;" php.ini | grep -v "^$" > ../../7.4/fpm/php.ini.7.3-nocomments
root@debian:/etc/php/7.3/fpm# cd ../../7.4/fpm/
root@debian:/etc/php/7.4/fpm# grep -v "^;" php.ini | grep -v "^$" > php.ini.7.4-nocomments

Comparar ambos archivos y actualizar la nueva versión de php.ini para 7.4:

# diff php.ini.7.3-nocomments php.ini.7.4-nocomments

Editar el archivo de configuración de la nueva versión:

root@debian:/etc/php/7.4/fpm# nano php.ini

Modifican las variables en el php.ini de la nueva versión para que quede igual al de la versión anterior. Por ejemplo:

precision = -1
max_execution_time = 120
max_input_vars = 100
memory_limit = 64M
html_errors = On
upload_max_filesize = 20M
date.timezone = "America/Argentina/Buenos_Aires"
intl.default_locale = es-AR
session.gc_maxlifetime = 43200

Cada una de estas configuraciones personalizadas tiene el siguiente propósito:

Luego se debe hacer el switch de servicio FPM:

root@debian:~# netstat -xln | grep php
unix  2      [ ACC ]     STREAM     LISTENING     1108827  /run/php/php7.4-fpm.sock
unix  2      [ ACC ]     STREAM     LISTENING     1072012  /var/run/php7-fpm_wiki.linuxito.com.sock
unix  2      [ ACC ]     STREAM     LISTENING     1072018  /var/run/php7-fpm_testing.linuxito.com.sock
unix  2      [ ACC ]     STREAM     LISTENING     1072024  /run/php/php7.3-fpm.sock

Detener FPM 7.3:

root@debian:/etc/php/7.4/fpm# service php7.3-fpm stop
root@debian:/etc/php/7.4/fpm# netstat -xln | grep php
unix  2      [ ACC ]     STREAM     LISTENING     1108827  /run/php/php7.4-fpm.sock

Reiniciar FPM 7.4:

root@debian:/etc/php/7.4/fpm/pool.d# service php7.4-fpm stop
root@debian:/etc/php/7.4/fpm/pool.d# service php7.4-fpm start
root@debian:/etc/php/7.4/fpm/pool.d# netstat -xln | grep php
unix  2      [ ACC ]     STREAM     LISTENING     1112470  /var/run/php7-fpm_wiki.linuxito.com.sock
unix  2      [ ACC ]     STREAM     LISTENING     1112476  /var/run/php7-fpm_testing.linuxito.com.sock
unix  2      [ ACC ]     STREAM     LISTENING     1112482  /run/php/php7.4-fpm.sock

Por último, deshabilitar el servicio php7.3-fpm y habilitar el servicio php7.4-fpm:

root@debian:/etc/php/7.4/fpm/pool.d# systemctl disable php7.3-fpm
Synchronizing state of php7.3-fpm.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable php7.3-fpm
insserv: warning: current start runlevel(s) (empty) of script `php7.3-fpm' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `php7.3-fpm' overrides LSB defaults (0 1 6).
root@debian:/etc/php/7.4/fpm/pool.d# systemctl enable php7.4-fpm
Synchronizing state of php7.4-fpm.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable php7.4-fpm
Actualización de php.ini para CLI

Cambiar al directorio de configuración del CLI de PHP 7.4:

root@debian:/etc/php/7.4/fpm/pool.d# cd /etc/php/7.4/cli/

Comparar con la versión anterior:

# diff ../../7.3/cli/php.ini php.ini | grep -v "^< ;" | grep -v "^> ;" | grep -v "^< $" | grep -v "^> $"

Editar el archivo de configuración de la nueva versión:

root@debian:/etc/php/7.4/cli# nano php.ini

Se realizan las siguientes modificaciones:

precision = -1
max_execution_time = 60
memory_limit = 128M
html_errors = On
date.timezone = "America/Argentina/Buenos_Aires"
intl.default_locale = es-AR

Cada una de estas configuraciones personalizadas tiene el siguiente propósito:

Referencias

Compartí este artículo