Environments:
Server:Ubuntu 22.04.3 LTS
Nginx:1.18.0
PHP:8.1.2
MySQL:8.0.40
Step 1:创建wordpress数据库和对应权限的数据库用户
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'your_password_here';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
flush privileges;
Step 2:下载安装WordPress
mkdir -p /var/www/html/runs.wang
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
mv /tmp/wordpress/* /var/www/html/runs.wang/
chown -R www-data: /var/www/html/runs.wang
Step 3:设置Nginx
cd /etc/nginx/sites-available
cp default default.back
vim default
server {
root /var/www/html/runs.wang;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name runs.wang; # managed by Certbot
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/runs.wang/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/runs.wang/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = runs.wang) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name runs.wang;
return 404; # managed by Certbot
}
Step 4:重启Nginx
nginx -t
systemctl restart nginx
Step 5:打开浏览器输入地址runs.wang根据之前创建的数据库信息初始化页面即可
References:
《WordPress Nginx: Everything You Need to Know About Installing WordPress on Ubuntu》
《How to install and configure WordPress with NGINX》