How to compile and install PHP 7.4 as PHP-FPM and FastCGI for ISPConfig 3 on Ubuntu 18.04 LTS

How to compile and install PHP 7.4 as PHP-FPM and FastCGI for ISPConfig 3 on Ubuntu 18.04 LTS

Ubuntu 18.04 comes with PHP 7.2 as the default PHP version. Major PHP versions are not 100% compatible with each other, so websites may need newer or older PHP versions to work properly. ISPConfig supports multiple PHP versions on the same server. You can choose a PHP version for each website individually in the website settings. This tutorial shows how to install PHP 7.4 on PHP 18 with FPM and FCGI mode on an Ubuntu 18 server. Other PHP versions are installed in the / opt folder, so their installation will not affect the default PHP version.

1 preliminary description

I will install PHP 7.4. Please note that PHP-FPM is available on Apache and Nginx servers, while FastCGI is only available on Apache servers.

2 installation prerequisites

Install the prerequisites for building PHP and the nano editor for editing configuration files:

apt -y install build-essential nano net-tools autoconf
apt -y install libfcgi-dev libfcgi0ldbl libjpeg-turbo8-dev libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libzip-dev libsqlite3-dev libonig-dev
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
cd /usr/includeln -s x86_64-linux-gnu/curl

(If you use –with-imap to build PHP, you need the last command, because otherwise ./configure will stop with the following error:

checking for crypt in -lcrypt... yesconfigure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.[email protected]:/tmp/php-7.4.0

)

3 compile PHP 7.4 to PHP-FPM and Fastcgi

Download and unzip the PHP archive:

cd /tmpwget https://www.php.net/distributions/php-7.4.0.tar.gztar xfz php-7.4.0.tar.gz
cd php-7.4.0

Configure and build PHP 7.4 as follows (you can adjust the ./configure command as needed,

./configure --help

See all available options; if you use other ./configure commands, you may need additional libraries, otherwise the build process will fail):

./configure --prefix=/opt/php-7.4 --with-pdo-pgsql --with-zlib-dir --with-freetype --enable-mbstring --enable-soap --enable-calendar --with-curl --with-zlib --enable-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 --with-zip --with-pdo-mysql --with-mysqli --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-jpeg --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-intl --with-pear --enable-fpm

The last switch (–enable-fpm) ensures that this PHP version can be used with PHP-FPM.

makemake install

Copy the file to the correct location:

cp php.ini-production /opt/php-7.4/lib/php.ini
cp /opt/php-7.4/etc/php-fpm.conf.default /opt/php-7.4/etc/php-fpm.conf
cp /opt/php-7.4/etc/php-fpm.d/www.conf.default /opt/php-7.4/etc/php-fpm.d/www.conf

Adjust /opt/php-7.4/etc/php-fpm.conf

sed -i 's/;pid = run/php-fpm.pid/pid = run/php-fpm.pid/g' /opt/php-7.4/etc/php-fpm.conf

Then update /opt/php-7.4/etc/php-fpm.d/www.conf:

cp /opt/php-7.4/etc/php-fpm.d/www.conf.default /opt/php-7.4/etc/php-fpm.d/www.conf

If you have another PHP version installed, check that the port is not in use:

netstat -tapn | grep -E ".*899.*php-fpm"

If you use nginx as a web server, adjust /opt/php-7.4/lib/php.ini:

sed -i 's/;date.timezone =/date.timezone = "Europe/Berlin"/g' /opt/php-7.4/lib/php.ini
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /opt/php-7.4/lib/php.ini

3.1 create system unit files

Next, we will create a system unit file that is used to start and stop the PHP-FPM daemon.

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

Has the following:

[Unit]Description=The PHP 7.4 FastCGI Process ManagerAfter=network.target[Service]Type=simplePIDFile=/opt/php-7.4/var/run/php-fpm.pidExecStart=/opt/php-7.4/sbin/php-fpm --nodaemonize --fpm-config /opt/php-7.4/etc/php-fpm.confExecReload=/bin/kill -USR2 $MAINPID[Install]WantedBy=multi-user.target

Enable the service and reload systemd:

systemctl enable php-7.4-fpm.servicesystemctl daemon-reload

Finally, start PHP-FPM.

systemctl start php-7.4-fpm.service

To enable Zend OPcache:

echo zend_extension=opcache.so >> /opt/php-7.4/lib/php.ini

3.2 Enable Memcache (optional)

Use these commands to install memcache.

cd /opt/php-7.4/etc../bin/pecl -C ./pear.conf update-channels../bin/pecl -C ./pear.conf install memcached

And enable memache

echo extension=memcached.so >> /opt/php-7.4/lib/php.ini

3.3 Install xDebug Extension (optional)

The xDebug module is a debugging extension for PHP. Installation is optional.

Use these commands to install xDebug.

cd /opt/php-7.4/etc../bin/pecl -C ./pear.conf update-channels../bin/pecl -C ./pear.conf install xdebug

And enable xDebug

echo zend_extension=/opt/php-7.4/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so >> /opt/php-7.4/lib/php.ini

Finally restart the php-fpm daemon:

systemctl start php-7.4-fpm.service

Test the PHP version:

cd /opt/php-7.4/bin./php --version

3.4 Enable PHP 7.4 in ISPConfig

In ISPConfig 3.1, you can configure a new PHP version under System> Other PHP Versions. On the “Name” tab, you only need to fill in the name of the PHP version (eg PHP 7.4)-this PHP version will be listed under that name in the ISPConfig’s website settings:

Go to the “FastCGI Settings” tab and fill in the fields as follows:

Path to the PHP FastCGI binary: /opt/php-7.4/bin/php-cgiPath to the php.ini directory: /opt/php-7.4/lib
How to compile and install PHP 7.4 as PHP-FPM and FastCGI for ISPConfig 3 on Ubuntu 18.04 LTS

Then go to the PHP-FPM settings tab and fill in the fields as follows:

Path to the PHP-FPM init script: php-7.4-fpmPath to the php.ini directory: /opt/php-7.4/libPath to the PHP-FPM pool directory: /opt/php-7.4/etc/php-fpm.d
How to compile and install PHP 7.4 as PHP-FPM and FastCGI for ISPConfig 3 on Ubuntu 18.04 LTS

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

Source

Sidebar