下面给你一份 CentOS 上配置 Apache(httpd) 的实用步骤,适用于 CentOS 7 / 8 / Stream(差别我会标出来)。
yum install -y httpd
dnf install -y httpd
systemctl start httpd
systemctl enable httpd
查看状态:
systemctl status httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
如果没开防火墙可忽略。
浏览器访问:
http://服务器IP
看到 Apache Test Page 即成功。
默认网站根目录:
/var/www/html
放一个测试页:
echo "Hello Apache" > /var/www/html/index.html
mkdir -p /var/www/example.com
echo "example.com" > /var/www/example.com/index.html
vi /etc/httpd/conf.d/example.conf
内容示例:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
systemctl restart httpd
yum install -y php php-cli
systemctl restart httpd
测试:
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
# 检查配置语法
httpd -t
# 重启
systemctl restart httpd
# 查看错误日志
tail -f /var/log/httpd/error_log
如果你是要:
可以直接告诉我,我按你的场景写。