开发者

PHP Files won't open in browser - only download. What do I need to change to make it work properly?

I have tried reinstalling PHP. PHP is working, and Apache2 is running. I don't know why it's not opening in a browser and displaying normally.

Just so you know - my httpd.conf is empty - and instead I hav开发者_JAVA技巧e everything in apache2.conf. This is because I'm using Ubuntu.

Can you help me? I know it's something simple, but I can't seem to find the answer.


Have you virtual host on this project?

Are you open php file with http://localhost/file.php or directly like file://...../file.php ?


In your apache conf:

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

Don't forget to restart apache afterwards. Let me know how it goes.


In my case there was a modification of the /etc/apache2/mods-enabled/php5.conf by module userdir

<IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
    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>

The solution is inside the config file, just comment the lines from <IfModule mod_userdir> to </IfModule>.


Try

sudo a2enmod php5

in terminal. Assuming you are using php 5 :)


If you are using php5 the complete solution would be

sudo apt-get install libapache2-mod-php5

Then

sudo a2enmod php5


I recently had this problem, but only when accessing my site's root (e.g. http://example.com) - it worked as expected when accessing index.php explicitly (e.g. http://example.com/index.php).

The issue was that before creating index.php, I had an index.html file in the web root, but then I renamed it to index.html.bak to 'move it out of the way'. Unfortunately, that doesn't move it out of the way. For whatever reason, Apache will serve that file up with a MIME type of application/x-trash.
(As the /etc/mime.types file contains a line reading "application/x-trash ~ % bak old sik")

Maybe that will help someone else who is scratching their head as I was.


Also, when moving a site and you encounter this, make sure your .htaccess file doesn't specify a different method handler for php. We ran into this moving a wordpress site for a client.


Had same problem - and it was in the .htaccess file I had accidentally downloaded from the live server. Once you've deleted the .htaccess file, you will need to clear your cache to be able to load the .php file in your browser via http://

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