ติดตั้ง Wordpress โดยใช้ NGINX บน Debian
2 min read

ติดตั้ง Wordpress โดยใช้ NGINX บน Debian

สิ่งที่ต้องติดตั้ง เพื่อให้ Wordpress ทำงาน

  • webservice แล้วแต่ว่าจะใช้ nginx หรือ apache
  • php
  • mariadb
  • ตัวเว็บ Wordpress

Step 1 Install Nginx

apt install nginx

Step 2 Install php for wordpress

apt install php7.3-{fpm,common,mbstring,xmlrpc,soap,gd,xml,intl,mysql,cli,ldap,zip,curl}

Step 3 Install Mariadb (Debian 10)

apt-get install software-properties-common dirmngr -y
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
add-apt-repository 'deb [arch=amd64] http://mirror.kku.ac.th/mariadb/repo/10.4/debian buster main'
apt update
apt install mariadb-server
mysql_secure_installation

เวอร์ชั่นอื่นหรือ OS อื่นๆ ดูได้จาก

https://downloads.mariadb.org/mariadb/repositories/#mirror=yamagata-university

Step 3 Download Wordpress and install

wget https://wordpress.org/latest.zip

unzip /path/to/latest.zip

กำหนดสิทธิ์ให้ไฟล์ wordpress

chown -R www-data:www-data /path/to/wordpress

Step 4 Config Mariadb

mysql -u root

create database wordpress_db_name character set 'utf8mb4' collate 'utf8mb4_general_ci';
GRANT ALL PRIVILEGES ON wordpress_db_name.* TO wordpress_user@'ip-wordpress' IDENTIFIED BY 'Password-for-user';

ip-wordpress คือ ip เครื่องที่ติดตั้ง wordpress สามารถใส่เป็น localhost หรือ % คือทุก IP

Step 5 Config php-fpm for Nginx

vim /etc/php/7.3/fpm/pool.d/php-wordpress.conf

[php-wordpress]

listen = /var/run/php-wordpress.sock
listen.backlog = 500000
rlimit_files = 500000
rlimit_core = 0

; Unix user/group of processes
user = www-data
group = www-data

listen.owner = www-data
listen.group = www-data

pm = ondemand
pm.max_children = 200
pm.process_idle_timeout = 10s
pm.max_requests = 2000

; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

Step 6 Config Nginx

vim /etc/nginx/conf.d/domain.conf

server {
listen 80;
server_name domain.com;
root /path/to/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-wordpress.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
}

Test Config Nginx

nginx -t

Restart Nginx และ PHP

systemctl restart php7.3-fpm.service
systemctl restart nginx