Apache和PHP结合、Apache默认虚拟主机

Apache和PHP结合
[root@wsl-001 php-7.1.6]# /usr/local/apache2.4/bin/apachectl restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe45:ec93. Set the 'ServerName' directive globally to suppress this message
[root@wsl-001 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf

ServerName www.example.com:81 (打开#号)

LoadModule php5_module        modules/libphp7.so
#LoadModule php7_module        modules/libphp8.so (需要注释掉一个)


    AllowOverride none
    Require all granted  (更改这一项,不然会403 Forbidden)


AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php (增加这一行,不然无法解析PHP)


    DirectoryIndex index.html index.php (增加index.php)


(检查配置文件语法是否正确)
[root@wsl-001 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
(重新加载配置文件)
[root@wsl-001 php-7.1.6]# /usr/local/apache2.4/bin/apachectl graceful
[root@wsl-001 php-7.1.6]# /usr/local/apache2.4/bin/apachectl restart
[root@wsl-001 php-7.1.6]# 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      874/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1093/master         
tcp        0      0 172.16.79.140:8730      0.0.0.0:*               LISTEN      1655/rsync          
tcp6       0      0 :::3306                 :::*                    LISTEN      6334/mysqld         
tcp6       0      0 :::80                   :::*                    LISTEN      62840/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      874/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1093/master  
[root@wsl-001 php-7.1.6]# ps aux |grep httpd
root      62840  0.2  0.6 253536 12384 ?        Ss   09:48   0:00 /usr/local/apache2.4/bin/httpd -k restart
daemon    62928  0.0  0.3 540364  7412 ?        Sl   09:48   0:00 /usr/local/apache2.4/bin/httpd -k restart
daemon    62929  0.0  0.3 540364  7412 ?        Sl   09:48   0:00 /usr/local/apache2.4/bin/httpd -k restart
daemon    62930  0.0  0.3 540364  7404 ?        Sl   09:48   0:00 /usr/local/apache2.4/bin/httpd -k restart
root      63013  0.0  0.0 112676   984 pts/0    S+   09:48   0:00 grep --color=auto httpd
(打开80端口)
[root@wsl-001 php-7.1.6]# iptables -I INPUT -p tcp --dport 90 -j ACCEPT

[root@wsl-001 ~]# vi /usr/local/apache2.4/htdocs/1.php

php无法解析检查项

#查看模块加载情况
[root@wsl-001 ~]# /usr/local/apache2.4/bin/httpd -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)
 php5_module (shared)
[root@wsl-001 ~]# ls /usr/local/apache2.4/modules/libphp5.so 
/usr/local/apache2.4/modules/libphp5.so
[root@wsl-001 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf

ServerName www.example.com:81 (打开#号)

LoadModule php5_module        modules/libphp7.so
#LoadModule php7_module        modules/libphp8.so (需要注释掉一个)


    AllowOverride none
    Require all granted  (更改这一项,不然会403 Forbidden)


AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php (增加这一行,不然无法解析PHP)


    DirectoryIndex index.html index.php (增加index.php)


Apache默认虚拟主机

Apache默认虚拟主机
[root@wsl-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf

# Virtual hosts
Include conf/extra/httpd-vhosts.conf (打开这一行)

(打开虚拟主机配置文件)
[root@wsl-001 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf

(管理员邮箱)
    ServerAdmin [email protected]
(网站目录)
    DocumentRoot "/data/wwwroot/abc.com"
(网站网址,只能写一个)
    ServerName abc.com
(网站别名,可以写多个)
    ServerAlias www.abc.com www.123.com
(错误日志)
    ErrorLog "logs/dummy-host.example.com-error_log"
(日志)
    CustomLog "logs/dummy-host.example.com-access_log" common

(虚拟主机配置文件生效后,之前定义的配置文件就没什么用了)

    ServerAdmin [email protected]
    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


[root@wsl-001 ~]# mkdir /data/wwwroot/
[root@wsl-001 ~]# mkdir /data/wwwroot/abc.com
[root@wsl-001 ~]# mkdir /data/wwwroot/111.com
[root@wsl-001 ~]# vim  /data/wwwroot/abc.com/index.php

[root@wsl-001 ~]# vim  /data/wwwroot/111.com/index.php
[root@wsl-001 ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@wsl-001 ~]# /usr/local/apache2.4/bin/apachectl graceful
(没有定义的域名会访问到第一个虚拟主机上)
[root@wsl-001 ~]# curl -x 172.16.79.140:80 abc.com
abc.com
[root@wsl-001 ~]# curl -x 172.16.79.140:80 a.com
abc.com
[root@wsl-001 ~]# curl -x 172.16.79.140:80 111.com
111.com

多端口需要更改配置监听端口

1、开打多监听端口
httpd.conf 文件

Listen 80

Listen 8888

     这样就打开了80 同8888端口。

你可能感兴趣的:(Apache和PHP结合、Apache默认虚拟主机)