Step 1: Enable PPA
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Step 2: Install PHP 7.1
sudo apt-get install php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm
Step 5: Configure php.ini file
php --ini |grep Loaded
Loaded Configuration File: /etc/php/7.1/cli/php.ini
Edit the file using your favorite text editor:
sudo nano /etc/php/7.1/cli/php.ini
Make the following changes:
cgi.fix_pathinfo=0
Then, restart the PHP-FPM service:
sudo systemctl restart php7.1-fpm.service
Step 6: Install Nginx on Ubuntu 16.04
sudo apt-get install nginx
Create Nginx virtual server block for your domain name:
sudo nano /etc/nginx/sites-available/example.com
Paste the following content:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
Of course, you should replace example.com with your actual domain name. Save and close the file. To enable the server block in Nginx you need to create a symbolic link to site-enabled
. Use the following command to create a symbolic link:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
Check if there are errors with the configuration:
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If the syntax is OK and there are no errors you can restart Nginx.
sudo systemctl restart nginx.service
Enable Nginx and PHP-FPM on system boot:
sudo systemctl enable nginx.service
sudo systemctl enable php7.1-fpm.service