系统环境:
CentOS 7
Apache 2.4
php 5.4
MariaDB 5.5
项目需求:
创建3个虚拟主机,分别架设phpMyadmin,wordpress,Discuz
其中phpMyadmin提供https服务.
一、使用yum安装环境所需组件
httpd,php,php-MySQL,mariadb-server
# yum install httpd php php-mysql mariadb-server
二、关闭SELINUX并配置防火墙
1.为了测试方便,先关闭selinux
临时关闭:
setenforce 0
永久关闭:
vim /etc/sysconfig/selinux
SELINUX=disabled
2.在CentOS 7自带防火墙中添加80,443,3306端口
查看firewall运行状态
# firewall-cmd --state
添加端口
# firewall-cmd --add-port=80/tcp --permanent
# firewall-cmd --add-port=443/tcp --permanent
# firewall-cmd --add-port=3306/tcp --permanent
重载firewall配置
# firewall-cmd --reload
查看已有规则
# iptables -L -n
三、测试一下各软件是否正常
1.启动httpd并测试访问:
# systemctl start httpd
没什么意外的话,此时浏览器访问测试页应该是成功的.
2.测试数据库
启动MariaDB
# systemctl start mariadb
能进入MariaDB命令行即可
# mysql
3.查看php版本,我的版本是5.4.16
# php -v
四、配置Apache
1.新建所需文件夹
在/web/vhosts下创建三个虚拟主机分别需要的文件夹 ,pma,wp,dz
# mkdir -p /web/vhosts/{pma,wp,dz}
2.赋予Apache用户对整个/web目录的访问权:
# chown -R apache:apache /web
3.创建测试页面
# vim /web/vhosts/pma/index.php
内容为:
<?php
echo "this is pma"
?>
# vim /web/vhosts/wp/index.php
内容为:
<?php
echo "this is wp"
?>
# vim /web/vhosts/dz/index.php
内容为:
<?php
echo "this is dz"
?>
4.取消欢迎页,否则会有干扰
# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak
5.添加三个虚拟主机
创建一个叫vhosts.conf配置文件
# vim /etc/httpd/conf.d/vhosts.conf
内容:
<VirtualHost *:80>
DocumentRoot /web/vhosts/pma
ServerName pma.linuxidc.com
ErrorLog logs/pma.err
CustomLog logs/pma.access combined
</VirtualHost>
<Directory "/web/vhosts/pma">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot /web/vhosts/wp
ServerName wp.linuxidc.com
ErrorLog logs/wp.err
CustomLog logs/wp.access combined
</VirtualHost>
<Directory "/web/vhosts/wp">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot /web/vhosts/dz
ServerName dz.linuxidc.com
ErrorLog logs/dz.err
CustomLog logs/dz.access combined
</VirtualHost>
<Directory "/web/vhosts/dz">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
6.重新载入httpd配置:
# systemctl reload httpd
7.测试一下三个虚拟主机:
测试成功!
五、配置mariaDB
1.刚安装完mariaDB后先初始化安全设置
运行安全初始化脚本
# /usr/bin/mysql_secure_installation
以下给出我自己的选项作为参考
1)是否设置root用户密码? (是)