zoukankan      html  css  js  c++  java
  • 打开mac上面的apache 服务器

    1. apache 服务器在系统安装的时候就默认安装了

        config 文件未知:  /etc/apache2/httpd.conf

    2. 编辑配置文件 httpd.conf

        2.1 查找  DocumentRoot,并修改它的值 ---该值是服务器地址

             同时修改 DocumentRoot下面的 Directory

            * 其实也可以不改可以。那服务的根目录就是在 原来的DocumentRoot下面

        2.2 查找 DirectoryIndex,并修改它的值 ---该值是服务器指定的入口网页

        2.3 查找 404 ,可以指定 NotFound.

        注* 查找:在查看模式下 输入 “/DocumentRoot" 然后回车即可查找 

     3. php环境配置

        3.1 查找 php, 找到类似 “#LoadModule php7_module libexec/apache2/libphp7.so”语句,移除注释

        3.2 服务器目录中写入php代码

    <?php 
    phpinfo(); 
    ?>
    <html>  
    <body>  
    <?php  
        echo "<div>Hello World</div>";  
    ?>  
    </body>  
    </html>

     4. 开启和关闭服务

    $ sudo apachectl -k start     //开启
    $ sudo apachectl -k stop     //关闭
    $ sudo apachectl -k restart //重启

     5. 可配置request的header

         打开配置文件 httpd.conf,在其中的某个地方加入 Header add MyHeader "Hello World"

    Header add Author-ZH "古龙•历山大亚"
    Header add Author-EN "LexanderA"
    

         如果配置文件httpd.conf 中设置LoadModule headers_module modules/mod_headers.so

         那可以使用一下语句对不同类型的请求返回不用的head

    <IfModule mod_headers.c>
    <filesmatch ".(html|htm|txt)$">
    header set Cache-Control "max-age=3600"
    </filesmatch>
    <filesmatch ".(jpeg|jpg|png)$">
    header set Cache-Control "max-age=30"
    </filesmatch>
    </IfModule>
    

     6. 配置php

    6.1 编写php文件 helloworld.php

    <?php
        echo "hello world";
    ?>
    

     在浏览器中输入 http://localhost/helloworld.php 将报 404错误

    6.2 编辑配置文件

       6.2.1  打开libphp7.io这一行

    LoadModule php7_module libexec/apache2/libphp7.so
    

     6.2.2 查找 AddType application/x-gzip .gz .tgz 在其后添加类似语句

    AddType application/x-httpd-php .php
    

    注:

           报错1 :AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using huanggulong-2.local. Set the 'ServerName' directive globally to suppress this message

           答: 查找(ServerName) 将里面的 #ServerName www.example.com:80 注释去掉并且将www.example.com改为localhost。

  • 相关阅读:
    Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.
    旋转二维数组
    replace empty char with new string,unsafe method和native implementation的性能比较
    判断一字符串是否可以另一字符串重新排列而成
    移除重复字符的几个算法简单比较
    也来纠结一下字符串翻转
    判断重复字符存在:更有意义一点
    程序员常去网站汇总
    sublime
    针对程序集 'SqlServerTime' 的 ALTER ASSEMBLY 失败,因为程序集 'SqlServerTime' 未获授权(PERMISSION_SET = EXTERNAL_ACCESS)
  • 原文地址:https://www.cnblogs.com/gulong/p/6784118.html
Copyright © 2011-2022 走看看