在CentOS7使用yum安装httpd、mariadb以及php。并且部署phpMyAdmin、wordpress、Discuz这三个服务。
虚拟主机名称为:
pma.lcs.com,安装phpMyAdmin
wp.lcs.com,安装wordpress
dz.lcs.com,安装Discuz
httpd、mariadb服务器主机IP地址为172.16.125.128,DNS服务器的IP地址为172.16.125.125,用于测试的主机IP地址为172.16.125.129。
安装详细步骤:
第一步:安装httpd;
[[email protected] pma]# yum install httpd
第二步:安装mariadb;
[[email protected] pma]# yum install mariadb-server mariadb
第三步:安装php以及php-mysql;
[[email protected] pma]# yum install php php-mysql
第四步:安装完成之后,启动各服务,并进行测试。
[[email protected] pma]# systemctl restart httpd.service [[email protected] pma]# systemctl restart mariadb.service
进行服务的测试:
编辑/etc/httpd/conf/httpd.conf配置文件,加入如下内容:
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps DirectoryIndex index.php index.html
在/var/www/html/目录下创建一个index.php文件,内容如下:
<?php $link = mysql_connect("localhost","root",""); if ($link) echo "OK"; else echo "Failure"; mysql_close(); phpinfo(); ?>
测试结果如下图:
创建虚拟主机:
1、为安装phpMyAdmin创建虚拟主机,主机名称为pma.lcs.com。
(1)首先注释掉中心主机(在/etc/httpd/conf/httpd.conf文件中);
注释掉这一行DocumentRoot "/var/www/html";
(2)在/etc/httpd/conf.d/此目录下创建虚拟主机的配置文件vhosts.conf。
<VirtualHost 172.16.125.128:80> DocumentRoot /web/vhosts/pma ServerName pma.lcs.com ErrorLog /var/log/httpd/pmalog.err CustomLog /var/log/httpd/pmalog.access common <Directory "/web/vhosts/pma"> OPtions None Allowoverride None Require all denied Require ip 172.16.0.0/255.255.0.0 </Directory> </VirtualHost>
(3)在DNS服务器主机上的正向解析库文件中添加A记录:
pma.lcs.com. IN A 172.16.125.128
在DNS服务器主机的/etc/resolv.conf配置文件中添加nameserver 172.16.125.125。
在测试主机的/etc/sysconfig/network-scripts/ifcfg-eth0的网络配置文件中添加dns服务器的指向地址。
DNS1=172.16.125.125
测试虚拟主机能否被正确解析:
(4)配置本地yum源,安装php-mbstring这一软件包。
[[email protected] pma]# yum install php-mbstring
(5)给mariadb的root用户设置登录密码
MariaDB [(none)]> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘linux‘); MariaDB [(none)]> SET PASSWORD FOR ‘root‘@‘127.0.0.1‘ = PASSWORD(‘linux‘);
(6)下载PhpMyAdmin安装包,进行解压,并复制到站点目录下。
[[email protected] pma]# unzip phpMyAdmin-4.4.5-all-languages.zip [[email protected] pma]# cp -a phpMyAdmin-4.4.5-all-languages /web/vhosts/pma/pma
(7)进行测试,如下图所示。
2、为wordpress配置虚拟主机。
(1)在在/etc/httpd/conf.d/此目录下虚拟主机的配置文件vhosts.conf中添加如下内容:
<VirtualHost 172.16.125.128:80> DocumentRoot /web/vhosts/wp ServerName wp.lcs.com ErrorLog /var/log/httpd/wplog.err CustomLog /var/log/httpd/wp.access common <Directory "/web/vhosts/wp"> Options None AllowOverride None Require all denied Require ip 172.16.0.0/16 </Directory> </VirtualHost>
(2)在DNS服务器的正向解析库文件中添加A记录:
wp.lcs.com. IN A 172.16.125.128
(3)测试虚拟主机wp.lcs.com能否被正确解析:
(4)搭建wordpress。
[[email protected] ~]# unzip wordpress-4.3.1-zh_CN.zip [[email protected] ~]# cp -a wordpress /web/vhosts/wp/wp [[email protected] wp]# pwd /web/vhosts/wp/wp [[email protected] wp]# mv wp-config-sample.php wp-config.php [[email protected] wp]# vim wp-config.php
在wp-config.php配置文件中修改如下内容:
define(‘DB_NAME‘, ‘wpdb‘); /** MySQL数据库用户名 */ define(‘DB_USER‘, ‘wpuser‘); /** MySQL数据库密码 */ define(‘DB_PASSWORD‘, ‘wpuser‘);
(5)创建上图所示的数据库,以及相对应的用户名和密码,为用户wpuser授权对数据库wpdb具有全部权限。
MariaDB [(none)]> create database wpdb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> CREATE USER ‘wpuser‘@‘localhost‘ IDENTIFIED BY ‘wpuser‘;Query OK, 0 rows affected (0.03 sec) MariaDB [(none)]> CREATE USER ‘wpuser‘@‘l27.0.0.1‘ IDENTIFIED BY ‘wpuser‘;Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘wpuser‘@‘localhost‘; Query OK, 0 rows affected (0.02 sec) MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘wpuser‘@‘127.0.0.1‘; Query OK, 0 rows affected (0.01 sec)
通过以上步骤,进行测试。在第一次登录该地址时,需要进行安装才可以。
3、为Discuz配置虚拟主机。
(1)在在/etc/httpd/conf.d/此目录下虚拟主机的配置文件vhosts.conf中添加如下内容:
<VirtualHost 172.16.125.128:80> DocumentRoot "/web/vhosts/dz" ServerName dz.lcs.com ErrorLog /var/log/httpd/dzlog.err CustomLog /var/log/httpd/dz.access common <Directory "/web/vhosts/dz"> Options None AllowOverride None Require all denied Require ip 172.16.0.0/16 </Directory> </VirtualHost>
(2)在DNS服务器的正向解析库文件中添加A记录:
dz.lcs.com. IN A 172.16.125.128
测试,查看虚拟主机名能否被正确解析:
(3)下载解压Discuz_X3.2_TC_UTF8.zip,会出现三个文件readme、upload、utility。将upload复制到/web/vhosts/dz/dz下。
[[email protected] ~]# unzip Discuz_X3.2_TC_UTF8.zip [[email protected] ~]# ls [[email protected] ~]# cp -a upload /web/vhosts/dz/dz
修改/web/vhosts/dz/dz这个文件夹下文件的权限。
[[email protected] dz]# pwd /web/vhosts/dz [[email protected] dz]# chmod -R 777 dz/*
(4)开始安装discuz并且创建相关数据库。
创建所需要的数据库:
MariaDB [(none)]> CREATE DATABASE forumdb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> CREATE USER ‘forumuser‘@‘localhost‘ IDENTIFIED BY ‘forumuser‘; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> CREATE USER ‘forumuser‘@‘127.0.0.1‘ IDENTIFIED BY ‘forumuser‘; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL ON forumdb.* TO ‘forumuser‘@‘localhost‘; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL ON forumdb.* TO ‘forumuser‘@‘127.0.0.1‘; Query OK, 0 rows affected (0.00 sec)
(5)按照操作,一步一步进行安装,就OK。
在登录的时候,要输入管理员的帐号和密码才可以登录。