CentOS 7 配置wordpress(HTTP)
实验环境
服务端: 一台CentOS 7桌面版,IP地址:192.168.10.1/24,DNS:192.168.10.1,关闭防火墙和子系统
客户端: 一台CentOS 7桌面版,IP地址:192.168.10.2/24,DNS:192.168.10.1,关闭防火墙和子系统
服务端配置
DNS配置
nslookup www.hb.com #解析正向地址
nslookup 192.168.10.1 #解析反向地址

安装php软件包
yum install php php-mysql -y #安装php和php-mysql数据库连接工具

安装mysql数据库
yum install mariadb-server -y #安装数据库服务

将数据库服务加入到开机自启
systemctl enable mariadb #将服务加入到开机自启
systemctl restart mariadb #重启mariadb数据库服务


创建数据库
[root@localhost ~]# mysql #进入数据库
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database wordpress; #创建wordpress数据库
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on wordpress.* to 'wordpress'@'localhost' identified by 'Skills39!'; #创建数据库连接用户,wordpress代表数据库,*代表数据库中的表,localhost也可以是远端的,可以用远端的IP地址,域名或者主机名代替或者百分号
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec) #刷新管理用户让其数据库生效
MariaDB [(none)]> exit #退出数据库
Bye

重启数据库服务
systemctl restart mariadb #重启数据库

wordpress配置
上传wordpress安装包


上传成功

创建存储wordpress的文件
mkdir /1

解压wordpress压缩包到/1下
tar -zxvf wordpress-4.9.4-zh_CN.tar.gz -C /1/

解压成功

配置wordpress连接mysql
cd /1/wordpress #切换到wordpress目录下
cp -a wp-config-sample.php wp-config.php #复制模板wp-config-sample.php wp-config.php
vim wp-config.php #编辑wp-config.php主配置文件
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress'); #填写wordpress数据库文件为wordpress
/** MySQL数据库用户名 */
define('DB_USER', 'wordpress'); #填写mysql数据库用户名为wordpress
/** MySQL数据库密码 */
define('DB_PASSWORD', 'Skills39!'); #填写mysql数据库用户密码为Skills39!
/** MySQL主机 */
define('DB_HOST', 'localhost'); #因为是一台服务器,可以写本地连接和访问
/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8'); #默认是utf-8编码
/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');

http配置
yum install httpd -y #安装httpd服务

复制模板文件
find / | grep vhosts
cp -a /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf.d/vhosts.conf

编辑主配置文件允许读取根目录和index.php文件
vim /etc/httpd/conf/httpd.conf
102 <Directory />
103 AllowOverride none
104 Require all granted #允许读取根目录
105 </Directory>

163 <IfModule dir_module>
164 DirectoryIndex index.html index.php #添加index.php文件
165 </IfModule>

编辑虚拟配置文件
vim /etc/httpd/conf.d/vhosts.conf
<VirtualHost *:80>
DocumentRoot "/1/wordpress"
ServerName www.hb.com
</VirtualHost>

重启httpd服务
systemctl restart httpd #重启httpd服务
systemctl status httpd #查看httpd服务状态

客户端测试
打开浏览器访问http://www.hb.com

安装wordpress站点

点击登录

账户名称:wordpress
账户密码:wordpress

登录后台成功

扩展知识点
在wordpress里面发布一篇自定义文章
发布第一篇文章

文章标题设置为hello,wlgczhywsx
文章内容:Always believe that beautiful things are about tohappen

点击发布

发布成功

新建一个网站访问http://www.hb.com

往下滑,找到hello,wlgczhywsx

访问文章成功
