GNU/Linux >> Tutoriales Linux >  >> Debian

Cómo instalar PHP 7 (PHP-FPM y FastCGI) para ISPConfig 3 en Debian 8 (Jessie)

La primera versión beta de PHP 7 está disponible para descargar ahora, PHP 7 es hasta 2 veces más rápido que php 5.6 y 14 veces más rápido que php 5.0 según las notas de la versión. La nueva versión de PHP no es 100% compatible con PHP 5.x ya que se han eliminado algunas API obsoletas, por lo que es una buena idea comenzar a probar la compatibilidad de sus sitios web con esta nueva versión. Esto se puede hacer fácilmente y sin afectar todos los sitios en su servidor usando la función de versión múltiple de PHP en ISPConfig 3. La versión de PHP se puede seleccionar en la configuración del sitio web de ISPConfig 3 para cada sitio individualmente. Esta función funciona con PHP-FPM y FastCGI. Este tutorial muestra cómo compilar el nuevo PHP 7 (Beta) como una versión PHP-FPM y FastCGI en un servidor Debian Jessie. Estas compilaciones de PHP 7 incluyen Zend OPcache.

Nota Preliminar

Instalaré PHP 7 que se encuentra actualmente en Beta en el momento de escribir este artículo. Tenga en cuenta que PHP-FPM se puede usar en servidores Apache y nginx, mientras que FastCGI solo está disponible para servidores Apache.

Con versiones anteriores de PHP, PHP-FPM y FastCGI se excluyeron mutuamente, por lo que un binario fpm y FastCGI se crearon por separado. Con PHP 7, ambos binarios se pueden compilar juntos, por lo que tendremos que hacer solo una compilación de PHP ahora.

Compila PHP 7 con PHP-FPM y Fastcgi

Descarga y extrae PHP 7:

mkdir -p /opt/php-7.0.0
mkdir /usr/local/src/php5-build
cd /usr/local/src/php5-build
wget https://downloads.php.net/~ab/php-7.0.0beta1.tar.bz2 -O php-7.0.0.tar.bz2
tar jxf php-7.0.0.tar.bz2
cd php-7.0.0beta1/

Instale los requisitos previos para compilar PHP 7 y el editor nano que usaré para editar los archivos de configuración:

apt-get install build-essential nano
apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-turbo-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a

(El último comando es necesario si compila PHP con --with-imap, porque de lo contrario, ./configure se detendrá con el siguiente error:

checking for crypt in -lcrypt... yes
configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.
[email protected]:/usr/local/src/php5-build/php-7.0.0#

)

Configure y cree PHP 7.0.0 de la siguiente manera (puede ajustar el comando ./configure según sus necesidades, eche un vistazo a

./configure --help

para ver todas las opciones disponibles; si usa un comando ./configure diferente, es posible que se requieran bibliotecas adicionales o que el proceso de compilación falle):

./configure --prefix=/opt/php-7.0.0 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-mysqli --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm

El último cambio (--enable-fpm) asegura que esta versión de PHP funcionará con PHP-FPM.

make
make install

Copie php.ini y php-fpm.conf en las ubicaciones correctas:

cp /usr/local/src/php5-build/php-7.0.0beta1/php.ini-production /opt/php-7.0.0/lib/php.ini
cp /opt/php-7.0.0/etc/php-fpm.conf.default /opt/php-7.0.0/etc/php-fpm.conf
cp /opt/php-7.0.0/etc/php-fpm.d/www.conf.default /opt/php-7.0.0/etc/php-fpm.d/www.conf

Abra /opt/php-7.0.0/etc/php-fpm.conf y ajuste la siguiente configuración (elimine el # delante de la línea pid):

nano /opt/php-7.0.0/etc/php-fpm.conf
[...]
pid = run/php-fpm.pid
[...]

Luego abra /opt/php-7.0.0/etc/php-fpm.conf y ajuste la línea de escucha, debe usar un puerto no utilizado (por ejemplo, 8999; el puerto 9000 podría estar ya en uso por el PHP-FPM predeterminado de Debian):

nano /opt/php-7.0.0/etc/php-fpm.d/www.conf
[...]
listen = 127.0.0.1:8999
[...]

Debian es compatible con Systemd, así como con los scripts de inicio tradicionales. Primero crearé un script de inicio para el servicio php-fpm y luego crearé una unidad systemd.

Primero cree un script de inicio para PHP-FPM:

nano /etc/init.d/php-7.0.0-fpm
#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-7.0.0-fpm
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-7.0.0-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO
php_fpm_BIN=/opt/php-7.0.0/sbin/php-fpm
php_fpm_CONF=/opt/php-7.0.0/etc/php-fpm.conf
php_fpm_PID=/opt/php-7.0.0/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF"
wait_for_pid () {
        try=0
        while test $try -lt 35 ; do
                case "$1" in
                        'created')
                        if [ -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                        'removed')
                        if [ ! -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                esac
                echo -n .
                try=`expr $try + 1`
                sleep 1
        done
}
case "$1" in
        start)
                echo -n "Starting php-fpm "
                $php_fpm_BIN $php_opts
                if [ "$?" != 0 ] ; then
                        echo " failed"
                        exit 1
                fi
                wait_for_pid created $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;
        stop)
                echo -n "Gracefully shutting down php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -QUIT `cat $php_fpm_PID`
                wait_for_pid removed $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed. Use force-exit"
                        exit 1
                else
                        echo " done"
                       echo " done"
                fi
        ;;
        force-quit)
                echo -n "Terminating php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -TERM `cat $php_fpm_PID`
                wait_for_pid removed $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;
        restart)
                $0 stop
                $0 start
        ;;
        reload)
                echo -n "Reload service php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -USR2 `cat $php_fpm_PID`
                echo " done"
        ;;
        *)
                echo "Usage: $0 {start|stop|force-quit|restart|reload}"
                exit 1
        ;;
