Sam's Tech Blog

'You can check out any time you like, But you can never leave!'



How to install PHP7 (and 8) on new Debian web server.


This "How To" assumes that you have a working Debian web server. Here is a good guide for perfect server.

Repositories for Debian web-server Apache/NginX
apt-get install -y apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg
echo "deb $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt-get update

Update 2021/09: DPA has a new key. You might have to upgrade with:
wget -O /etc/apt/trusted.gpg.d/php.gpg
apt-get update

Legacy support
apt install php-memcache php-memcached php-apcu php-apcu-bc php-mysql sqlite libsqlite3-0 php-sqlite3 php-zip php-zeroc-ice php-xml php-tcpdf php-ssh2 php-soap php-snmp php-redis php-php-gettext php-mysql php-pear php-net-smtp php-net-socket php-net-imap php-net-nntp php-mcrypt php-mbstring php-imap php-intl php-json php-imagick php-gnupg php-gd php-geoip php-fpm php-dev php-mail php-mail-mime php-curl php-auth-sasl

Currently supported php7
apt install php7.0-common php7.0-cli php7.0-cgi php7.0-fpm php7.0-gd php7.0-mbstring php7.0-mysql php7.0-sqlite3 php7.0-imap php7.0-curl php7.0-intl php7.0-pspell php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-zip php7.0-soap php7.1-common php7.1-cli php7.1-cgi php7.1-fpm php7.1-gd php7.1-mbstring php7.1-mysql php7.1-sqlite3 php7.1-imap php7.1-curl php7.1-intl php7.1-pspell php7.1-sqlite3 php7.1-tidy php7.1-xmlrpc php7.1-xsl php7.1-zip php7.1-soap php7.2-common php7.2-cli php7.2-cgi php7.2-fpm php7.2-gd php7.2-mbstring php7.2-mysql php7.2-sqlite3 php7.2-imap php7.2-curl php7.2-intl php7.2-pspell php7.2-sqlite3 php7.2-tidy php7.2-xmlrpc php7.2-xsl php7.2-zip php7.2-soap php7.3-common php7.3-cli php7.3-cgi php7.3-fpm php7.3-gd php7.3-mbstring php7.3-mysql php7.3-sqlite3 php7.3-imap php7.3-curl php7.3-intl php7.3-pspell php7.3-sqlite3 php7.3-tidy php7.3-xmlrpc php7.3-xsl php7.3-zip php7.3-soap php7.4-common php7.4-cli php7.4-cgi php7.4-fpm php7.4-gd php7.4-mbstring php7.4-mysql php7.4-sqlite3 php7.4-imap php7.4-curl php7.4-intl php7.4-pspell php7.4-sqlite3 php7.4-tidy php7.4-xmlrpc php7.4-xsl php7.4-zip php7.4-soap

New php8
apt install php8.0-common php8.0-cli php8.0-cgi php8.0-fpm php8.0-gd php8.0-mbstring php8.0-mysql php8.0-sqlite3 php8.0-imap php8.0-curl php8.0-intl php8.0-pspell php8.0-sqlite3 php8.0-tidy php8.0-xmlrpc php8.0-xsl php8.0-zip php8.0-soap

No longer supported
apt install php7.?-mcrypt php7.?-recode

Enable new services
systemctl enable php7.0-fpm
systemctl enable php7.1-fpm
systemctl enable php7.2-fpm
systemctl enable php7.3-fpm
systemctl enable php7.4-fpm

systemctl enable php8.0-fpm
a2enconf php8.0-fpm

a2enmod proxy_fcgi setenvif

Activate the necessary Apache modules
a2enmod suexec rewrite ssl actions include cgi dav_fs dav auth_digest headers proxy_fcgi alias

Set Default PHP to 7.0
update-alternatives --config php
update-alternatives --config php-cgi

Mandatory commands
systemctl restart php*
systemctl restart apache2.service

Helpful diagnostic commands
systemctl status php7*
systemctl status apache2.service
systemctl status php7.0-fpm.service
systemctl enable php7.4-fpm

systemctl status php8*
systemctl status apache2.service
systemctl status php8.0-fpm.service
systemctl enable php8.0-fpm

You should keep the default PHP version as 7.0 or many 3rd party services like ISPConfig may fail to start.

ISPConfig related - Additional PHP Versions
These settings are found in ISPConfig System Settings
(Leave Client field empty!)

PHP Name: PHP 7.0
FastCGI Settings: 
Path to the PHP FastCGI binary: php-cgi7.0
Path to the php.ini directory: /etc/php/7.0/cgi/php.ini
PHP-FPM Settings: 
Path to the PHP-FPM init script: php7.0-fpm
Path to the php.ini directory: /etc/php/7.0/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.0/fpm/pool.d

PHP Name: PHP 7.1
FastCGI Settings: 
Path to the PHP FastCGI binary: php-cgi7.1
Path to the php.ini directory: /etc/php/7.1/cgi/php.ini
PHP-FPM Settings: 
Path to the PHP-FPM init script: php7.1-fpm
Path to the php.ini directory: /etc/php/7.1/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.1/fpm/pool.d

PHP Name: PHP 7.2
FastCGI Settings: 
Path to the PHP FastCGI binary: php-cgi7.2
Path to the php.ini directory: /etc/php/7.2/cgi/php.ini
PHP-FPM Settings: 
Path to the PHP-FPM init script: php7.2-fpm
Path to the php.ini directory: /etc/php/7.2/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.2/fpm/pool.d

PHP Name: PHP 7.3
FastCGI Settings: 
Path to the PHP FastCGI binary: php-cgi7.3
Path to the php.ini directory: /etc/php/7.3/cgi/php.ini
PHP-FPM Settings: 
Path to the PHP-FPM init script: php7.3-fpm
Path to the php.ini directory: /etc/php/7.3/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.3/fpm/pool.d

PHP Name: PHP 7.4
FastCGI Settings: 
Path to the PHP FastCGI binary: php-cgi7.4
Path to the php.ini directory: /etc/php/7.4/cgi/php.ini
PHP-FPM Settings: 
Path to the PHP-FPM init script: php7.4-fpm
Path to the php.ini directory: /etc/php/7.4/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.4/fpm/pool.d