部署apache
部署apache
使用yum安装
yum install -y httpd
配置防火墙
centos7默认防火墙firewall,配置防火墙开放80端口。
#配置80端口开放
firewall-cmd --zone=public --add-port=80/tcp --permanent
#跟新规则
firewall-cmd --reload
#查看
firewall-cmd --query-port=80/tcp
出现Unit firewalld.service could not be found.情况,运行以下命令安装firewalld模块即可
yum install firewalld systemd -y
centos7防火墙服务
#开启
systemctl start firewalld.service
#重启
systemctl restart firewalld.service
#查看
systemctl status firewalld.service
#关闭
systemctl stop firewalld.service
#禁用(开机禁用)
systemctl disable firewalld.service
#启用(开机开启)
systemctl enable firewalld.service
关闭SELinux
SELinux是Linux的一个安全子系统,如果你不熟悉Linux的,干脆把它关了就行了。
临时关闭
setenforce 0
配置更改
主配置文件位于:/etc/httpd/conf/httpd.conf
yum安装的话配置文件一般不用改,注意几个点即可
#看看你有没有监听80端口
Listen 80
#这个可以选择改(默认就是开放的),这个为对所有ip都允许访问/var/www/html
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
Allow from all
Require all granted
</Directory>
启动
systemctl start httpd
整合PHP
一样使用yum下载
sudo yum install -y php
然后重启apache服务器即可,使用yum安装的php好像会处理apache之间的整合,所以这里不用修改也能用。
systemctl start httpd
测试
在/var/www/html目录下弄一个index.php,然后访问一下试试即可。
vim /var/www/html/index.php