安装Nginx
#添加nginx-repo
vi /etc/yum.repos.d/nginx.repo
#编辑源
[nginx]
name = nginx repo
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck = 0
enabled = 1
#保存退出
:wq
#安装Nginx
yum install -y nginx
#修改配置文件
vim /etc/nginx/conf.d/default.conf
#编辑Nginx(取消IPV6监听并联动PHP)
server {
listen 80;
root /usr/share/nginx/html;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
#
location / {
index index.php index.html index.htm;
}
#error_page 404 /404.html;
#redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#保存退出
:wq
#启动Nginx
systemctl start nginx
#设置开机启动
systemctl enable nginx
#浏览器访问本机IP,如页面显示"Welcome to nginx"则代表nginx运行正常
安装MariaDB数据库
#查询本机是否有旧版MariaDB
rpm -qa | grep -i mariadb
#存在mariadb的话将其全部卸载
yum -y remove 包名
#添加mariadb-repo
vi /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.4 CentOS repository list - created 2019-11-05 11:56 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = https://mirrors.cloud.tencent.com/mariadb/yum/10.4/centos7-amd64
gpgkey=https://mirrors.cloud.tencent.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
#保存退出
:wq
#安装MariaDB
yum -y install MariaDB-client MariaDB-server
#启动MariaDB
systemctl start mariadb
#设置MariaDB开机启动
systemctl enable mariadb
#验证MariaDB
mysql
#如显示"Welcome to the MariaDB monitor"则表示MariaDB运行正常,此时可退出数据库
\q
安装PHP
#更新yum中PHP的软件源
rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
#更新yum中PHP的软件源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#安装依赖
yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64
#启动PHP-FPM服务
systemctl start php-fpm
#设置PHP-FPM开机启动
systemctl enable php-fpm
#生成PHP示例文件
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php
#重启Nginx
systemctl restart nginx
#访问本机IP,如显示"PHP Version"则PHP正常运行
安装WordPress
配置MariaDB
#进入数据库
mysql
#创建数据库
CREATE DATABASE wordpress;
#创建用户
CREATE USER 'user'@'localhost' IDENTIFIED BY '123456';
#给用户赋予全部权限
GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost' IDENTIFIED BY '123456';
#设置root用户密码
ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD('输入您的密码');
#使配置立即生效
FLUSH PRIVILEGES;
#退出数据库
\q
配置WordPress
#删除测试时创建的PHP文件
rm -rf /usr/share/nginx/html/index.php
#进入Nginx网站目录
cd /usr/share/nginx/html
#下载WordPress
wget https://cn.wordpress.org/wordpress-5.0.4-zh_CN.tar.gz
#解压WordPress文件
tar zxvf wordpress-5.0.4-zh_CN.tar.gz
#复制示例配置文件
cd /usr/share/nginx/html/wordpress
cp wp-config-sample.php wp-config.php
#修改WordPress配置文件
vim wp-config.php
#编辑配置
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'user');
/** MySQL database password */
define('DB_PASSWORD', '123456');
/** MySQL hostname */
define('DB_HOST', 'localhost');
#保存退出
:wq
#浏览器访问本机IP+/wordpress,如显示"WordPress五分钟安装程序",则WordPress安装成功
恭喜,现在可以开始写博客了
#查询防火墙状态
systemctl status firewalld.service
#临时关闭防火墙
systemctl stop firewalld.service
#永久关闭防火墙
systemctl disable firewalld.service
#开放MariaDB端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
#开放一段区间内的端口
firewall-cmd --zone=public --add-port=40000-49999/tcp --permanent
#重启防火墙立即生效
firewall-cmd --reload
#修改mariadb密码
mysqladmin -uroot -poldpassword password newpassword
#查看mariadb用户
SELECT User, Host, Password FROM mysql.user;
#mariadb开启远程连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
#刷新
flush privileges;
#补充,如果还无法访问,注释掉本地监听绑定
# bind-address = 127.0.0.1
#跳过wordpress要求的ftp操作
#编辑wp-config.php
#在if ( !defined('ABSPATH') )define('ABSPATH', dirname(__FILE__) . '/');
#新建tmp文件夹
cd ./html/wordpress/wp-content
mkdir tmp
#后面添加以下代码
define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp');
define("FS_METHOD", "direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);
#将主题和插件父目录设置777权限
chmod -R 777 wordpress/wp-content