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

简介:

Apache和PHP结合

1、先禁用之前的php7的模块

[root@centos7 ~]# cat /usr/local/apache2.4/conf/httpd.conf| grep 'php'

LoadModule php5_module        modules/libphp5.so

#LoadModule php7_module        modules/libphp7.so


2、查看下是否禁用php7模块

[root@centos7 ~]# /usr/local/apache2.4/bin/apachectl -M

 rewrite_module (shared)

 php5_module (shared) #只有一个,说明禁用了

Syntax OK


3、访问下apache是否工作,可以看到It works!说明apache已经正常

a2c3409799a176addea5d8aaafb37acb.png-wh_


4、添加php服务解析

[root@centos7 ~]# vi /usr/local/apache2.4/conf/httpd.conf

    AddType application/x-compress .Z

    AddType application/x-gzip .gz .tgz

    AddType application/x-httpd-php .php  #添加下这行后,apache才能解析

5、/usr/local/apache2.4/bin/apachectl graceful

6、

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

<?php

phpinfo();

0315499068a0c12b1a69327ee52ca7b5.png-wh_

7、vi /usr/local/apache2.4/conf/httpd.conf

<IfModule dir_module>

    DirectoryIndex index.html index.php  #新增这个

</IfModule>

重载配置文件

/usr/local/apache2.4/bin/apachectl graceful

mv   /usr/local/apache2.4/htdocs/1.php /usr/local/apache2.4/htdocs/index.php

8、访问http://192.168.3.74

a16ae17cf5ff925f1341a8cbe259816c.png-wh_


apache配置php7来解析

1、[root@centos7 htdocs]# vi /usr/local/apache2.4/conf/httpd.conf

#LoadModule php5_module        modules/libphp5.so

LoadModule php7_module        modules/libphp7.so

2、[root@centos7 htdocs]# /usr/local/apache2.4/bin/apachectl graceful

3、访问
2edfb486d42636828b7a9f22b3799e5d.png-wh_


Apache默认虚拟主机

1、打开vhosts虚拟主机

[root@centos7 htdocs]# vi /usr/local/apache2.4/conf/httpd.conf

# Virtual hosts

Include conf/extra/httpd-vhosts.conf

2、[root@centos7 htdocs]# /usr/local/apache2.4/bin/apachectl graceful

3、定义了两个虚拟主机

[root@centos7 htdocs]# cat  /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.111.com www.example.com

    ErrorLog "logs/111.com-error_log"

    CustomLog "logs/111.com-access_log" common

</VirtualHost>

4、

[root@centos7 htdocs]# mkdir /data/wwwroot/

[root@centos7 htdocs]# mkdir /data/wwwroot/abc.com

[root@centos7 htdocs]# mkdir /data/wwwroot/111.com

5、

[root@centos7 htdocs]# vi /data/wwwroot/abc.com/index.php


<h1>this is abc.com</h1>

[root@centos7 htdocs]# vi /data/wwwroot/111.com/index.php


<h1>this is 111.com</h1>

6、

[root@centos7 htdocs]# /usr/local/apache2.4/bin/apachectl graceful

7、访问:[root@centos7 abc.com]# curl -x http://127.0.0.1:80 abc.com

错误:403拒绝访问:

c4b401c14f2bb629ddafdcefb1acb2df.png-wh_

解决: vi /usr/local/apache2.4/conf/httpd.conf

<Directory />

    Options FollowSymLinks

    AllowOverride None

    Order deny,allow

#    Deny from all

</Directory>

8、/usr/local/apache2.4/bin/apachectl graceful

9、访问

[root@centos7 abc.com]# curl -x127.0.0.1:80 www.abc.com

<h1>this is abc.com</h1>

[root@centos7 abc.com]# curl -x127.0.0.1:80 www.111.com

<h1>this is 111.com</h1>

10、abc.com为默认的页面

11、无论访问哪个都为调到这上

[root@centos7 abc.com]# curl -x127.0.0.1:80 123123123asdasd

<h1>this is abc.com</h1>


本文转自 jiekegz  51CTO博客,原文链接:http://blog.51cto.com/jacksoner/1980209


相关文章
|
MySQL 关系型数据库 PHP
apache2.4 + php7.2 + mysql 配置指南2018版
2018最新php+mysql+apache环境配置
3252 0
|
关系型数据库 Linux PHP
|
Web App开发 Apache PHP
|
关系型数据库 MySQL 测试技术

推荐镜像

更多