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:
- 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…
- 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 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…
- 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…
- Access To The Path Is Denied Nginx Ubuntu Access To The Path Is Denied Nginx Ubuntu What is the Problem? Access to the path is denied Nginx Ubuntu is an issue that can occur when running software that…
- 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…
- 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 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…
- Vps Webserver Nginx Php7 Mysql Vps Webserver Nginx Php7 Mysql What Is VPS Webserver? A VPS webserver is a Virtual Private Server (VPS) that has been configured to act as a web server. A VPS…
- 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.…
- Bash Install Nginx On Ubuntu How To Install Nginx On Ubuntu What is Nginx? Nginx is a web server that is gaining popularity in the world of web hosting. Nginx is an open source web…
- 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…
- 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…
- 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…
- 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…
- Remove Nginx Full Complete On Ubuntu 18 Remove Nginx Full Complete On Ubuntu 18 Uninstallating Nginx From Ubuntu Ubuntu is one of the most popular Linux-based operating systems, and it has a wide variety of programs available…
- 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…
- 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…
- Install Nginx Mysql Phpmyadmin Ubuntu Install Nginx Mysql Phpmyadmin Ubuntu 1. Introduction In today's tutorial, we will show you how to install Nginx, MySQL, and phpMyAdmin on Ubuntu 20.04. Nginx is an open source web…
- Freebsd Rc D Nginx Not Found Freebsd Rc D Nginx Not Found What is FreeBSD? FreeBSD is an open source, Unix-like operating system, developed by the computer scientists at the University of California, Berkeley. It is…
- 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…
- 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 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…
- 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,…
- 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…
- Nginx Always Displaying Default Page In Ubuntu Nginx Always Displaying Default Page In Ubuntu Introduction Ubuntu is one of the most popular Linux distributions and an immensely powerful and versatile operating system. It has a great package…
- 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.…
- 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…
- 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…
- Stop Nginx Ubuntu 16.04 Stop Nginx Ubuntu 16.04 What is Nginx? Nginx is a web server and reverse proxy software. It is open source and widely used on the web. It is used to…