Apache is downloading php files instead of displaying them

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

    I came across this issue today and none of the solutions described worked for me. So here is another possible cause:

    If you have something like

    AddHandler x-mapp-php6 .php3 .php4 .php .phtml
    

    in a .htaccess file of your web content folder, it can cause your PHP scripts to stop working. In my case the server did not know the x-mapp-php6 type, since that .htaccess file was something I imported from a different web host when I transferred the website content.

    Just removing the AddHandler line from the .htaccess file solved it for me.

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

    It's also possible that you have nginx running but your php is set up to run with apache. To verify, run service nginx status and service apache2 status to see which is running. In the case that nginx is running and apache is not, just run sudo service nginx stop; sudo service apache2 start and your server will now serve php files as expected.

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

    Ok... I know that there are 1.000.000 answers to this questions already, - but I have spent at least 6 effective hours, figuring this one out; and I have googled it hundreds of times and not found a single post about it. So I figured that I would add the solution to my problem here.

    The conclusion

    If I commented these two lines out in my .conf-files in the /etc/apache2/[[SERVER-NAME].conf-file:

    php_admin_value engine Off
    IPCComTimeout 31
    

    I have no idea what they do or how they got there, - but it is in every one of my .conf-files. And if I remove those lines and ensure that there is a symlink in /etc/apache2/sites-enabled/-folder, then it doesn't download the index.php - and every works as it should.

    The entire story

    I have VirtualMin installed on an Ubuntu 16.04 VPS. I upgraded to PHP version 7.2. Shortly after that, I updated the Ubuntu-version and struck a 'Kernel Offset: Disabled'-error. So I had to go delete the latest Ubuntu-version, - and when my OS booted up again: BOOM! I got the error that his post talks about: For every site on my VPS, it simply downloaded the index.php instead of showing it.

    I tried all kinds of stuff:

    • Removed PHP7.2 and installed PHP5.6 (I know now, that the PHP-version has nothing to do with it; it's the apache-configuration that needs work).
    • Tried enabling and disabling apache modules, on the existing installation, but without luck.
    • Then I removed apache completely and installed it again, where-after the problem was still there!
    • Tried playing around with the Virutal Server setup in VirtualMin ( Webmin >> Servers >> Apache Webserver ).
    • Checked the configuration on a single Virtual-server ( Virtualmin >> System Settings >> Re-Check Configuration )... This step was pretty nice, since it told which module in Apache was missing; where-after I could enable it with a2enmod [MODULE_NAME]. And I found the module name by Googling around. I had to active about 6-8 modules, before I got past that step in the validation - and it took a couple of minutes before the cache ran out, - so doing this was a tedious step.
    • And lastly, I figured out above-written conclusion - together with the symlinks, - and then I got it to work. I had to go through it for every site on my VPS, though.
    0 讨论(0)
  • 2020-11-22 01:29

    This might be happening due to the missing modules required for your php. Assuming you have php7 installed, search available php7 modules using

    sudo apt-cache search php7-*
    

    Above command will list all available PHP7 modules for installation. You can begin installation of modules like,

    sudo apt-get install libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-json
    
    0 讨论(0)
  • 2020-11-22 01:29

    If Your .htaccess have anything like this

    AddType application/x-httpd-ea-php56 .php .php5 .phtm .html .htm
    
    0 讨论(0)
  • 2020-11-22 01:30

    this solved the problem for me (I have php7 installed):

    sudo apt-get install libapache2-mod-php7.0

    sudo service apache2 restart

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