Install Apache2
# Ubuntu/Debian 系统
sudo apt update && sudo apt upgrade -y
# 安装 Apache
sudo apt install apache2 -y
# 启动 Apache 服务
sudo systemctl start apache2
# 设置开机自启动
sudo systemctl enable apache2
# 检查 Apache 状态,确保服务正常运行
sudo systemctl status apache2BashInstall MySQL
# 安装 MariaDB 服务器和客户端
sudo apt install mysql-server mysql-client -y
# 启动 MariaDB 服务
sudo systemctl start mysql
# 设置开机自启动
sudo systemctl enable mysql
# 检查 MariaDB 状态
sudo systemctl status mysql
# 加固数据库安全
sudo mysql_secure_installationBashInstall PHP
# 安装 PHP 及 WordPress 必需的扩展(如 mysql、curl、gd 等)
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-xml php-mbstring php-zip -y
# 检查 PHP 版本,确保 ≥ 7.4
php -vBashInstall WordPress
# 进入 /tmp 目录(临时存放压缩包)
cd /tmp
# 下载 WordPress 最新版(官网链接)
wget https://wordpress.org/latest.tar.gz
# 解压压缩包(会生成 wordpress 文件夹)
tar -zxvf latest.tar.gz
# 将解压后的文件移动到 Apache 默认网站目录(/var/www/html/)
sudo mv wordpress /var/www/html/
# 设置目录所有者为 www-data(Apache 用户)
sudo chown -R www-data:www-data /var/www/html/wordpress/
# 设置目录权限(文件夹 755,文件 644,确保安全且可访问)
sudo chmod -R 755 /var/www/html/wordpress/BashCreate WordPress Database
CREATE DATABASE wordpress_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY '你的强密码';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;SQLConfigure Web Server
sudo bash -c "cat >/etc/apache2/sites-available/wordpress.conf" <<'EOF'
<VirtualHost *:80>
# 网站域名或服务器 IP(如无域名,直接填写服务器公网 IP)
ServerName yourdomain.com
ServerAlias www.yourdomain.com # 可选,域名别名
# WordPress 网站根目录(指向我们移动的 wordpress 文件夹)
DocumentRoot /var/www/html/wordpress
# 管理员邮箱,用于接收服务器错误通知
ServerAdmin admin@yourdomain.com
# 日志文件路径(方便调试)
ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
# 允许 .htaccess 文件覆盖 Apache 配置(用于 WordPress 固定链接)
<Directory /var/www/html/wordpress>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOF
sudo a2ensite wordpress.conf
sudo a2dissite 000-default.conf
sudo a2enmod rewrite
sudo systemctl restart apache2BashEnable SSL(https)
Generating ssl certificate file.
$ sudo certbot --apache -d meow.lostyu.qzz.io
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for meow.lostyu.qzz.io
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/meow.lostyu.qzz.io/fullchain.pem
Key is saved at: /etc/letsencrypt/live/meow.lostyu.qzz.io/privkey.pem
This certificate expires on 2026-11-02.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for meow.lostyu.qzz.io to /etc/apache2/sites-available/wordpress-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://meow.lostyu.qzz.io
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -BashChanging wordpress link.
mysql> use wordpress_db
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from wp_options where option_name in ('siteurl','home');
+-----------+-------------+------------------------------+----------+
| option_id | option_name | option_value | autoload |
+-----------+-------------+------------------------------+----------+
| 3 | home | http://meow.lostyu.qzz.io:80 | on |
| 2 | siteurl | http://meow.lostyu.qzz.io:80 | on |
+-----------+-------------+------------------------------+----------+
2 rows in set (0.00 sec)
mysql> update wp_options set option_value='https://meow.lostyu.qzz.io' where option_name in ('siteurl','home');
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
ByeSQLWordPress Debug
修改wp-config.php文件,添加如下参数,日志将输出到wp-content/debug.log
└─$ sudo vi wp-config.php
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );Bash如需关闭,则设置define( 'WP_DEBUG', false );
评论(0)
暂无评论