简体   繁体   中英

xampp virtual host downloading php files in browser (Mac)

I have xampp installed on my Mac. I have setup virtual hosts with this is in httpd-vhosts.conf

    <VirtualHost *:80>
        DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
        ServerName localhost
    </VirtualHost>

    <VirtualHost *:80>
        DocumentRoot "/Users/username/Dropbox/folder/cms backup/test"
        ServerName cms.local
        ServerAlias cms.local
        <Directory "/Users/username/Dropbox/folder/cms backup/test">
           Options Indexes FollowSymLinks Includes ExecCGI
           AddType application/x-httpd-php .php3 .php 
           AddOutputFilter INCLUDES .php
           AllowOverride All
           Order allow,deny
           Allow from all
        </Directory>
     </VirtualHost>

I have uncommented

    # Virtual hosts
    Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

Changed user and Group

    User "my username"
    #Group nogroup
    Group admin

And added to hosts

    127.0.0.1 cms.local

But when I go to cms.local/php_file.php I get a server 500 error and the php file is downloaded by the browser instead of being displayed. Everything works fine when I try to view the same page in localhost/php_file.php

Can anyone give any ideas why it is downloading the file?

Logs and Header info:

Header info:

    Request URL:http://cms.local/diary.php
    Request Method:GET
    Status Code:200 OK
    Request Headersview source
    Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
    Accept-Encoding:gzip,deflate,sdch
    Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
    Cache-Control:max-age=0
    Connection:keep-alive
    Host:cms.local
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31
    Response Headersview source
    Accept-Ranges:bytes
    Connection:Keep-Alive
    Content-Type:application/x-httpd-php
    Date:Tue, 07 May 2013 23:01:58 GMT
    Keep-Alive:timeout=5, max=100
    Server:Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1
    Transfer-Encoding:chunked

Access log:

    127.0.0.1 - - [08/May/2013:09:01:58 +1000] "GET /diary.php HTTP/1.1" 200 61851

Error log:

    [Wed May 08 09:05:54 2013] [notice] caught SIGTERM, shutting down
    [Wed May 08 09:06:05 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
    [Wed May 08 09:06:06 2013] [notice] Digest: generating secret for digest authentication ...
    [Wed May 08 09:06:06 2013] [notice] Digest: done
    [Wed May 08 09:06:06 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations

Permissions for the file and directory were set to 644 and then I changed them to 755. It made no difference.

Finally found an answer that worked here: PHP Files won't open in browser - only download. What do I need to change to make it work properly?

Adding:

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

to the httpd.conf file fixed it

What headers are displayed with F-12 tools (Firebug/Chrome Dev. Tools)?

What are the file permissions?

What do the logs show?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM