Apache is downloading php files instead of displaying them

后端 未结 26 1735
陌清茗
陌清茗 2020-11-22 01:03

OS and server information:

  • CentOS 6.4 (Final)
  • Apache 2.2.15
  • PHP 5.5.1

I previously had php 5.3.x installed but decided to upgr

26条回答
  •  半阙折子戏
    2020-11-22 01:34

    Please take a look at your addtype directives.

    It looks to me like Apache is telling the browser that it's sending a document type of application/php for scripts with extensions like .php5. In fact Apache is supposed to tell the browser that the script is outputting text/html.

    Please try this:

    AddType text/html .php
    

    Regarding the suggestion above that you should tell the browser that you are outputting a PHP script: It seemed like an unusual idea to me. I googled it and found that there is quite a bit of discussion about it on the web. Apparently there are cases where you might want to say that you are sending a PHP script (even though Apache is supposed to execute the script and emit text/html,) and there are also cases where the browser simply doesn't recognize that specific Mime Type.

    Clearing your browser cache is always a good idea.

    In case it's helpful here's a copy of my /etc/httpd/conf.d/php.conf file from a server running CentOS 5.9:

    #        
    # PHP is an HTML-embedded scripting language which attempts to make it                                             
    # easy for developers to write dynamically generated webpages.                                                  
    #
    
      LoadModule php5_module modules/libphp5.so
    
    
      LoadModule php5_module modules/libphp5-zts.so
    
    
    #
    # Cause the PHP interpreter to handle files with a .php extension.
    #
    AddHandler php5-script .php
    AddType text/html .php
    
    #
    # Add index.php to the list of files that will be served as directory
    # indexes.
    #
    DirectoryIndex index.php
    
    #
    # Uncomment the following line to allow PHP to pretty-print .phps
    # files as PHP source code:
    #
    #AddType application/x-httpd-php-source .phps
    

提交回复
热议问题