These are instructions for installing PHP7, MySQL 5.7 and Nginx 1.10 on Ubuntu 16.04.

Update All The Things

First run:

1
apt-get update

Install MySQL

1
apt-get -y install mysql-server

Check version using:

1
2
mysql --version
mysql  Ver 14.14 Distrib 5.7.17, for Linux (x86_64) using  EditLine wrapper

Install Nginx

1
apt-get -y install nginx

Check version using:

1
2
nginx -v
nginx version: nginx/1.10.0 (Ubuntu)

Install PHP-FPM

1
2
apt-get -y install php7.0 php7.0-fpm php7.0-mysql php7.0-curl php7.0-json php7.0-cli php7.0-common php7.0-xml
mkdir -p /run/php

Check version using:

1
2
3
4
5
php -v
PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.13-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologies

Configure Nginx

Change the config in /etc/nginx/sites-enabled/default to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    server_name     localhost;
        
    set $root_path '/var/www/html';

    root $root_path;
    index  index.php index.html index.htm;

    try_files $uri  $uri/   /index.php;

    access_log      /var/log/nginx/access.log;

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_split_path_info       ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_read_timeout 15;
    }
        
    location ~ /\.ht {
        deny all;
     }
}

Restart Services

Do:

1
2
3
service mysql restart
service nginx restart
service php7.0-fpm restart

Test Installation

You should see the PHP information page after running the following:

1
2
echo "<?php phpinfo(); ?>" > /var/www/html/index.php
curl http://localhost

Final One-shot script

You can run all the commands in one go. Paste the following in one file and run it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
apt-get update
apt-get -y install mysql-server
apt-get -y install nginx
apt-get -y install php7.0 php7.0-fpm php7.0-mysql php7.0-curl php7.0-json php7.0-cli php7.0-common php7.0-xml
mkdir -p /run/php
echo "
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    server_name     localhost;
        
    set \$root_path '/var/www/html';

    root \$root_path;
    index  index.php index.html index.htm;

    try_files \$uri  \$uri/   /index.php;

    access_log      /var/log/nginx/access.log;

    location ~ \.php$ {
            try_files \$uri =404;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_split_path_info       ^(.+\.php)(/.+)\$;
            fastcgi_param PATH_INFO       \$fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED \$document_root\$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_read_timeout 15;
    }
        
    location ~ /\.ht {
        deny all;
     }
} " > /etc/nginx/sites-enabled/default

echo "<?php phpinfo(); ?>" > /var/www/html/index.php

service mysql restart
service nginx restart
service php7.0-fpm restart

curl http://localhost

Thatโ€™s all, folks!