码迷,mamicode.com
首页 > 系统相关 > 详细

2018-04-12 Linux学习

时间:2018-04-12 22:23:52      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:Linux学习

11.14-15 Apache 和 PHP 结合

httpd 主配置文件  /usr/local/apache2.4/conf/httpd.conf
vim /usr/local/apache2.4/conf/httpd.conf    //修改以下4个地方
ServerName    //去掉#注释,194行
        ServerName www.example.com:80

Require all granted  //修改 denied 为 granted
        <Directory />
            AllowOverride none
            Require all granted
        </Directory>    

AddType application/x-httpd-php .php  //添加这一行
        AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
        AddType application/x-httpd-php .php

DirectoryIndex index.html index.php   //这一行添加 index.php
        <IfModule dir_module>
        DirectoryIndex index.html index.php
        </IfModule>

/usr/local/apache2.4/bin/apachectl -t   //测试语法
/usr/local/apache2.4/bin/apachectl graceful   //
/usr/local/apache2.4/bin/apachectl start  //启动服务
netstat -lntp
curl localhost

vim /usr/local/apache2.4/htdocs/test.php  //增加如下内容
<?php
echo 123;

curl localhost/test.php

iptables -I INPUT -p tcp --dport 80 -j ACCEPT

    [root@aming-01 ~]# /usr/local/apache2.4/bin/apachectl graceful
    httpd not running, trying to start
    /usr/local/apache2.4/bin/apachectl: 行 79:  4343 段错误               $HTTPD -k $ARGV

    以上报错,注释掉以下其中一个
    LoadModule php5_module        modules/libphp5.so
    #LoadModule php7_module        modules/libphp7.so

    [root@aming-01 ~]# ls /usr/local/apache2.4/htdocs/
    index.html

    PHP信息内容
    [root@aming-01 ~]# vim vim /usr/local/apache2.4/htdocs/info.php
    <?php
    phpinfo();

11.16-17 Apache默认虚拟主机

一个服务器可以访问多个网站,每个网站都是一个虚拟主机
概念:域名(主机名)、DNS、解析域名、hosts
任何一个域名解析到这台机器,都可以访问的虚拟主机就是默认虚拟主机

vim /usr/local/apache2.4/conf/httpd.conf   //搜索httpd-vhost,去掉#

        # Virtual hosts
        Include conf/extra/httpd-vhosts.conf

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf   //改为如下

        <VirtualHost *:80>
            ServerAdmin abc@test.com
            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
            ErrorLog "logs/111.com-error_log"
            CustomLog "logs/111.com-access_log" common
        </VirtualHost>

[root@aming-01 ~]]# /usr/local/apache2.4/bin/apachectl -t        AH00112: Warning: DocumentRoot [/data/wwwroot/abc.com] does not exist
AH00112: Warning: DocumentRoot [/data/wwwroot/111.com] does not exist
Syntax OK

[root@aming-01 ~]]# /usr/local/apache2.4/bin/apachectl graceful
AH00112: Warning: DocumentRoot [/data/wwwroot/abc.com] does not exist
AH00112: Warning: DocumentRoot [/data/wwwroot/111.com] does not exist

curl -x192.168.104.160:80 

[root@aming-01 ~]# mkdir /data/wwwroot/
[root@aming-01 ~]# mkdir /data/wwwroot/abc.com
[root@aming-01 ~]# mkdir /data/wwwroot/111.com
[root@aming-01 ~]# vim /data/wwwroot/abc.com/index.php
[root@aming-01 ~]# vim /data/wwwroot/111.com/index.php
[root@aming-01 ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aming-01 ~]# /usr/local/apache2.4/bin/apachectl graceful

[root@aming-01 ~]# curl -x192.168.104.160:80 www.abc.com
abc.com[root@aming-
[root@aming-01 ~]# curl -x192.168.104.160:80 abc.com
abc.com[root@aming-01 ~]# curl -x192.168.104.160:80 111.com
111.com[root@aming-01 ~]#

2018-04-12 Linux学习

标签:Linux学习

原文地址:http://blog.51cto.com/9298822/2097593

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!