Contents

Install Nginx and PHP-FPM on Linux Mint 19

Install Nginx

Download the Nginx signing key from Nginx official site, and them add it into system.

1
$ wget http://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Add Nginx repository to the system.

1
2
3
$ echo "deb [arch=amd64] http://nginx.org/packages/ubuntu/ bionic nginx" | sudo tee /etc/apt/sources.list.d/nginx.list

$ echo "deb-src [arch=amd64] http://nginx.org/packages/ubuntu/ bionic nginx" | sudo tee -a /etc/apt/sources.list.d/nginx.list

Update repository index.

1
$ sudo apt update

Install Nginx

1
$ sudo apt install -y nginx

Set Site’s Root DirectoryPermalink

1
2
3
4
5
$ cd /etc/nginx/sites-available
$ sudo vi default

-       root /var/www/html;
+       root /var/www/public;

Ownership and permissions for nginx local webserver

1
2
3
4
5
$ sudo vi /etc/nginx/nginx.conf

$ grep user /etc/nginx/nginx.conf
-	user www-data;
+	user dyiwu cosmos;

Install PHP-FPM

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation.

Use apt to install php-fpm

1
$ sudo apt install -y php-fpm php-mysql php-cli

Edit the respective php.ini depending on the PHP version you have installed on the system.

1
2
3
4
$ sudo vi /etc/php/7.2/fpm/php.ini

-	cgi.fix_pathinfo=1
+	cgi.fix_pathinfo=0

Edit the /etc/php/7.2/fpm/pool.d/www.conf file, change user, group, listen,listen.owner and listen.group.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ sudo vi /etc/php/7.2/fpm/pool.d/www.conf
-	user = www-data
-	group = www-data
+	user = dyiwu
+	group = cosmos
 
-	listen = 127.0.0.1:9000
+	listen = /run/php/php7.2-fpm.sock
 
-	listen.owner = www-data
-	listen.group = www-data
+	listen.owner = dyiwu
+	listen.group = cosmos

Fix for Nginx PID problem in Ubuntu 16.04

1
2
3
4
5
6
7
8
9
$ sudo systemctl stop nginx
$ sudo mkdir /etc/systemd/system/nginx.service.d

# build the file in root where no sudo is needed
$ printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > override.conf

$ sudo cp override.conf /etc/systemd/system/nginx.service.d/override.conf
$ sudo systemctl daemon-reload
$ sudo systemctl start nginx

Correct the permission of directory files.

1
2
$ sudo chown -R dyiwu:cosmos /var/www/public
$ ls -ld /var/www/public

Test Nginx

Restart nginx and php-fpm services.

1
2
3
4
5
6
7
$ sudo systemctl restart nginx
$ sudo systemctl status nginx
$ ps aux | grep nginx

$ sudo systemctl restart php7.2-fpm
$ sudo systemctl status php7.2-fpm
$ ps aux | grep php-fpm

Check the version of nginx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$ sudo nginx -v
nginx version: nginx/1.16.0
$ sudo nginx -V

# create the index.php page to test PHP.
$ cat /var/www/public/index.php
<?php
phpinfo();
?>

# Open a web browser to http://127.0.0.1/, the phpinfo() page should be shown out.

Deployment

Deploy the hugo pages to local public directory by rsync

1
2
3
4
5
$ cat rsync-local.sh 
#!/bin/bash
cd ~/Hugo/Sites/chaos
hugo
rsync -avh --delete --progress public/ /var/www/public/

Deploy the hugo pages to Raspberry Pi by rsync

1
2
3
4
5
$ cat rsync-raspberry.sh 
#!/bin/bash
cd ~/Hugo/Sites/chaos
hugo
rsync -avh --delete --progress public/ 192.168.1.164:/var/www/public/

Reference