Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucenarenato/f2b30a7e244381c55c424fdd409a02bb to your computer and use it in GitHub Desktop.
Save lucenarenato/f2b30a7e244381c55c424fdd409a02bb to your computer and use it in GitHub Desktop.
########################################################################
# 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-json \
php5.6-mbstring \
php5.6-mcrypt \
php5.6-mysql \
php5.6-opcache \
php5.6-readline \
php5.6-soap \
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-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-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-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-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
# Miscellanous PHP Packages
sudo apt install -y \
php-pear \
php-xdebug
# 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
# Disable PHP 5.6 Apache Module & Enable PHP 7.3-FPM Module
sudo a2dismod php5.6
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.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;
# }
########################################################################
# 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