Last active
March 26, 2025 17:46
-
-
Save sheikhwaqas/ee494834646f61351afd4e34cb354907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################################## | |
# Installing and Configuring Apache & Nginx with Multiple PHP Versions # | |
# Apache will run on port 8080 and will be behind Nginx # | |
# Nginx will serve as a reverse proxy for Apache Sites # | |
# Nginx will act as the primary web and caching server # | |
######################################################################## | |
# Update Packages | |
sudo apt update && sudo apt upgrade -y | |
# Install Apache2 Server | |
sudo apt install apache2 -y | |
# Modify Apache Ports to Listen on Port 80 (http) and 8443 (https) | |
sudo sed -i 's/80/8080/' /etc/apache2/ports.conf | |
sudo sed -i 's/443/8443/' /etc/apache2/ports.conf | |
# Restart Apache service to listen on the new ports | |
sudo systemctl restart apache2 | |
# Now, let's install Nginx as the primary web server to listen on Ports 80 & 443 for Non-SSL and SSL respectively | |
sudo apt install nginx -y | |
# Add the PHP Repository for Multi-PHP Version Installation | |
sudo add-apt-repository ppa:ondrej/php -y | |
# Install PHP Versions and their respective extensions | |
# PHP 5.6 | |
sudo apt install -y \ | |
libapache2-mod-php5.6 \ | |
php5.6 \ | |
php5.6-bcmath \ | |
php5.6-bz2 \ | |
php5.6-cli \ | |
php5.6-common \ | |
php5.6-curl \ | |
php5.6-enchant \ | |
php5.6-fpm \ | |
php5.6-gd \ | |
php5.6-intl \ | |
php5.6-json \ | |
php5.6-mbstring \ | |
php5.6-mcrypt \ | |
php5.6-mysql \ | |
php5.6-opcache \ | |
php5.6-readline \ | |
php5.6-soap \ | |
php5.6-sqlite3 \ | |
php5.6-tidy \ | |
php5.6-xml \ | |
php5.6-xmlrpc \ | |
php5.6-zip | |
# PHP 7.0 | |
sudo apt install -y \ | |
libapache2-mod-php7.0 \ | |
php7.0 \ | |
php7.0-bcmath \ | |
php7.0-bz2 \ | |
php7.0-cli \ | |
php7.0-common \ | |
php7.0-curl \ | |
php7.0-enchant \ | |
php7.0-fpm \ | |
php7.0-gd \ | |
php7.0-intl \ | |
php7.0-json \ | |
php7.0-mbstring \ | |
php7.0-mcrypt \ | |
php7.0-mysql \ | |
php7.0-opcache \ | |
php7.0-readline \ | |
php7.0-soap \ | |
php7.0-sqlite3 \ | |
php7.0-tidy \ | |
php7.0-xml \ | |
php7.0-xmlrpc \ | |
php7.0-xsl \ | |
php7.0-zip | |
# PHP 7.1 | |
sudo apt install -y \ | |
libapache2-mod-php7.1 \ | |
php7.1 \ | |
php7.1-bcmath \ | |
php7.1-bz2 \ | |
php7.1-cli \ | |
php7.1-common \ | |
php7.1-curl \ | |
php7.1-enchant \ | |
php7.1-fpm \ | |
php7.1-gd \ | |
php7.1-intl \ | |
php7.1-json \ | |
php7.1-mbstring \ | |
php7.1-mcrypt \ | |
php7.1-mysql \ | |
php7.1-opcache \ | |
php7.1-readline \ | |
php7.1-soap \ | |
php7.1-sqlite3 \ | |
php7.1-tidy \ | |
php7.1-xml \ | |
php7.1-xmlrpc \ | |
php7.1-xsl \ | |
php7.1-zip | |
# PHP 7.2 | |
sudo apt install -y \ | |
libapache2-mod-php7.2 \ | |
php7.2 \ | |
php7.2-bcmath \ | |
php7.2-bz2 \ | |
php7.2-cli \ | |
php7.2-common \ | |
php7.2-curl \ | |
php7.2-enchant \ | |
php7.2-fpm \ | |
php7.2-gd \ | |
php7.2-intl \ | |
php7.2-json \ | |
php7.2-mbstring \ | |
php7.2-mysql \ | |
php7.2-opcache \ | |
php7.2-readline \ | |
php7.2-soap \ | |
php7.2-sqlite3 \ | |
php7.2-tidy \ | |
php7.2-xml \ | |
php7.2-xmlrpc \ | |
php7.2-xsl \ | |
php7.2-zip | |
# PHP Version 7.3 | |
sudo apt install -y \ | |
libapache2-mod-php7.3 \ | |
php7.3 \ | |
php7.3-bcmath \ | |
php7.3-bz2 \ | |
php7.3-cli \ | |
php7.3-common \ | |
php7.3-curl \ | |
php7.3-enchant \ | |
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-sqlite3 \ | |
php7.3-tidy \ | |
php7.3-xml \ | |
php7.3-xmlrpc \ | |
php7.3-xsl \ | |
php7.3-zip | |
# PHP Version 7.4 | |
sudo apt install -y \ | |
libapache2-mod-php7.4 \ | |
php7.4 \ | |
php7.4-bcmath \ | |
php7.4-bz2 \ | |
php7.4-cli \ | |
php7.4-common \ | |
php7.4-curl \ | |
php7.4-enchant \ | |
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-sqlite3 \ | |
php7.4-tidy \ | |
php7.4-xml \ | |
php7.4-xmlrpc \ | |
php7.4-xsl \ | |
php7.4-zip | |
# PHP 8.0 | |
sudo apt install php8.0 \ | |
libapache2-mod-php8.0 \ | |
php8.0-bcmath \ | |
php8.0-bz2 \ | |
php8.0-cli \ | |
php8.0-common \ | |
php8.0-curl \ | |
php8.0-enchant \ | |
php8.0-fpm \ | |
php8.0-gd \ | |
php8.0-imagick \ | |
php8.0-intl \ | |
php8.0-mbstring \ | |
php8.0-memcache \ | |
php8.0-memcached \ | |
php8.0-mongodb \ | |
php8.0-mysql \ | |
php8.0-oauth \ | |
php8.0-opcache \ | |
php8.0-pgsql \ | |
php8.0-phpdbg \ | |
php8.0-pspell \ | |
php8.0-psr \ | |
php8.0-readline \ | |
php8.0-redis \ | |
php8.0-snmp \ | |
php8.0-soap \ | |
php8.0-solr \ | |
php8.0-sqlite3 \ | |
php8.0-tidy \ | |
php8.0-uuid \ | |
php8.0-xdebug \ | |
php8.0-xml \ | |
php8.0-xmlrpc \ | |
php8.0-xsl \ | |
php8.0-yaml \ | |
php8.0-zip | |
# PHP 8.1 | |
sudo apt install php8.1 \ | |
libapache2-mod-php8.0 \ | |
php8.1-bcmath \ | |
php8.1-bz2 \ | |
php8.1-cli \ | |
php8.1-common \ | |
php8.1-curl \ | |
php8.1-enchant \ | |
php8.1-fpm \ | |
php8.1-gd \ | |
php8.1-imagick \ | |
php8.1-intl \ | |
php8.1-mbstring \ | |
php8.1-mcrypt \ | |
php8.1-memcache \ | |
php8.1-memcached \ | |
php8.1-mongodb \ | |
php8.1-mysql \ | |
php8.1-oauth \ | |
php8.1-opcache \ | |
php8.1-pgsql \ | |
php8.1-phpdbg \ | |
php8.1-pspell \ | |
php8.1-psr \ | |
php8.1-readline \ | |
php8.1-redis \ | |
php8.1-snmp \ | |
php8.1-soap \ | |
php8.1-solr \ | |
php8.1-sqlite3 \ | |
php8.1-swoole \ | |
php8.1-tidy \ | |
php8.1-uploadprogress \ | |
php8.1-uuid \ | |
php8.1-xdebug \ | |
php8.1-xml \ | |
php8.1-xmlrpc \ | |
php8.1-xsl \ | |
php8.1-yaml \ | |
php8.1-zip | |
# PHP 8.2 | |
sudo apt install php8.2 \ | |
libapache2-mod-php8.2 \ | |
php8.2-bcmath \ | |
php8.2-bz2 \ | |
php8.2-cli \ | |
php8.2-common \ | |
php8.2-curl \ | |
php8.2-enchant \ | |
php8.2-fpm \ | |
php8.2-gd \ | |
php8.2-imagick \ | |
php8.2-intl \ | |
php8.2-mbstring \ | |
php8.2-mcrypt \ | |
php8.2-memcache \ | |
php8.2-memcached \ | |
php8.2-mongodb \ | |
php8.2-mysql \ | |
php8.2-oauth \ | |
php8.2-opcache \ | |
php8.2-pgsql \ | |
php8.2-phpdbg \ | |
php8.2-pspell \ | |
php8.2-psr \ | |
php8.2-readline \ | |
php8.2-redis \ | |
php8.2-snmp \ | |
php8.2-soap \ | |
php8.2-solr \ | |
php8.2-sqlite3 \ | |
php8.2-swoole \ | |
php8.2-tidy \ | |
php8.2-uploadprogress \ | |
php8.2-uuid \ | |
php8.2-xdebug \ | |
php8.2-xml \ | |
php8.2-xmlrpc \ | |
php8.2-xsl \ | |
php8.2-yaml \ | |
php8.2-zip | |
# PHP 8.3 | |
sudo apt install php8.3 \ | |
libapache2-mod-php8.3 \ | |
php8.3-bcmath \ | |
php8.3-bz2 \ | |
php8.3-cli \ | |
php8.3-common \ | |
php8.3-curl \ | |
php8.3-enchant \ | |
php8.3-fpm \ | |
php8.3-gd \ | |
php8.3-imagick \ | |
php8.3-intl \ | |
php8.3-mbstring \ | |
php8.3-mcrypt \ | |
php8.3-memcache \ | |
php8.3-memcached \ | |
php8.3-mongodb \ | |
php8.3-mysql \ | |
php8.3-oauth \ | |
php8.3-opcache \ | |
php8.3-pgsql \ | |
php8.3-phpdbg \ | |
php8.3-pspell \ | |
php8.3-psr \ | |
php8.3-readline \ | |
php8.3-redis \ | |
php8.3-snmp \ | |
php8.3-soap \ | |
php8.3-solr \ | |
php8.3-sqlite3 \ | |
php8.3-swoole \ | |
php8.3-tidy \ | |
php8.3-uploadprogress \ | |
php8.3-uuid \ | |
php8.3-xdebug \ | |
php8.3-xml \ | |
php8.3-xmlrpc \ | |
php8.3-xsl \ | |
php8.3-yaml \ | |
php8.3-zip | |
# Install Development Packages | |
sudo apt install php5.6-dev \ | |
php7.0-dev \ | |
php7.1-dev \ | |
php7.2-dev \ | |
php7.3-dev \ | |
php7.4-dev \ | |
php8.0-dev \ | |
php8.1-dev \ | |
php8.2-dev \ | |
php8.3-dev | |
# Restart all PHP FPM services | |
sudo systemctl restart php5.6-fpm | |
sudo systemctl restart php7.0-fpm | |
sudo systemctl restart php7.1-fpm | |
sudo systemctl restart php7.2-fpm | |
sudo systemctl restart php7.3-fpm | |
sudo systemctl restart php7.4-fpm | |
sudo systemctl restart php8.0-fpm | |
sudo systemctl restart php8.1-fpm | |
sudo systemctl restart php8.2-fpm | |
sudo systemctl restart php8.3-fpm | |
# Disable PHP 5.6 Apache Module & Enable PHP 8.2-FPM Module | |
sudo a2dismod php5.6 | |
sudo a2enmod proxy_fcgi setenvif | |
sudo a2enconf php8.3-fpm | |
# To Switch PHP FPM Version for Apache the following commands should be used | |
# sudo a2disconf php<ver>-fpm && sudo a2enconf php<ver>-fpm | |
sudo systemctl reload apache2 | |
# To enable Nginx Reverse Proxy for Apache, add the following to the Nginx specific site configuration | |
# location ~ \.php$ { | |
# proxy_set_header X-Real-IP $remote_addr; | |
# proxy_set_header X-Forwarded-For $remote_addr; | |
# proxy_set_header Host $host; | |
# proxy_pass http://127.0.0.1:8080; | |
# } | |
# To switch CLI PHP version to another than the default use the following syntax | |
# sudo update-alternatives --set php /usr/bin/php<version> | |
# For Example (Replace 8.2 with your PHP version) | |
# sudo update-alternatives --set php /usr/bin/php8.2 | |
# sudo update-alternatives --set phar /usr/bin/phar8.2 | |
# sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.2 | |
# sudo update-alternatives --set php-config /usr/bin/php-config8.2 | |
# sudo update-alternatives --set phpize /usr/bin/phpize8.2 | |
######################################################################## | |
# Now configure your Apache and Nginx Virtual Hosts / Sites # | |
# Enjoy! # | |
######################################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment