说明
操作系统:linux centos7
Apache版本:2.4.6
安装方式:yum安装
1. 安装
yum -y install httpd
# 安装完成后启动httpd
# systemctl status httpd 查看状态
# systemctl start httpd 启动
# systemctl restart httpd 重启
# systemctl stop httpd 停止
# systemctl enable httpd 设置开机自启动
# systemctl disable httpd 设置开机不自启动
浏览器输入服务器ip地址,网页出现test123…说明安装成功。
提示:需要注意一下防火墙是否开放80端口
2. 配置Apache
vim /etc/httpd/conf/httpd.conf
# 编辑配置文件,找到
<Directory />
AllowOverride none
Require all denied
</Directory>
# 改为
<Directory />
AllowOverride none
Require all granted
</Directory>
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>
# 改为
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
3. 项目部署
然后进入Apache项目根目录
cd /var/www/html
新建文件夹test1,创建index.html,并随机写一下内容
mkdir test1
# 编辑test1下的index.html
vim test1/index.html
浏览器输入服务器ip/test1,网页出现刚刚index.html的内容则成功
4. 多项目部署,并配置域名
和上面方法一下,在创建一个test2,然后
vim /etc/httpd/conf.d/vhost.conf
写入
<VirtualHost *:80>
# 项目文件
DocumentRoot "/var/www/html/test1"
# 域名
ServerName 你的域名1
ServerAlias www.你的域名1
<Directory "/var/www/html/test1">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/test2"
ServerName 你的域名2
ServerAlias www.你的域名2
<Directory "/var/www/html/test2">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
浏览器输入你的域名1.com,你的域名2.com,能成功访问则成功。