准备:
① Centos7.6一台,我用的是阿里云服务器
② wordpress安装文件
链接:https://pan.baidu.com/s/1G5I9AGD-y8LnYGVk1xyX2A 提取码:lpcq
③ 升级yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
④ 关闭防火墙,关闭selinux
⑤ 云服务器安全组放通端口,包括80 3306等相关端口
一、安装mariadb,创建WordPress后台数据库
# 安装mariadb
yum install mariadb mariadb-server
# 启动
systemctl start mariadb
# 初始化数据库,用户名root,密码123456
mysql_secure_installation
# 登录
mysql -uroot -p
# 登录数据库后创建(WordPress)的数据库,数据命名为wenlong
create database wenlong;
# 授权可以远程访问,用户名root,密码123456
grant all on *.* to root@'%' identified by '123456';
#刷新权限
flush privileges;
二、安装php70w、php-fpm等php组件
# 安装php70w和相关组件
yum -y install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64
# 安装fpm、opcache组件
yum -y install php70w-fpm php70w-opcache
# 启动fpm
systemctl start php-fpm
# 查看php的版本
php -v
# 查看9000(fpm)、3306(mysql)、80(httpd)端口是否正常
netstat -antp
三、安装nginx
3.1安装nginx
# 安装nginx
yum install nginx
# 启动
systemctl start nginx
3.2编辑nginx配置文件,server节点内添加配置,重启nginx
vim /etc/nginx/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 重启nginx
systemctl restart nginx
# 查看监控端口情况3306 9000 80
netstat -anpt
3.3在站点根目录新建index.php首页
# 编辑index.php,插入下边代码并保存退出
vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
3.4浏览器输入http://你的ip/,查看nginx和php安装是否成功
四、安装WordPress
# 上传WordPress安装文件到云服务器,解压
tar -zxvf wordpress-5.4.2.tar.gz
# 将解压后的文件移动到nginx站点根目录
mv wordpress /usr/share/nginx/html/
# 进入到WordPress,修改配置文件
cd /usr/share/nginx/html/wordpress/
# 重命名配置文件,让nginx能够识别
mv wp-config-sample.php wp-config.php
# 配置后台数据库对应的库、用户名和密码
vim wp-config.php
# 后台数据库名
define( 'DB_NAME', 'wenlong' );
/**数据库用户名 */
define( 'DB_USER', 'root' );
/** 数据库密码 */
define( 'DB_PASSWORD', '123456' );
五、初始化WordPress,首先重启nginx
# 修改nginx配置文件,修改WordPress后都应该重启nginx
# 重启nginx
systemctl restart nginx
浏览器输入网页安装地址:http://你的ip地址/wordpress/wp-admin/install.php
填入安装信息,点击按钮install WordPress
输入上边注册的用户、密码登录
附录:如果防火墙、selinux开启,修改防火墙规则,selinux上下文一般不用改
# 防火墙放开80端口,nginx默认使用80
# --permanent重启后仍然有效
firewall-cmd --add-port=80/tcp --permanent
# 也可放通mysql默认的端口3306
firewall-cmd --add-port=3306/tcp --permanent
# 重新加载防火墙配置规则
firewall-cmd --reload
云服务器安全组放通80、3306等相应端口