日期:2014-05-17  浏览次数:20525 次

为什么我的本地环境不能解析子目录下的PHP文件
环境是
apache2.2 
PHP5.4


在apache的安装目录下的htdosc是我的WEB根目录.
我在里面创建的项目不能解析PHP文件.会提示连接被重置!或网络已断开.在地址栏输入这个路径只能看到当前目录下的文件.
而根目录的index.php却能正常解析.

有时候自己就好了.很奇怪啊.
我觉得是httpd.conf的配置有问题.看了又找不出原因.我对apache的配置不是很懂.
请各位哥哥帮帮我.

------解决方案--------------------
httpd.conf可解析的文件扩展名:

<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .phtml .vcgi
AddHandler type-map var
</IfModule>
------解决方案--------------------
检查apache错误日志,看报什么错。
------解决方案--------------------
htdocs本来就是放静态文件的
动态文件,例如php放cgi-bin里
google关键字:Apache ScriptAlias
------解决方案--------------------
PHP code

DefaultType text/plain

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php3

    #
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    #AddHandler cgi-script .cgi

    # For type maps (negotiated resources):
    #AddHandler type-map var

    #
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml
</IfModule>

------解决方案--------------------
我在里面创建的项目不能解析PHP文件.会提示连接被重置!或网络已断开.在地址栏输入这个路径只能看到当前目录下的文件.
而根目录的index.php却能正常解析.

如果没有index.php索引文件,你直接打开目录的话 的确是显示文件目录结构的,如果有这个index.php文档,那么apache会先解析index.php文档.这个你可以在apache的配置文件修改 

搜索
Options Indexes FollowSymLinks

将Indexes 去掉 保存重启apache 即可.

访问某个文件提示 连接被重置
那就查日志看看具体的错误是什么内容 .这种原因可能有很多,比如你的php出现错误 .打开 php.ini里的错误提示,设置浏览器的(IE的友好错误提示)...