准备工作
-
购买服务器:注册成功后,点击部署,配置自选
-
购买域名:域名备案等操作
-
域名映射
软件配置(latest version):
- Nginx
- MySQL
- MariaDB
- PHP
- wordpress
- Center-os8
配置步骤
连接服务器
关闭防火墙及SELinux
systemctl disable firewalld
nano /etc/selinux/config
修改配置文件:
SELINUX=disabled
配置nginx
- 安装
dnf install nginx -y
- 启动nginx服务,并设置开机自启动
systemctl start nginx
systemctl enable nginx
安装MariaDB数据库
- 安装
dnf install mariadb-server -y
- 启动MariaDB服务,并设置开机自启动
systemctl start mariadb
systemctl enable mariadb
- 设置密码
mysql_secure_installation
设置过程中提问:
Enter current password for root (enter for none): #服务器中的密码
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
安装PHP
- 安装
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
- 安装依赖及拓展
dnf module reset php
dnf module install php:remi-8.0 -y
dnf install php php-mysqlnd php-fpm php-opcache php-curl php-json php-gd php-xml php-mbstring php-zip -y
修改PHP配置文件
- 进入php配置文件
nano /etc/php-fpm.d/www.conf
- 修改内容
user = nginx
group = nginx
- 保存并重启php-fpm
systemctl start php-fpm
systemctl enable php-fpm
创建wordpress数据库
mysql -u root -p
CREATE DATABASE wordpressdb;
CREATE USER `wordpressuser`@`localhost` IDENTIFIED BY 'securepassword';
GRANT ALL ON wordpressdb.* TO `wordpressuser`@`localhost`;
FLUSH PRIVILEGES;
EXIT;
下载安装wordpress
yourdomain.com为映射好的个人域名,不能输错
cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
mv wordpress yourdomain.com
chown -R nginx:nginx /var/www/html/yourdomain.com
为 WordPress 创建 Nginx 虚拟主机
- 进入nginx配置文件
nano /etc/nginx/conf.d/yourdomain.conf
- 添加内容
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/html/yourdomain.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
- 重启ngnix服务
systemctl restart nginx
访问wordpress网站:https://yourdomain.com,根据提示填入注册信息
配置网站样式、发布内容等系列操作
参考:
How to Install WordPress on CentOS 8 (Step by Step) Tutorial