Apache shows PHP code instead of executing it

前端 未结 26 1574
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 02:23

I have recently been trying to install PHP and Apache on my computer. After many hours, they\'re installed. I have modified the httpd.conf and php.ini files like everyone sa

相关标签:
26条回答
  • 2020-11-22 03:21

    Alright if you've tried what you've been told above or earlier(which are possible reasons) and it still displays the code instead of executing it then there is one thing which you are doing wrong that hasn't been addressed. The url you used to access your php code; some people try to execute their php code by just dragging the .php file into the web browser. this is wrong practice and could lead to this kind of problem. if you have saved a file as "test.php" in the C://wamp/www folder then you must access this file this way: localhost://test.php. this kind of mistake will arise when you access it this way: localhost://wamp/www/test.php

    Hope I helped someone out there. o/ ~Daniel

    0 讨论(0)
  • 2020-11-22 03:22

    I had the same problem, caused by the Debian/ Ubuntu default configuration of module suphp. It contained suPHP_Engine off for whole /usr/share, which resulted in the php sources being shown in the browser. Deactivating with a2dismod suphp was the interim solution.

    0 讨论(0)
  • 2020-11-22 03:23

    I had the same problem. When I run a php file, the web browser showed me the php code instead of execute it. I had tried many times: uninstall/reinstall the wampserver64, working around the PHP/Apache settings/modules, etc. After 2 days: I realised that when I tried to run the php file within the notepad++ by pressing the default combination "ctrl + alt + shift + R" for chrome. It was trying to execute my php file like: "file///C:/wamp64/www/bla/bla.." in my chrome's address bar. That was my problem. I made the changes according to page Configuring Notepad++ to run php on localhost?. My problem was solved. But after 2 days..

    0 讨论(0)
  • 2020-11-22 03:24

    I found this to solve my related problem. I added it to the relevant <Directory> section:

    <IfModule mod_php5.c>
        php_admin_flag engine on
    </IfModule>
    
    0 讨论(0)
  • 2020-11-22 03:26

    You could delete your .htaceess file and let the system creates a new (blank or basic) one. It may be that some lines you added are incorrect statements, or something else inside is causing the problem. You can then add line by line from your old .htaccess file to see what caused the problem.

    That worked for me. The lines telling machine not to display php extensions were problem in my case (RewriteCond and RewriteRule). My old .htaccess file worked just fine on a shared server, but this issue appeared when I switched to VPS.

    0 讨论(0)
  • 2020-11-22 03:26

    I tried a number of the solutions above however the fix in our scenario was to install the fpm-module.

    We had installed httpd before php which may have had something to do with the issue, but to resolve we installed the following:

    yum module install php:7.2

    This installed the php-fpm-7.2.11-4.module+el8.1.0+5443+bc1aeb77.x86_64.rpm module which we then enabled by:

    systemctl enable --now php-fpm

    From that point we left the /etc/httpd/conf.d/php.conf as default and restarted httpd

    service httpd restart

    Then everything worked.

    Hope this helps, took way longer than it should have to figure out.

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