Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CentOS 7 + PHP7 -- php not rendering in browser

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

like image 535
Didier Jean Charles Avatar asked Jan 04 '17 15:01

Didier Jean Charles


People also ask

Why is PHP not showing in browser?

If you are loading the php file locally instead of running it from a webserver such as nginx or apache, then you will not get any php output. If you are running from a webserver, then it may not know how to interpret the php file. Read the documentation for your webserver to learn more about this.

Why PHP code is printing instead of executing?

If you are running your PHP script on a Windows computer, you need to manually install PHP. If you haven't already done so, your PHP code won't execute.

Why is my PHP page not working?

The most common reason for a blank page is that the script is missing a character. If you left out a ' or } or ; somewhere, your PHP won't work. You don't get an error; you just get a blank screen.


2 Answers

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

like image 86
Fabien Thetis Avatar answered Sep 22 '22 09:09

Fabien Thetis


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>
like image 38
fabianfiorotto Avatar answered Sep 19 '22 09:09

fabianfiorotto