本次环境:
1、DebianServer 一台
2、SSH工具(如:Termius)
更新安装工具包
(以下安装流程注意权限 sudo)
apt update && apt upgrade
apt install vim wget unzip
安装Nginx
apt install nginx
systemctl start nginx
systemctl enable nginx #开机自启
systemctl status nginx #查看有无报错
安装PHP
apt install php php-curl php-fpm php-bcmath php-gd php-soap php-zip php-curl php-mbstring php-mysqlnd php-gd php-xml php-intl php-zip
php -v #检查版本 根据2024-7-5 官网 最低版本需要大于7.4
配置PHP (可选 根据自己服务器配置决定)
vim /etc/php/8.2/fpm/php.ini #路径自查 根据PHP版本变化
修改如下参数
max_execution_time = 200
memory_limit = 256M
post_max_size = 128M
upload_max_filesize = 128M
systemctl restart php8.2-fpm #重启服务 生效配置
安装MariaDB
apt install mariadb-server mariadb-client
systemctl start mariadb
systemctl enable mariadb #开机自启
systemctl status mariadb #确认状态
mysql_secure_installation #根据需求配置
systemctl restart mariadb #重启确保启动
配置数据库
mysql -u root -p #这里的密码为先前的配置中设置
进入数据库后
#创建名为wordpress_db的数据库
> CREATE DATABASE wordpress_db;
#创建数据库用户名<wordpress>以及密码<password> 并下发权限
> GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress'@'localhost' IDENTIFIED BY 'password';
#刷新生效
> FLUSH PRIVILEGES;
#退出
> EXIT
下载WordPress官方包
#中文版
wget https://cn.wordpress.org/latest-zh_CN.zip
#英文版
wget https://wordpress.org/latest.zip
#解压包
unzip latest-zh_CN.zip -d /var/www/html/
cd /var/www/html/wordpress
#使用默认配置
cp wp-config-sample.php wp-config.php
#修改符合自己的配置
vim wp-config.php
define( 'DB_NAME', '你的数据库名称' );
define( 'DB_USER', '数据库用户名' );
define( 'DB_PASSWORD', '数据库密码' );
define( 'DB_HOST', 'localhost' );
#修改所有者
chown -R www-data:www-data /var/www/html/wordpress/
配置Nginx
#若要公网访问 则需要公网ip
#若觉得ip访问太丑 就购买域名
vim /etc/nginx/conf.d/wordpress.conf
以下为nginx config 范例 (80端口 hhtp)
server {
listen 80;
server_name your-domain.com www.your-domain.com;
root /var/www/html/wordpress;
index index.php;
access_log /var/log/nginx/your-domain.com.access.log;
error_log /var/log/nginx/your-domain.com.error.log;
client_max_body_size 80M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
include fastcgi_params;
fastcgi_intercept_errors on;
}
}
配置完nginx后 重启服务
systemctl restart nginx
其他命令(可选)
nginx -t #测试 config能否通过自测
nginx -s reload #热生效配置
我遇到的小问题:
1、输入域名后进入了默认的 Apache2 Debian Default Page
#删除debian12自带的index.html
rm /var/www/html/index.html
2、输入域名后进入了默认的nginx页面
请自行修改 nginx config 确保监听的域名是否填写正确