Apache is downloading php files instead of display

2018-12-31 04:07发布

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 upgrade. I first uninstalled the php 5.3.x and then installed php 5.5.1 but after the installation completed apache did not parse the php files it just downloaded them. I have checked similar questions here in stackoverflow but none of them have helped me so far.

For the record I have the following lines in my httpd.conf and php.conf that should make php work but don't:

AddHandler application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php-source .phps
AddHandler php5-script .php

I would really appreciate any help. Thank you.

EDIT:

I have these lines in the php.conf

<IfModule !worker.c>
  LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
  LoadModule php5_module modules/libphp5-zts.so
</IfModule>

EDIT:

By removing the

AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml

apache no longer downloads the file. Now apache is showing the source code, but not all of it just part. I added

AddType text/html .php

but no luck.

21条回答
不再属于我。
2楼-- · 2018-12-31 04:38

I previously has a similar issue, after upgrading from 5.3 to 5.4. But my setup looks a little bit different as that I'm running Debian and using fcgid to server the PHP pages, and not the PHP5 apache/cgi module. So after I upgraded, it also installed php5_cgi, which collided with my fcgid setup, and would not execute PHP files anymore.

I had to disable the Apache Module and restart Apache

a2dismod php5_cgi
/etc/init.d/apache2 restart

Once the php5_cgi module was out of the way, fcgid was able to serve PHP pages again.

查看更多
只若初见
3楼-- · 2018-12-31 04:38

I had this problem and if you actually never played with your server configuration settings, then your problem is 90% in your .htaccess file

You either modify .htaccess file LOCALLY, ore delete it (LOCALLY)

查看更多
柔情千种
4楼-- · 2018-12-31 04:39

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.

查看更多
几人难应
5楼-- · 2018-12-31 04:40

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.

查看更多
人间绝色
6楼-- · 2018-12-31 04:40

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

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

sudo service apache2 restart

查看更多
琉璃瓶的回忆
7楼-- · 2018-12-31 04:42

If Your .htaccess have anything like this

AddType application/x-httpd-ea-php56 .php .php5 .phtm .html .htm
查看更多
登录 后发表回答