Programing

Apache가 PHP 파일을 표시하는 대신 다운로드하고 있습니다.

lottogame 2020. 9. 16. 08:22
반응형

Apache가 PHP 파일을 표시하는 대신 다운로드하고 있습니다.


OS 및 서버 정보 :

  • CentOS 6.4 (최종)
  • Apache 2.2.15
  • PHP 5.5.1

이전에 php 5.3.x를 설치했지만 업그레이드하기로 결정했습니다. 먼저 php 5.3.x를 제거한 다음 php 5.5.1을 설치했지만 설치가 완료된 후 아파치는 php 파일을 구문 분석하지 않고 방금 다운로드했습니다. stackoverflow에서 비슷한 질문을 확인했지만 지금까지 아무도 저를 도왔습니다.

기록을 위해 httpd.conf 및 php.conf에 php가 작동하지만 작동하지 않는 다음 줄이 있습니다.

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

도움을 주시면 감사하겠습니다. 감사합니다.

편집하다:

php.conf에 다음 줄이 있습니다.

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

편집하다:

제거하여

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

아파치는 더 이상 파일을 다운로드하지 않습니다. 이제 아파치가 소스 코드를 보여 주지만 전부는 아닙니다. 나는 추가했다

AddType text/html .php

하지만 운이 없습니다.


php의 올바른 AddType은 application / x-httpd-php입니다.

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

또한 PHP 모듈이로드되었는지 확인하십시오.

LoadModule php5_module        modules/mod_php55.so

아파치를 구성 할 때 다른 브라우저에서 페이지를 봅니다. 크롬이 결과를 완고하게 캐시하고 소스 코드를 계속 다운로드하는 동안 다른 브라우저에서는 괜찮습니다.


많은 고생 끝에 마침내 문제를 해결했습니다.

.php파일을 실행하는 대신 다운로드하라는 메시지가 표시되면 여기에 완벽한 솔루션이 있습니다. 이미 PHP5를 설치했지만 여전히이 오류가 발생한다고 가정합니다.

$ sudo su
$ a2enmod php5

이거 야.

그러나 여전히 오류가 발생하는 경우 :

Config file php5.conf not properly enabled: /etc/apache2/mods-enabled/php5.conf is a real file, not touching it

그런 다음 다음을 수행하십시오.

파일 판명이에 저장해서는 안된다 mods-enabled, 오히려에 보관해야합니다 mods-available. 그런 다음 mods-available에 저장된 파일을 가리키는 심볼릭 링크를 mods-enabled에서 생성해야합니다.

먼저 원본을 제거하십시오.

$ mv /etc/apache2/mods-enabled/php5.conf /etc/apache2/mods-available/

그런 다음 심볼릭 링크를 만듭니다.

$ ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf

문제가 해결되기를 바랍니다.


오늘이 문제를 발견했지만 설명 된 솔루션 중 어느 것도 저에게 효과가 없었습니다. 따라서 또 다른 가능한 원인이 있습니다.

당신이 뭔가를 가지고 있다면

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

.htaccess웹 콘텐츠 폴더 파일에서 PHP 스크립트가 작동을 멈출 수 있습니다. 제 경우에는 x-mapp-php6해당 .htaccess파일이 웹 사이트 콘텐츠를 전송할 때 다른 웹 호스트에서 가져온 파일 이기 때문에 서버가 유형을 알지 못했습니다 .

파일 에서 AddHandler줄을 제거하는 것만으로도 .htaccess해결되었습니다.


addtype 지시문을 살펴보십시오.

Apache가 브라우저에 .php5와 같은 확장자를 가진 스크립트에 대해 application / php의 문서 유형을 보내고 있다고 말하는 것처럼 보입니다. 사실 Apache는 스크립트가 text / html을 출력하고 있음을 브라우저에 알려야합니다.

이것을 시도하십시오 :

AddType text/html .php

PHP 스크립트를 출력하고 있다는 것을 브라우저에 알려야한다는 위의 제안과 관련하여 : 나에게는 특이한 생각처럼 보였습니다. 나는 그것을 검색하고 웹에서 그것에 대해 꽤 많은 토론이 있음을 발견했습니다. 분명히 PHP 스크립트를 보내고 있다고 말하고 싶은 경우가 있으며 (아파치가 스크립트를 실행하고 text / html을 내 보내야하지만) 브라우저가 특정 Mime을 인식하지 못하는 경우도 있습니다. 유형.

브라우저 캐시를 지우는 것은 항상 좋은 생각입니다.

도움이되는 경우 CentOS 5.9를 실행하는 서버의 /etc/httpd/conf.d/php.conf 파일 사본이 있습니다.

#        
# PHP is an HTML-embedded scripting language which attempts to make it                                             
# easy for developers to write dynamically generated webpages.                                                  
#
<IfModule prefork.c>
  LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
  LoadModule php5_module modules/libphp5-zts.so
</IfModule>

#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps

이것은 PHP에 필요한 모듈 누락으로 인해 발생할 수 있습니다. php7이 설치되어 있다고 가정하고 다음을 사용하여 사용 가능한 php7 모듈을 검색하십시오.

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

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...


I have the same problem. Apache doesn't load php files from a certain website, just downloaded it. I read this post and the answers and I have seen I've got this line into the last place of the .htaccess file:

AddHandler x-mapp-php5.5  .php

I have commented it and everything works fine.

Thanks to all !!!


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.


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

I had similar symptoms, yet another solution: in /etc/apache2/mods-enabled/php5.conf there was a helpful advice in the comment, which I followed:

# 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.

I spent two days tracking this and found out that I was putting my PHP scripts in the wrong directory.

On my standard Ubuntu installation, I was putting the scripts in /var/www. They should have been in /var/www/html.

I just started PHP work, so I don't know if my solution relates to the version change you went through.


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

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

sudo service apache2 restart


I had this problem. It turned out that I had both nginx and apache installed and automatically starting on boot. The problem was that nginx was binding to the http port first which prevented apache from starting.


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.


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.


If none of the above works,

try commenting out the line

SetHandler ....

and restart apache using

/etc/init.d/httpd restart

It should work!


PHP56

vim /etc/httpd/conf/httpd.conf

LoadModule php5_module        libexec/apache/libphp5.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

I got this kind of problem. This is how I solve it. After installed Apache then I installed PHP using this command.

sudo apt-get install php libapache2-mod-php

it executes correctly but I request .php file from Apache, it gives without executing the PHP script.

Then I check PHP is enabled.

$ cd /etc/apache2
$ ls -l mods-*/*php*

but it didn't show any results. I check installed PHP packages.

$ dpkg -l | grep php| awk '{print $2}' |tr "\n" " "

Different type of PHP versions installed to my computer. Then I remove some PHP packages from my previous list, using apt-get purge.

sudo apt-get purge libapache2-mod-php7.0 php7.0 php7.0-cli php7.0-common php7.0-json

I reinstall PHP

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

Verify that the PHP module is loaded

$ a2query -m php7.0

if not enabled with:

$ sudo a2enmod php7.0

Restart Apache server

$ sudo systemctl restart apache2

Finally, I check PHP process on Apache

create an empty file

sudo vim /var/www/html/info.php

Add this content to info.php & save.

<?php
  phpinfo();
?>

Check on browser:

http://localhost/info.php

it shows correctly.I think this will help anyone.


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.

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)


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

If Your .htaccess have anything like this

AddType application/x-httpd-ea-php56 .php .php5 .phtm .html .htm

참고URL : https://stackoverflow.com/questions/18422140/apache-is-downloading-php-files-instead-of-displaying-them

반응형