Install PHP 7, NGINX & MySQL on Ubuntu
The latest major release of PHP version 7.0 has been released with lots of speed optimizations and security. So you should try this version for your development. This tutorial will help you to install PHP 7.0, Nginx, & MySQL 5.6 on Ubuntu 15.10, 14.04 and 12.04 LTS release.
Step 1 – Install PHP 7 with PHP-FPM
First install python-software-properties package on your system which provides add-apt-repository command then use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install it.
$ sudo apt-get install python-software-properties $ sudo add-apt-repository ppa:ondrej/php $ sudo apt-get update $ sudo apt-get install -y php7.0 php7.0-fpm
Step 2 — Install Nginx
First we will install Latest Nginx web server on our system. Use the following commands to add PPA for installing latest Nginx version on your Ubuntu 14.04 (Trusty).
$ echo "deb http://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx" >> /etc/apt/sources.list $ echo "deb-src http://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx" >> /etc/apt/sources.list
and use the following commands to install Nginx web server.
$ curl http://nginx.org/keys/nginx_signing.key | apt-key add - $ sudo apt-get update $ sudo apt-get install nginx
Step 3 — Install MySQL 5.6
Use the following commands to install or upgrade MySQL 5.6 on your Ubuntu systems. At the last update of this tutorial MySQL 5.6.27 is latest available MySQL version in series of MySQL 5.6.X.
$ sudo add-apt-repository -y ppa:ondrej/mysql-5.6 $ sudo apt-get update $ sudo apt-get install mysql-server-5.6
Step 4 — Install Other Requirements
You may also need to install modules like PHP7-MySQL, etc based on your application requirements. Use the following command to find our available php 7 modules.
$ sudo apt-cache search php7-*
Above command will list all available PHP7 modules for installation, Let’s begin installation of modules.
$ sudo apt-get install php7.0-mysql php7.0-curl php7.0-json
Step 5 — Configure PHP-FPM
PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features.
$ sudo nano /etc/php/7.0/fpm/php.ini
un-comment cgi.fix_pathinfo=1 line and set value to 0.
cgi.fix_pathinfo=0
Now set the listen parameter in /etc/php/7.0/fpm/pool.d/www.conf configuration file. Here you can use php7.0-fpm socket to work or start php7.0-fpm service on specific port. We are going to use it as service .
$ sudo nano /etc/php/7.0/fpm/pool.d/www.conf
Now make changes in configuration file as below. Commend listen with socket file and enable it as service
#listen = /run/php/php7.0-fpm.sock
listen = 127.0.0.1:9000
Step 6 — Configure Nginx VirtualHost
Finally do the configuration of Nginx virtualhost. For this example we are editing default configuration file.
$ sudo nano /etc/nginx/conf.d/default.conf
and make changes as below.
server {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
You have to do the same changes in all VirtualHosts configured.
Step 7 – Restart Services
After installing all services on your system, start all required services.
$ sudo service nginx restart $ sudo service php7.0-fpm restart
Step 8 – Open Access in Firewall
If you are using iptables, Use following commands to open port 80 for public access of webserver.
Iptables Users:
$ sudo iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
UFW Users:
$ sudo ufw allow 80/tcp
Step 9 – Verify Setup
Finally verify installation of PHP 7 with NGINX. Let’s create a file info.php on website document root using following content.
<?php phpinfo(); ?>
Now browse this file in web browser. It will so all the details about version’s and installation.
0 comments:
Post a Comment