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:
- Docker Install Nginx Mysql Php Docker Install Nginx Mysql Php What is Docker? Docker is an open-source platform for automating the deployment of applications as lightweight, portable, and self-sufficient containers. It bundles applications and all…
- Install Wordpress On Ubuntu Vps On Nginx Install Wordpress On Ubuntu VPS On Nginx What is WordPress? WordPress is an open-source, content management system (CMS) top-tier overall that is used to create powerful online presence. It powers…
- 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…
- 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…
- 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…
- 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…
- 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…
- Install Nginx Passenger Ubuntu 16.04 Install Nginx Passenger Ubuntu 16.04 Installing Nginx On Ubuntu 16.04 Nginx is an open source web server that can be used to create web and application servers. It is a…
- 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…
- Install Laravel Ubuntu 16.04 With Nginx Web Server Install Laravel Ubuntu 16.04 With Nginx Web Server Introduction Laravel is one of the most popular expressive, elegant, and robust PHP frameworks available today. It is an open source framework…
- Check Ok For Nginx Confgiruration On Ubuntu Check OK for Nginx Confgiruation On Ubuntu What is Nginx? Nginx is an open-source web server that is renowned for its scalability and agility. It was originally designed as an…
- Install Nginx And Php On Ubuntu Install Nginx And Php On Ubuntu A Comprehensive Tutorial to Install Nginx And Php On Ubuntu Nginx and PHP are two of the most popular web server and scripting language…
- Cara Install Nginx Ubuntu 14.04 Cara Install Nginx Ubuntu 14.04 Step 1: Update the Software Packages The first step in installing Nginx is to update the software packages in Ubuntu 14.04. This can be done…
- 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…
- Install Webmin Plugin Nginx Ubuntu Install Webmin Plugin Nginx Ubuntu What is Nginx? Nginx is a web server that runs on the Linux operating system. It is a popular web server software and can handle…
- 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…
- 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…
- 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…
- Install Nginx Latest Version Ubuntu Install Nginx Latest Version Ubuntu Introduction to Nginx Nginx is a powerful and widely used web server software that is used to power web sites. It is free, open-source, and…
- 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…
- Error Install Nginx On Ubuntu Error Install Nginx On Ubuntu What is Nginx? Nginx is a web server software used to host web applications. It is open source software developed by the open source community.…
- 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.…
- 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…
- Laravel Nginx Config Ubuntu 18 Laravel Nginx Config Ubuntu 18 Introduction Laravel is a powerful web-based MVC (Model-View-Controller) framework used by developers to create web applications, websites and APIs. It is based on the popular…
- 502 Bad Gateway Nginx In Ubuntu 502 Bad Gateway Nginx In Ubuntu What Is A 502 Bad Gateway Error? A 502 Bad Gateway Error is an HTTP status code that is not able to connect to…
- 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…
- Linux Nginx Mysql Php Lemp Linux Nginx Mysql Php Lemp What is Linux, Nginx, MySQL, PHP (LEMP)? Linux, Nginx, MySQL, PHP (LEMP) is a software stack combination of Linux, Nginx, MySQL, and PHP, commonly referred…
- 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…
- 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…
- 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.…