esac

Haga que el script de inicio sea ejecutable y cree los enlaces de inicio del sistema:

chmod 755 /etc/init.d/php-7.0.0-fpm
insserv php-7.0.0-fpm

Y ahora crea el archivo de unidad systemd

nano /lib/systemd/system/php-7.0.0-fpm.service

con el siguiente contenido:

[Unit]
Description=The PHP 7 FastCGI Process Manager
After=network.target

[Service]
Type=simple
PIDFile=/opt/php-7.0.0/var/run/php-fpm.pid
ExecStart=/opt/php-7.0.0/sbin/php-fpm --nodaemonize --fpm-config /opt/php-7.0.0/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

Y recarga systemd:

systemctl daemon-reload

Finalmente inicie PHP-FPM.

Para sistemas con sistema de inicio tradicional, ejecute:

/etc/init.d/php-7.0.0-fpm start

El resultado debería ser:

/etc/init.d/php-7.0.0-fpm start
Starting php-fpm done

En los servidores que usan systemd, use este comando en su lugar:

systemctl start php-7.0.0-fpm.service

Para habilitar Zend OPcache, abra /opt/php-7.0.0/lib/php.ini...

nano /opt/php-7.0.0/lib/php.ini

... y agregue la siguiente línea al final:

[...]
zend_extension=opcache.so

La extensión Memcache y APCu aún no se puede instalar en PHP 7, por lo que omitiré su instalación por ahora. Actualizaré el tutorial más adelante cuando las extensiones pecl sean compatibles con PHP 7.

Habilitar PHP 7 en ISPConfig

En ISPConfig 3, puede configurar la nueva versión de PHP en Sistema> Versiones adicionales de PHP. En la pestaña Nombre, simplemente ingrese un nombre para la versión de PHP (por ejemplo, PHP 7.0.0); esta versión de PHP aparecerá con este nombre en la configuración del sitio web en ISPConfig:

Vaya a la pestaña Configuración de FastCGI y complete los campos de la siguiente manera:

Path to the PHP FastCGI binary: /opt/php-7.0.0/bin/php-cgi
Path to the php.ini directory: /opt/php-7.0.0/lib

Luego vaya a la pestaña Configuración de PHP-FPM y complete los campos de la siguiente manera:

Path to the PHP-FPM init script: /etc/init.d/php-7.0.0-fpm
Path to the php.ini directory: /opt/php-7.0.0/lib
Path to the PHP-FPM pool directory: /opt/php-7.0.0/etc/php-fpm.d

4 Enlaces

  • PHP:http://www.php.net/
  • ISPConfig:http://www.ispconfig.org/
  • Debian:http://www.debian.org/

Debian
  1. Cómo compilar PHP 5.6 (PHP-FPM y FastCGI) con Zend OPcache y APCu para ISPConfig 3 en Debian 7 (Wheezy)

  2. Cómo instalar PHP 8.0 en Debian 11

  3. Cómo instalar PHP 8.0 en Debian 10 / Debian 9

  4. Cómo instalar PHP en Debian 11

  5. Cómo instalar PHP 7.2 en Debian 9

Cómo instalar PHP 7.1, 7.2 y 5.6 como PHP-FPM y FastCGI para ISPConfig 3 en Debian 9

Cómo instalar PHP 5.6 y 7.0 - 8.1 como PHP-FPM y FastCGI para ISPConfig 3 con apt en Debian 8 a 11

Cómo instalar LAMP (Apache, MySQL, PHP) en Debian 8 Jessie

Cómo instalar Apache con PHP-FPM en Debian 10

Cómo instalar Nginx con PHP-FPM en Debian 10

Cómo instalar ISPConfig en Debian 11