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:
- 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…
- 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…
- 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…
- Install Php Nginx Mysql Ubuntu 18.04 Install Php Nginx Mysql Ubuntu 18.04 What is PHP, Nginx, and MySQL PHP is a popular and powerful scripting language that can be used to create dynamic web pages, web…
- Ubuntu 16.04 Nginx Ipv6 Ubuntu 16.04 Nginx Ipv6 What is Ubuntu 16.04? Ubuntu 16.04 is a version of the Ubuntu Linux operating system for computers and servers. Ubuntu has been around since 2004, and…
- Nginx Error Invalid Pid Number In Var Run Nginx Pid Nginx Error Invalid Pid Number In Var Run Nginx Pid What is NGINX? NGINX is an open source web server created in 2002. It is a popular web server used…
- How To Set Up Nginx Loadbalancer Ubuntu How To Set Up Nginx Loadbalancer Ubuntu Introduction to Nginx Loadbalancer Nginx Loadbalancer is a web application that lets you easily set up load balancing for your website. It is…
- Install Nginx And Php On Ubuntu 18.04 Install Nginx And Php On Ubuntu 18.04 Introduction In this article, we will guide you on how to install Nginx and php on Ubuntu 18.04. Nginx is a popular web…
- Nginx Mariadb Php Fpm Debian8 Mariadb Nginx Mariadb Php Fpm Debian8 Mariadb Introduction to the Setup Nginx, MariaDB, and PHP are all popular tools for web development. Nginx is a web server, MariaDB is an open-source…
- Nginx On Ubuntu 18.04 Nginx On Ubuntu 18.04 What is Nginx? Nginx is a free, open-source, high-performance web server software. It is known for its stability, rich feature set, simple configuration, and low resource…
- Install Nginx Php Java On Centos 7 Install Nginx Php Java On Centos 7 What is Nginx? Nginx is an open source Web server created to serve Web traffic efficiently, reliably, and quickly. Nginx has become the…
- 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 Phpmyadmin On Nginx Ubuntu Install Phpmyadmin On Nginx Ubuntu What Is Phpmyadmin? Phpmyadmin is a free, open source web application written in PHP specifically designed to help manage MySQL databases. It is a powerful…
- 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…
- 403 Forbidden Nginx Ubuntu 14.04 403 Forbidden Nginx Ubuntu 14.04 What Is a 403 Forbidden Error? A 403 Forbidden error is an HTTP status code that denotes that a server, upon receiving a request from…
- Install Nginx Phpmyadmin Ubuntu 18.04 Install Nginx Phpmyadmin Ubuntu 18.04 Introduction to Nginx, PHP, and Ubuntu Nginx is an open-source, high-performance web server written in C and used to serve static and dynamic webpages. It…
- 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…
- 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…
- Ubuntu 16 Bind9 Nginx Subdomain Ubuntu 16 Bind9 Nginx Subdomain Overview Ubuntu is a popular Linux-based operating system, often used in web hosting. Bind 9 is a DNS server, commonly used in Ubuntu, that helps…
- Install Odoo 11 Nginx Ubuntu 16 Install Odoo 11 Nginx Ubuntu 16 What is Odoo 11 Nginx? Odoo 11 Nginx is an open source software package designed to facilitate secure and reliable web development. It is…
- Ubuntu Install Nginx Php7.2 Mysql Ubuntu Install Nginx Php7.2 Mysql What is Nginx? Nginx is an open source web server that is very popular for powering web applications such as WordPress and Drupal. It is…
- Digital Ocean Ubuntu Nginx Docker Digital Ocean Ubuntu Nginx Docker What is Digital Ocean? Digital Ocean is a cloud computing provider. It is a great platform for businesses and developers who need to quickly set…
- Digital Ocean Ubuntu Server Nginx Digital Ocean Ubuntu Server Nginx Introducing Digital Ocean Digital Ocean, a leader in cloud hosting, provides high-performance server instances, unlimited storage, and multiple configurations for all types of digital demands.…
- 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…
- 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…
- Failed To Start Nginx Service In Ubuntu Failed to Start Nginx Service in Ubuntu What is Nginx? Nginx is an open-source web server written in C, designed for high performance and stability. Nginx is one of the…
- Php-Fpm Nginx Ubuntu 18.04 PHP-FPM & Nginx on Ubuntu 18.04 Introduction to PHP-FPM PHP-FPM (FastCGI Process Manager) is an implementation of FastCGI, which is a standard protocol for interfacing external applications with web servers.…
- Ubuntu Nginx See Real Time Request Ubuntu Nginx - See Real Time Requests Introduction to Nginx on Ubuntu OS Nginx is a powerful, open source web server software that runs in the background of an Ubuntu…
- How To Install Nginx On Ubuntu 18.04 How To Install Nginx on Ubuntu 18.04 Introduction Nginx is a popular open-source web server and reverse proxy software that’s used by millions of websites. It’s the most widely used…
- Ubuntu 18.04 Letsencrypt Nginx Ubuntu 18.04 Letsencrypt Nginx What is Ubuntu and Why is it Used for Nginx? Ubuntu is a Linux-based operating system designed for open-source use. It is regularly updated, secure, and…