# 系统
Linux huanghetest 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
1、安装LAMP或LEMP
# 更新系统包
sudo apt update
sudo apt upgrade
# 安装LAMP(Linux, Apache, MySQL, PHP)
# 或者安装LEMP(Linux, Nginx, MySQL, PHP)
# 我这里已经有Nginx和Mysql了,所以我这里只安装PHP扩展
sudo apt install php-fpm php-mysql php-xml php-gd php-mbstring php-zip
二、下载并安装WordPress
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
root@huanghetest:/var/www/wordpress# ls
index.php wp-activate.php wp-comments-post.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php
license.txt wp-admin wp-config-sample.php wp-includes wp-login.php wp-signup.php
readme.html wp-blog-header.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php
三、配置MySQL数据库
# 使用mysql-workbench创建一个库wordpressdb;
CREATE DATABASE wordpressdb;
# 配置数据库信息
cp wp-config-sample.php wp-config.php
vi wp-config.php
# 修改数据库的名称、账号、密码、HOST
define( 'DB_NAME', 'database_name_here' );
/** Database username */
define( 'DB_USER', 'username_here' );
/** Database password */
define( 'DB_PASSWORD', 'password_here' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
四、配置Nginx
# 将 your_domain_or_IP 按实际情况修改;
# 将/var/www/html 改为 /var/www/wordpress;
server {
listen 8881 ssl;
server_name your_domain_or_IP;
error_log /var/log/nginx-error.log info;
ssl_certificate /usr/local/nginx/cert/3682644__.pem;
ssl_certificate_key /usr/local/nginx/cert/3682644__.key;
ssl_session_timeout 8m;
root /var/www/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; # 根据你的PHP版本调整
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
#
mkdir snippets
chmod -R 777 snippets
cp /etc/nginx/snippets/fastcgi-php.conf /usr/local/nginx/conf/snippets
# 检查nginx是否有语法错误 sudo nginx -t
# 重启nginx /usr/local/nginx/sbin/nginx
sudo systemctl status php7.2-fpm.service
sudo systemctl enable php7.2-fpm.service
六、访问 your_domain_or_IP:8881

image.png