browser downloads php file from apache web server

后端 未结 3 621
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 23:43

I have an apache web server. Let\'s say this server\'s domain is example.com.

When I access example.com, then the index.php file is co

相关标签:
3条回答
  • 2021-01-18 00:20

    I've had a similar experience - some php files working OK, but others seem to have the raw php code downloaded.

    In my case, it was due to the broken files using the short tag format of <? and ?>. This is not recommended, and you may find the default php.ini has this support forced off. With support off, the php code is sent down to the browser as if it was HTML.

    If you can't avoid short tags (as in my case - a whole legacy codebase using short tags), then you can set it to be allowed in php.ini:

    short_open_tag = On
    
    0 讨论(0)
  • 2021-01-18 00:29

    Hope this saves someone else the headache. I know this question is old, but it still comes up when searching for this problem.

    I'm not sure if this works across all installations of apache2, but I am running apache2 on ubuntu and had the problem of my web browser downloading files instead of displaying the correct index file.

    The problem lies in the file /etc/apache2/mods-enabled/dir.conf The default document setting here was overriding what I had set in /etc/apache2/httpd.conf

    So just open up /etc/apache2/mods-enabled/dir.conf and change the order of the files listed.

    :)

    0 讨论(0)
  • 2021-01-18 00:35

    If you are on Debian/Ubuntu take a look at this file /etc/apache2/mods-available/php5.conf

    mine looks like this and you can see I had to comment some line to get PHP working in the user dir

    <IfModule mod_php5.c>
        <FilesMatch "\.ph(p3?|tml)$">
            SetHandler application/x-httpd-php
        </FilesMatch>
        <FilesMatch "\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>
        <FilesMatch "\.phps$">
            SetHandler application/x-httpd-php-source
        </FilesMatch>
        # To re-enable php in user directories comment the following lines
        # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
        # prevents .htaccess files from disabling it.
        #<IfModule mod_userdir.c>
        #    <Directory /home/*/public_html>
        #        php_admin_value engine Off
        #    </Directory>
        #</IfModule>
    </IfModule>
    

    Please note that after editing the file you would have to restart apache for the modifications to take effect, the command to restart apache on a debian based system is: /etc/init.d/apache2 restart

    0 讨论(0)
提交回复
热议问题