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

11.14/11.15 Apache和PHP结合

  1. httpd主配置文件/usr/local/apache2.4/conf/httpd.conf
  2. # vim /usr/local/apache2.4/conf/httpd.conf //修改如下4个地方
    ServerName
    Require all denied修改成allow
    AddType application/x-httpd-php .php//增长到AddType处
    DirectoryIndex index.html index.php//增长一个索引页
  3. /usr/local/apache2.4/bin/apachectl start //启动服务
  4. # /usr/local/apache2.4/bin/apachectl -t //测试语法是否正确
  5. # /usr/local/apache2.4/bin/apachectl graceful//从新加载配置文件的命令
    1. 是否加载php5的module
    2. 4个地方是否配置了
  6. # vim /usr/local/apache2.4/htodcs/1.php //增长以下内容

<?php phpinfo(); ?>php

  1. ctrl+r 直接输入命令,能够查找历史命令

11.16/11.17 Apache默认虚拟主机

  1. 一台服务器能够访问多个网站,每一个网站都是一个虚拟主机
  2. 概念:域名(主机名)、DNS、解析域名、hosts
  3. 任何一个域名解析到这台机器,均可以访问的虚拟主机就是默认虚拟主机
  4. vim /usr/local/apache2/conf/httpd.conf //搜索httpd-vhost,去掉#
  5. vim /usr/local/apache2/conf/extra/httpd-vhosts.conf //改成以下 <VirtualHost *:80> ServerAdmin admin@aminglinux.com DocumentRoot "/data/wwwroot/aming.com" ServerName aming.com ServerAlias www.aming.com ErrorLog "logs/aming.com-error_log" CustomLog "logs/aming.com-access_log" common </VirtualHost> <VirtualHost *:80> DocumentRoot "/data/wwwroot/www.123.com" ServerName www.123.com </VirtualHost>
  6. # /usr/local/apache2/bin/apachectl –t
  7. # /usr/local/apache2/bin/apachectl graceful
  8. mkdir -p /data/wwwroot/aming.com /data/wwwroot/www.123.com
  9. echo "aming.com" > /data/wwwroot/aming.com/index.html //网站默认的主页就是index.html
  10. echo "123.com" > /data/wwwroot/123.com/index.html
  11. curl -x127.0.0.1:80 aming.com //这样会去访问aming.com/index.html
  12. curl -x127.0.0.1:80 www.123.com //访问www.123.com
  13. curl -x127.0.0.1:80 www.abc.com c

扩展

  1. apache全部的主机都指向第一个 http://www.aminglinux.com/bbs/thread-491-1-1.html
相关文章
相关标签/搜索