ติดตั้ง phpMyAdmin ให้ Nginx บน Ubuntu 18.04

1.Installing phpMyAdmin

$ sudo apt update
$ sudo apt install phpmyadmin

During the installation process, you will be prompted to choose the web server (either Apache or Lighttpd) to configure. Because we are using Nginx as a web server, we shouldn’t make a choice here. Press tab and then OK to advance to the next step.

Next, you’ll be prompted whether to use dbconfig-common for configuring the application database. Select Yes. This will set up the internal database and administrative user for phpMyAdmin. You will be asked to define a new password for the phpmyadmin MySQL user. You can also leave it blank and let phpMyAdmin randomly create a password.

ถ้าจะ recofig ก็

sudo dpkg-reconfigure phpmyadmin

สร้าง link

$ sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
https://server_domain_or_IP/phpmyadmin

แต่น่าจะติด 403 Forbidden

ให้ เพิ่ม index.php ในไฟล์ /etc/nginx/sites-available/example.com

$ sudo nano /etc/nginx/sites-available/example.com
server {
        listen 80;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html index.php;
        server_name example.com;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

ทีนี้จะเข้าได้ละ

ติดตั้ง Nginx บน Ubuntu 18.04

1.Installing Nginx

$ sudo apt update
$ sudo apt install nginx

2.Adjusting the Firewall

$ sudo ufw app list
Available applications:
  CUPS
  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  • Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)
  • Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)
$ sudo ufw allow 'Nginx Full'
$ sudo ufw allow 'Nginx HTTP'
$ sudo ufw status
Status: inactive
$ sudo ufw enable
$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
Nginx Full                 ALLOW       Anywhere
Nginx HTTP                 ALLOW       Anywhere
Nginx Full (v6)            ALLOW       Anywhere (v6)
Nginx HTTP (v6)            ALLOW       Anywhere (v6)

เปิดพอร์ทแบบกำหนดไปเลย

$ sudo ufw allow 22/tcp
$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp

3.Checking your Web Server

$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-02-06 14:26:15 +07; 33min ago
     Docs: man:nginx(8)
 Main PID: 5720 (nginx)
    Tasks: 5 (limit: 4915)
   CGroup: /system.slice/nginx.service
           ├─5720 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           ├─5721 nginx: worker process
           ├─5722 nginx: worker process
           ├─5723 nginx: worker process
           └─5724 nginx: worker process