How to Ubuntu 16.04 Multiple PHP Nginx
Ubuntu 16.04 is a robust operating system that is commonly used for web application development. This operating system uses Nginx as the web server and PHP as the programming language. It is not uncommon to have multiple PHP versions on a server especially if you’re developing different applications that require different versions of PHP. In this article, we are going to explore how to Ubuntu 16.04 multiple PHP Nginx.
Preparing The System
Before we proceed to install and configure multiple PHP versions on Ubuntu 16.04, we need to update our system packages. This helps us to ensure that our system is up-to-date and that we have the latest packages. Here is the command to update our system:
sudo apt-get update && sudo apt-get upgrade
Install Nginx
The first step towards using multiple PHP versions on Ubuntu 16.04 is installing the Nginx web server. To install Nginx, use the following command:
sudo apt-get install nginx
Once Nginx is installed, we can confirm whether it’s up and running with the following command:
sudo systemctl status nginx
Install PHP
The next step is to install the various versions of PHP that we require. Ubuntu 16.04 comes with PHP 7. To install it just use the following command:
sudo apt-get install php-fpm php-mysql php-mbstring
With PHP 7 installed, we also need to install other versions of PHP. In this case, let’s install PHP 5.6 and PHP 7.1:
sudo apt-get install php5.6-fpm php5.6-mysql php5.6-mbstring
sudo apt-get install php7.1-fpm php7.1-mysql php7.1-mbstring
Once we’ve installed the various PHP versions, we need to configure Nginx to use them.
Configure Nginx
The configuration file for Nginx is found in the /etc/nginx/ directory. Navigate to this directory by typing the following command:
cd /etc/nginx/
Next, create a new file called example.com inside the sites-available directory:
sudo nano /etc/nginx/sites-available/example.com
Paste the following code into this file. This sets up a server block with two different locations, one for PHP 7 and the other for PHP 5.6.
server {
listen 80 ;
server_name example.com;
root /var/www/example.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /php5.6 {
alias /var/www/example.com/php5.6;
try_files $uri $uri/ /php5.6/index.php?$args;
}
location /php7.1 {
alias /var/www/example.com/php7.1;
try_files $uri $uri/ /php7.1/index.php?$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Before proceeding, ensure that the server_name line reflects your domain name. Also, ensure that the root directory defined in this file (/var/www/example.com) reflects your website’s location.
We also have two locations that correspond to PHP 5.6 and PHP 7.1. These locations map to directories where we have installed PHP 5.6 and PHP 7.1 respectively.
Next, we need to enable this server block by creating a symbolic link to the /etc/nginx/sites-enabled directory. The command to do this is:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Finally, check that the Nginx is properly configured by typing the following command:
sudo nginx -t
If Nginx is properly configured, we should get the following output:
nginx: configuration file /etc/nginx/nginx.conf test is successful
Conclusion
In conclusion, using multiple PHP versions in Ubuntu 16.04 is possible with a little configuration. We’ve covered how to install and configure multiple PHP versions using Nginx. With this guide, you should be able to get started with developing web applications on Ubuntu 16.04. Don’t forget to update your system regularly to ensure that you have the latest packages.
Happy developing!
Related Posts:
- Check Nginx Status Ubuntu 16.04 Check Nginx Status Ubuntu 16.04 What is Nginx? Nginx (pronounced "engine x") is an open source web server that is used for hosting websites and applications on a wide range…
- How To Install Flask Nginx On Ubuntu 1604 How To Install Flask Nginx On Ubuntu 1604 Introduction Flask is a web application framework based on Python. It is highly useful for web developers due to its flexibility and…
- Ubuntu Nginx Php-Fpm Short Cut Ubuntu Nginx Php-Fpm Short Cut What Is Nginx? Nginx is a web server software package developed by Igor Sysoev for use with the Linux operating system. It is open source…
- Install Postgis Ubuntu 18.04 Nginx Install Postgis Ubuntu 18.04 Nginx What is Postgis? Postgis is a Postgres-based open source geographic information system (GIS) that enables users to store, query, and analyze spatial data stored in…
- Remove Nginx And Install Apche Ubuntu 18.04 Remove Nginx And Install Apche Ubuntu 18.04 Introduction The world of web servers is quite vast and different web servers have different applications and preferences. If you are new to…
- Virtualhost Nginx Ubuntu 16.04 Virtualhost Nginx Ubuntu 16.04 Introduction to Virtualhost Virtualhost is a software configuration option in web servers including Apache, Nginx, and more that allows a web server to host multiple web…
- Install Phpmyadmin On Nginx Ubuntu 18.04 Install Phpmyadmin On Nginx Ubuntu 18.04 Introduction PhpMyAdmin is one of the most popular and widely used web-based database management tools available. It is used for administering, managing and maintaining…
- Tutorial Start Nginx Ubuntu Webserver Tutorial Start Nginx Ubuntu Webserver Step 1: Prerequisites Before we start configuring Nginx as a web server on Ubuntu, we need to make sure we have the following prerequisites: A…
- Digital Ocean Ubuntu Server Nginx Docker Digital Ocean Ubuntu Server Nginx Docker Understanding Digital Ocean Digital Ocean is a cloud service provider that focuses on simplifying web infrastructure for cloud developers. They offer a platform where…
- How To Deactive Nginx Ubuntu How To Deactivate Nginx Ubuntu Introduction Nginx is a web server that’s popular in the Linux world because of its simple configuration, scalability, and performance. The Apache httpd web server…
- How To Set Rails On Nginx Ubuntu 18.04 How To Set Rails On Nginx Ubuntu 18.04 Step 1: Install Ruby Using RVM The first step for setting up Ruby on Rails on an Ubuntu 18.04 server with Nginx…
- How Use Nginx Mysql Ubuntu How to Use Nginx, MySQL and Ubuntu What is Nginx? Nginx is an open source web server and reverse proxy software written by Igor Sysoev. It is a popular choice…
- Digitalocean Letsencrypt Nginx Ubuntu 18.04 Digitalocean Letsencrypt Nginx Ubuntu 18.04 Introduction Ubuntu 18.04 is the latest version of the popular Linux operating system. Digitalocean is a cloud hosting provider that specializes in hosting and managing…
- Docker Nginx Php Mysql In Xampp Docker Nginx Php Mysql In Xampp Overview of Docker Nginx Php Mysql in Xampp Docker Nginx Php Mysql in Xampp is a powerful web development platform used for developing complex…
- Install Laravel 5.8 Nginx Php7.3 Install Laravel 5.8 Nginx Php7.3 Overview Installing Laravel 5.8 on a Nginx server running PHP 7.3 can be a tricky task. This tutorial explains how to install the popular open…
- Install Mysql Pada Nginx Pada Ubuntu Install Mysql Pada Nginx Pada Ubuntu Overview of Nginx and Its Benefits Nginx is a web server, reverse proxy server, and mail proxy server application that is open-source and available…
- Nginx Php-Fpm Php Mariadb Mysql Centos 7.2 Digitalocean Nginx, Php-Fpm, Php, Mariadb, Mysql, Centos 7.2 Digitalocean Introduction: What is Nginx? Nginx is a powerful web server that was first released in 2004. It is known for being a…
- Ubuntu Server Postgresql Nginx Php Digitalocean Laravel Ubuntu Server Postgresql Nginx Php Digitalocean Laravel Introduction To The Stack Ubuntu Server, Postgresql, Nginx, PHP, Digitalocean and Laravel are an exceptional combination of elements that, when put together, make…
- Nginx Install Ssl Certificate Ubuntu Nginx Install SSL Certificate Ubuntu What is Nginx? Nginx is a free, open-source web server that is used for powering websites. It is popular for its speed, scalability, and stability,…
- Nginx Install 3 Version Php Nginx Install 3 Version Php What is Nginx, and What Benefits Does It Provide? Nginx is a server software used to create web applications, present content on the Internet, and…
- Log Nginx Ubuntu 14.04 Log Nginx Ubuntu 14.04 Introduction Nginx is an open-source web server that is considered fast and reliable for online traffic. It has been around for many years and is one…
- Installing Nginx On Centos 7 Installing Nginx On Centos 7 What is Nginx? Nginx is an open source, high performance web server software. It is commonly used for caching static web pages to speed up…
- Install Pdo_Mysql Ubuntu Nginx Install Pdo_Mysql Ubuntu Nginx What is Pdo_Mysql? PDO_Mysql is a driver for the PHP Data Objects (PDO) extension that provides a database abstraction layer for working with MySQL databases.PDO_Mysql provides…
- Virtual Host Nginx Ubuntu 16.04 Virtual Host Nginx Ubuntu 16.04 Introduction A virtual host (also known as Virtual Private Server or VPS) is a service that allows a single physical server to host multiple websites.…
- Install Php5 Nginx Ubuntu 18.04 Install PHP5 Nginx Ubuntu 18.04 Understanding The Basics of Nginx and PHP Before we learn how to install Nginx and PHP on Ubuntu 18.04, it’s important to understand the basic…
- Centos 6 Nginx Multiple Php Version Centos 6 Nginx Multiple PHP Versions What is CentOS 6? CentOS 6 is a Linux-based operating system. It is a free, open-source operating system that is based on Red Hat…
- Error Access Denided For User Root On Nginx Ubuntu 18 Error Access Denied For User Root On Nginx Ubuntu 18 What Is Nginx? Nginx is a web server which can be used to serve static files, run web applications, generate…
- Install Rails On Ubuntu Nginx Rbenv Install Rails On Ubuntu Nginx Rbenv Introduction Rails is an open-source web application framework written in Ruby. It is designed to make programming web applications easier by providing a full…
- Install Nginx Latest Ubuntu 16.04 Install Nginx Latest Ubuntu 16.04 What is Nginx? Nginx is a web server. It is also an open source and free software. It was first developed by Igor Sysoev in…
- Ubuntu 18.04 Nginx Hide Port Ubuntu 18.04 Nginx Hide Port Introduction to Nginx with Ubuntu Nginx is an open source web server and reverse proxy software that is commonly used in Linux servers. It is…