Debian 9 with old PHP 5.6 and MySQL 5.6, 5.7 or 8.0 and Apache2
Run below commands to upgrade the current packages to the latest version
#apt update
#apt upgrade
Install the Apache2 package
#apt install apache2
Execute the following commands to install the required packages first on your system. Then import packages signing key. After that configure PPA for the PHP packages on your system.
#apt install apt-transport-https lsb-release ca-certificates
#wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
#echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" >> /etc/apt/sources.list
Installing PHP 5.6
Execute the following commands for installing PHP 5.6 on your Debian 9 Stretch system.
#apt update
#apt install php5.6
#/usr/sbin/a2enmod php5.6
#/usr/sbin/a2enmod php5.6
Considering dependency mpm_prefork for php5.6:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php5.6:
Module php5.6 already enabled
Optional: Install PHP MOD for PHP Mysql and GD
#apt-get install php5.6-mysql php5.6-gd
OPTIONAL: Install completed php modules.
#apt install libmcrypt-dev libreadline-dev mcrypt php-pear
#apt install php5.6{cli,common,fpm,bcmath,mysql,curl,gd,imagick,intl,mbstring,xmlrpc,xsl,dev,zip,soap,xml}
Optional: Install PHP FPM
#apt-get install php5.6-fpm
Creating config file /etc/php/5.6/fpm/php.ini with new version
NOTICE: Not enabling PHP 5.6 FPM by default.
NOTICE: To enable PHP 5.6 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php5.6-fpm
#/usr/sbin/a2enmod proxy_fcgi setenvif
#/usr/sbin/a2enconf php5.6-fpm
Install MYSQL Version 5.6, 5.7 or 8.0, better 5.7 or 8.0
#apt -y install wget
#wget https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb
#dpkg -i mysql-apt-config_0.8.13-1_all.deb
During the installation the system will prompt to select MySQL version. Choose which MySQL version, 5.6, 5.7 or 8.0 available to choose then OK
#apt update
#apt -y install mysql-server
Finish up by running the MySQL secure_installation
#mysql_secure_installation
Test php working or not
Create new php file at /var/www/html
#vim info.php
write
<?php phpinfo(); ?>
Open browser http://localhost/info.php
Enable and load mod_rewrite Apache2 on Debian 8
#a2enmod rewrite
Then open and edit /etc/apache2/apache2.conf find
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Replace “AllowOverride None” to “AllowOverride all”
Enable Apache2 mod_headers & mod_expires on
To increase PageSpeed: Leverage browser caching.
enable mod_headers:
#a2enmod headers
enable mod_expires:
#a2enmod expires
Then restart Apache server to make these changes effective
#service apache2 restart