Apache is downloading php files instead of displaying them

后端 未结 26 1093
陌清茗
陌清茗 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:43

    I had a similar problem to the OP when upgrading php5 from an older version, to 5.5.9, which is the version installed with Mint 17.

    I'm running a LAMP setup on a machine on my local network, which I use to preview changes to websites before I upload those changes to the actual live server. So I maintain a perfect local mirror of the actual site.

    After the upgrade, files which run and display perfectly on the actual site would not display, or would only display html on the local machine. PHP was not parsed. The phpinfo() command worked, so I knew php was otherwise working. The log generated no errors. Viewing the page source showed me the actual php code.

    I had constructed a test.php page that contained the following code:

    <?php phpinfo(); ?>

    This worked. Then I discovered when I changed <?php to <? the command no longer worked. All my php sites use <? instead of <?php which might not be ideal, but it's the reality. I fixed the problem by going to /etc/php5/apache2 , searching for "short_open_tag" and changing the value from Off to On.

    0 讨论(0)
  • 2020-11-22 01:44

    If Your .htaccess have anything like this ... AddHandler application/x-httpd-php53 .php .php5 .php4 .php3 then comment it and try again refreshing this worked for me...

    0 讨论(0)
  • 2020-11-22 01:46

    If you have virtualmin try to comment out these lines in your apache configuration in /etc/apache2/sites-available

      #RemoveHandler .php
      #RemoveHandler .php7.0
      #php_admin_value engine Off
    
    0 讨论(0)
  • 2020-11-22 01:46

    For people who have found this post from Google almost 6 years in the future (and beyond!), you may run into this problem with Apache 2 and PHP 7 while also using the UserDir module.

    Another possible cause of this problem could be that you are trying to run the script in a "user directory" from the the UserDir module. Running PHP scripts in user directories is disabled by default. You will run into this problem if the script is in the public_html directory in your home folder and you are trying to access it from http://localhost/~your_username.

    To fix this, open up /etc/apache2/mods-enabled/php7.2.conf. You must comment or delete the tag block at the bottom that reads

    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_flag engine Off
        </Directory>
    </IfModule>
    
    0 讨论(0)
  • 2020-11-22 01:47

    The correct AddType for php is application/x-httpd-php

    AddType  application/x-httpd-php         .php
    AddType  application/x-httpd-php-source  .phps
    

    Also make sure your php module is loaded

    LoadModule php5_module        modules/mod_php55.so
    

    When you're configuring apache then try to view the page from another browser - I've had days when chrome stubbornly caches the result and it keeps downloading the source code while in another browser it's just fine.

    0 讨论(0)
  • 2020-11-22 01:51

    In case someone is using php7 under a Linux environment

    Make sure you enable php7

    sudo a2enmod php7
    

    Restart the mysql service and Apache

    sudo systemctl restart mysql
    sudo systemctl restart apache2
    
    0 讨论(0)
提交回复
热议问题