修改以下4个地方
ServerName 这个打开后开启httpd后没有警告
Require all denied 这个修改为Require all granted 防止打开虚拟主机配置文件时403
AddType application/x-httpd-php .php 加上这行才可以解析php
DirectoryIndex index.html index.php 添加默认索引页
DocumentRoot "/usr/local/apache2.4/htdocs" 这个参数可以定义网站的域名根目录
[root@aminglinux-02 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1122/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2094/master
tcp6 0 0 :::3306 :::* LISTEN 2658/mysqld
tcp6 0 0 :::80 :::* LISTEN 2387/httpd
tcp6 0 0 :::22 :::* LISTEN 1122/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2094/master
[root@akuilinux01 ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@akuilinux01 ~]# iptables -nvL
Chain INPUT (policy ACCEPT 58 packets, 3900 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
[root@aminglinux-02 ~]# vim /usr/local/apache2.4/htdocs/1.php
<?php
phpinfo();
?>
故障排查
检查Apache是否已加载PHP模块
[root@aminglinux-02 ~]# /usr/local/apache2.4/bin/apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
php7_module (shared)
[root@aminglinux-02 ~]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so
[root@aminglinux-02 ~]# ls /usr/local/apache2.4/modules/libphp5.so
/usr/local/apache2.4/modules/libphp5.so
#LoadModule php5_module modules/libphp5.so
LoadModule php7_module modules/libphp7.so
ServerName www.example.com:80
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
Addtype application/x-httpd-php .php
<Directory />
AllowOverride none
Require all granted
</Directory>
192.168.21.128 www.abc.com www.123.com
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
打开这个选项,启用虚拟主机配置文件/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/abc.com"
ServerName abc.com
ServerAlias www.abc.com www.123.com
ErrorLog "logs/abc.com-error_log"
CustomLog "logs/abc.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
ServerAlias www.example.com
ErrorLog "logs/111.com-error_log"
CustomLog "logs/111.com-access_log" common
</VirtualHost>
[root@aminglinux-02 ~]# mkdir /data/wwwroot
[root@aminglinux-02 ~]# mkdir /data/wwwroot/abc.com
[root@aminglinux-02 ~]# mkdir /data/wwwroot/111.com
[root@aminglinux-02 ~]# vim /data/wwwroot/abc.com/index.php
[root@aminglinux-02 ~]# vim /data/wwwroot/111.com/index.php
<?php
echo "abc.com";
root@aminglinux-02 ~]# curl -x192.168.16.120:80 abc.com
abc.com[root@aminglinux-02 ~]# curl -x192.168.16.120:80 111.com
111.com[root@aminglinux-02 ~]# curl -x192.168.16.120:80 www.dahjdhajabc.com
abc.com[root@aminglinux-02 ~]#
原文地址:http://blog.51cto.com/akui2521/2121361