CentOS 7 + PHP7 -- php not rendering in browser

33,382

Solution 1

That means that PHP isn't enabled in Apache. PHP addresses that here - step 8 should solve your problem.

As an addition: what I usually do on a new install, is install an entire LAMP-server. On Ubuntu, that's done with sudo apt-get install lamp-server^ (note: the caret is not a typo).

Solution 2

Fabien's answer worked for me, but apache started to serve css/js files with the wrong mime type. I fixed it adding this at the end of /etc/httpd/conf/httpd.conf

<FilesMatch \.php$>
 SetHandler application/x-httpd-php
</FilesMatch>

Solution 3

For PHP 7 (May apply to previous versions as well), but I had to do this:

Add this to the bottom of /etc/apache2/apache2.conf or for Centos /etc/httpd/conf/httpd.conf

SetHandler application/x-httpd-php

Share:
33,382
Didier Jean Charles
Author by

Didier Jean Charles

Updated on July 09, 2022

Comments

  • Didier Jean Charles
    Didier Jean Charles almost 2 years

    I have a clean install of apache/httpd and php7.1.0 running on CentOS 7.

    When I execute from the command line:

    php -v
    

    I get the expected response:

    PHP 7.1.0 (cli) (built: Dec  1 2016 08:13:15) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
    

    But when I try to hit my phpinfo.php page, all I get is... <?php phpinfo(); ?> literally outputted to the screen - can someone tell me what I'm missing, did I forget to enable a mod?

    enter image description here

  • Didier Jean Charles
    Didier Jean Charles over 7 years
    sweet that did the trick... It's frustrating that this wasn't done automatically...
  • treyBake
    treyBake over 6 years
    just a note: apt-get is for debian-based systems, not for CentOS ^^