Apache shows PHP code instead of executing it

前端 未结 26 1849
爱一瞬间的悲伤
爱一瞬间的悲伤 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:07

    For PHP7 and Apache2.4, this is all you need to do:

    sudo vim /etc/httpd/conf/httpd.conf
    

    Go to the very bottom and insert the following (all by itself):

    
    SetHandler application/x-httpd-php
    
    

    Then, restart Apache to load the new configuration:

    sudo service httpd restart
    

    Apache will now execute all HTTP/S requests with PHP. If all you have are html, css, and php files, then this will work fine for you. If you have other languages running, then you'll need to tailor the file matching to your situation. I've tested this with phpMyAdmin and it works fine.

    None of that other stuff all the people are talking about here was necessary for me. When I put the "AddType Application....." thing in the correct spot, Apache just told me that that module was already loaded and skipped it.

    More information can be found here: https://httpd.apache.org/docs/2.4/mod/core.html#filesmatch

    My install was done as follows:

    sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd
    

    You should also read this, if you haven't: https://httpd.apache.org/docs/current/howto/htaccess.html#when

提交回复
热议问题