Why are my php files showing as plain text? duplicate Ask Question 71. But in the browser it just displays plain text. Is there somewhere I have explicitly tell it to use PHP5? Thanks a lot. Laravel showing code of index.php on home page. Jul 06, 2017 Website displaying in plain text. On May 30, 2012 at 06:19 UTC. Next: Chrome 75 blocks. Unless his web filter is managed down to the user level, it may not be related. I had the same problem wit my IE9 showing text only and not displaying any graphics but I was able to fix the problem in a few seconds.
This question already has an answer here:
- PHP code is not being executed, instead code shows on the page 25 answers
I've been writing php apps using php for a while in wamp. Now I'm installing PHP & apache separately on my work PC. I've installed PHP 5, and the latest apache. I go to localhost and see it works! now I add a file called test.php which displays:
but in the browser it just displays plain text. Is there somewhere I have explicitly tell it to use PHP5?
Thanks a lot
Charles46.2k1212 gold badges8989 silver badges127127 bronze badges
iamjonesyiamjonesy10.6k3737 gold badges124124 silver badges196196 bronze badges
marked as duplicate by bummi, andrewsi, John Slegers, jbafford, PurkkaKoodariFeb 7 '16 at 15:00
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
7 Answers
You'll need to add this to your server configuration:
that is assuming you have installed php properly, which may not be the case since it doesn't work where it normally would immediately after installing.
It is entirely possible that you'll also have to add the php so/dll to your apache config using a
KrisKrisLoadModule
directive (usually in httpd.conf
)29.4k88 gold badges6464 silver badges9292 bronze badges
You should install php5 lib for apache
for debian and ubuntu:
apt-get install libapache2-mod-php5
and restart the apache
davdavservice apache2 restart
5,67466 gold badges5555 silver badges111111 bronze badges
You need to configure Apache (the webserver) to process PHP scripts as PHP. Check Apache's config, you need to load the module (the path may differ on your system):
and you also need to tell Apache what to process with PHP:
Cœur21.1k1010 gold badges120120 silver badges168168 bronze badges
PiskvorPiskvor73.3k4141 gold badges159159 silver badges210210 bronze badges
Yet another reason (not for this case but maybe it'll save some nerves for someone) is that in php 5.5 short open tags
Roman BekkievRoman Bekkiev<? phpinfo(); ?>
are disabled by default. So php interpreter would process code within short tags as a plain text. In previous versions php this feature was enable by default. So new behaviour can be little bit mysterious. 1,89611 gold badge1313 silver badges2222 bronze badges
You might also, like me, have installed php-cgi prior to installing Apache and when doing so it doesn't set up Apache properly to run PHP, removing PHP entirely and reinstalling seemed to fix my problem.
user3604332user3604332
You will need to add handlers in Apache to handle php code.
Edit by command sudo vi /etc/httpd/conf/httpd.conf
Add these two handlers
at position specified below
for more details on AddType handlers
http://httpd.apache.org/docs/2.2/mod/mod_mime.html
MysticForce48111 gold badge77 silver badges2222 bronze badges
SatyanarayanaSatyanarayana
Are you using the userdir mod?
In that case the thing is that PHP5 seems to be disabling running scripts from that location by default and you have to comment out the following lines:
in
/etc/apache2/mods-enabled/php5.conf
(on a ubuntu system)Henrik SommerlandHenrik Sommerland