By Gui

2011-02-25 19:06:51 8 Comments

I'm trying to execute some PHP code on a project (using Dreamweaver) but the code isn't being run.

When I check the source code, the PHP code appears as HTML tags (I can see it in the source code). Apache is running properly (I'm working with XAMPP), the PHP pages are being opened properly but the PHP code isn't being executed.

Does someone have a suggestion about what is happening?

Note: The file is already named as filename.php

Edit: The Code..:


The print


@yasin lachini 2019-04-28 05:47:23

the file that you put in /var/www/html/ should have .php forexample example.php if it is example it is not working but if you change it to example.php it works.

@Hasan Baig 2016-12-06 13:36:41

You're just opening your php file into browser. You have to open it using localhost url. if you open a file directly from your directory it will not execute the php code in any case.

use: http://locahost/index.php or http:

Enable php short code. In your case, you are using <? which is php short code for <?php. By default php short codes are disabled.

Also use: sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt if you are a ubuntu user.

@Gui 2016-12-06 16:20:27

Why is mcrypt required when i'm just including a file? You should noticed that this question is old and the short tags issue was mentioned 16 times, also in the top comment of my question.

@Hasan Baig 2016-12-07 07:43:12

I just share my solution, I was also facing the same error and after executing this command of mcrypt my issue solved. you may also try.

@zond 2017-01-26 13:38:23

by default php short codes are enabled. short_open_tag=On (Default Value=ON) in php 5.6

@Hayden Thring 2019-01-15 20:14:02

This was my problem, my virtualmin/apache configuration was for but i was putting my external ip address in the browser, i just updated my v/a config and now its working

@sh6210 2018-10-03 04:49:47

in my case (Apache/2.4.34),

after uncommenting the specific module

"LoadModule php7_module libexec/apache2/"



my problem was gone.

@bobble bubble 2018-09-06 14:36:12

Just spent hours of trying to get PHP 5 to run with Apache 2.4 on Windows 10. Finally for me it was a typo in httpd.conf LoadModule. Drew attention to writing and exact module path through the last answer in this apachelounge thread of denny2018. Thank you!

After two nights I discovered... My directory was written c: (lower case)

I had LoadModule php5_module "c:/php/php5apache2.dll" but correct for apache 2.4 is:

LoadModule php5_module "C:/php/php5apache2_4.dll"

So I also missed the _4 before (for apache 2.4). The full snippet that worked for me:

LoadModule php5_module "C:/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
<FilesMatch \.php$>
    SetHandler application/x-httpd-php

Just tried PHP 7. There the LoadModule line in httpd.conf for Apache 2.4 reads

LoadModule php7_module "C:/php/php7apache2_4.dll"

Currently php manual shows up c:/php/php5apache2.dll which of course needs to be adjusted.

@AamirR 2018-06-08 16:49:15

I faced this issue on php 7.1 that comes with High Sierra (OS X 10.13.5), editing /etc/apache2/httpd.conf with following changes helped:

  1. Uncomment this line

    LoadModule php7_module libexec/apache2/
  2. Paste following at the end

    <IfModule php7_module>
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps
        <IfModule dir_module>
            DirectoryIndex index.html index.php

@Gem 2019-01-09 07:00:26

Like same can you pls suggest Wamp 3 version same error. There is no /etc/apache2/httpd.conf folder path in wamp 3. @AamirR

@Barmar 2018-06-01 04:42:23

Make sure the script contains


before the code that should be executed. There should be no space between <? and php in this.

@Ashahmali 2018-05-04 13:56:39

Add AddType application/x-httpd-php .php to your httpd.conf file if you are using Apache 2.4

@Chaitanya Shivade 2013-12-04 23:34:16

Check all the packages you have installed for php using:

yum list installed | grep remi

Install all relevant php packages, especially php-devel on your machine.

@user3890355 2018-02-27 14:21:46

If you have configuration like this:

<VirtualHost *:80>
    DocumentRoot "/var/www/"

    <FilesMatch "\.php$">
        SetHandler "proxy:fcgi://"

Uncomment next lines in your httpd.conf

LoadModule proxy_module lib/httpd/modules/
LoadModule proxy_fcgi_module lib/httpd/modules/

It works for me

@shmeeps 2011-02-25 19:15:56

Sounds like there is something wrong with your configuration, here are a few things you can check:

  1. Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run php -v from a command line and see if returns version information or any errors.

  2. Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like LoadModule php5_module "c:/php/php5apache2_2.dll" in the file. Search for LoadModule php, and make sure that there is no comment (;) in front of it.

  3. Make sure that Apache's httpd.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.

  4. Make sure your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.

  5. Make sure you are not using short tags in the PHP file (<?), these are not enabled on all servers by default and their use is discouraged. Use <?php instead (or enable short tags in your php.ini with short_open_tag=On if you have code that relies on them).

  6. Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

And lastly check the PHP manual for further setup tips.

@MatuDuke 2012-07-25 02:03:53

Don't know why, but installer of PHP 5.3.15 doesn't add the line AddType application/x-httpd-php .php. Thanks a lot!!

@WebDevDanno 2013-05-22 14:25:18

I need to enter the AddType mentioned but the file is read only. How can I overcome this and write a new line into it?

@ClarkeyBoy 2013-10-28 16:35:27

@shmeeps: Where have you seen that short tags are deprecated? I've done some searching and can only find recommendations against them, nothing about deprecation. Granted for applications which are to be distributed it is better to use <?php in case the hosting server doesn't have them enabled, but for apps where you have full control over the server they're going to be on I don't see any reason not to use them.

@KawaiKx 2014-07-06 15:24:49

point no 6 worked for me.. local access doesn't use the apache server

@ulkas 2014-09-16 20:41:25

point 2 worked for me the safe way - apt-get purge apache2; apt-get install apache2 libapache-mod-php5

@fregante 2014-10-04 14:52:42

@ClarkeyBoy you're correct. Short tags were not deprecated, I fixed the answer.

@dangel 2014-12-27 02:22:43

short tags weren't working here, (server 2008), need to research why, but at least I know

@giannis christofakis 2015-12-21 21:11:28

I checked httpd.conf and the line LoadModule php5_module "c:/php/php5apache2_2.dll" is missing. Isn't that weird or not? Anyway, should I added myself ? I also saw in other sites that you should uncomment line LoadModule php5_module modules/, is this something different? Windows user here.

@dnep 2016-02-17 19:11:52

Point #5 did the trick. Already had a complete website using short tags.

@full_prog_full 2016-04-16 21:21:52

how to check point #1 on a shared server?

@shmeeps 2016-04-18 03:29:55

@full_prog_full Try uploading a file with a .php extension with the contents <?php echo("Success"); ?> and see if accessing the file through a web browser results in "Success" being displayed without the associated PHP code.

@EricC 2016-05-19 20:12:26

point #3 worked for me. Any idea why this is needed?

@Black 2017-03-07 10:38:43

There is no file called httpd.conf on my whole system. I searched with find / -name "httpd.conf"

@coderatchet 2017-03-09 00:07:17

@ulkas in ubuntu 16.04, for apache2 and php7, I installed sudo apt-get install libapache2-mod-php7.0 and it automatically configured my mods-enabled folder for php use.

@Quentin 2017-08-11 09:32:54

Given the command line and web server installs of PHP are often independent, I don't think point 1 is very useful. Also, given the reactions of people who ask this FAQ, point 6 should probably be upgraded to point 1.

@alper 2018-05-16 17:10:38

What should I do if there is no Apache's httpd.conf @shmeeps

@skiabox 2018-10-16 12:53:56

Point #3 did the trick for me! Thank you very much!!!

@FrankerZ 2019-03-13 13:26:23

I would clarify point #5, and mention that users should ensure their code starts with <?php.

@user2345998 2019-07-03 14:29:35

Why is AddType set to "application/x-httpd-php" and not to "text/html"? The docs say AddType is to set the mime type for browser; so "text/html" would be right.

@Eric Libay 2017-06-16 03:03:10

For fresh setup of LAMP running php 7 edit the file /etc/httpd/conf/httpd.conf Note: make sure to make backup for it before changing anything.

Paste this at the very bottom of the file:

<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
    DirectoryIndex index.html index.php

Then, search for LoadModule and paste the following line:

LoadModule php7_module modules/

This line will simply ask httpd to load the php 7 module

Then restart httpd

@sj59 2017-02-06 15:06:40

php7 :

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.0-fpm
sudo service apache2 restart

@Toby Speight 2017-02-06 18:31:37

While this code snippet may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post. Remember that you are answering the question for readers in the future, not just the person asking now! Please edit your answer to add explanation, and give an indication of what limitations and assumptions apply.

@Raymond Nijland 2017-04-24 11:53:56

This answer is linux related the topicstarter is clearly using windows.

@Goose 2017-05-05 20:57:40

@RaymondNijland true but this is canonical and I found this question and it saved me after over an hour of troubleshooting.

@Talvi Watia 2017-11-21 12:49:02

How and Why: This happens when PHP7 doesn't configure the default fast-CGI service in the make script. sudo a2enmod proxy_fcgi setenvif creates three new mods /mods-available/proxy.conf proxy_fcgi.load proxy.load Likewise, sudo a2enconf php7.0-fpm creates a config file /conf-available/php7.0-fpm.conf Once this is done and Apache2 can then run the PHP7 module as a fast-CGI service.

@zzapper 2018-01-20 23:41:55

worked for linux mint

@Jahmic 2016-12-04 13:40:47

This was in my .htaccess

DirectoryIndex index.html index.htm

index.html contained PHP code. By default, PHP won't process files with extentions like htm* as PHP code.

You can override this, by adding the following to .htaccess:

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

@albertski 2016-12-02 23:01:36

I had a case that I accidentally started untaring my files directory in root. It added the .htaccess file from my files folder that would block all php

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php5.c>
  php_flag engine off

Bottom line check the .htaccess file on root.

@b.g 2016-10-17 05:46:08

Reinstalling the mcrypt module worked for me.

$sudo apt-get install php5-mcrypt
$sudo php5enmod mcrypt

@b.g 2016-10-17 13:06:23

It honestly did, maybe because I hadn't configured the PHP properly on my system.But, since the question I asked regarding the same issue has been marked as a duplicate to this question, I only could answer it here. I wonder why the down vote.

@Raymond Nijland 2017-04-24 11:55:25

This answer is linux related the topicstarter is clearly using windows

@EdC 2016-08-15 09:32:59

note for php 7 users, add this to your httpd.conf file:

# PHP 7 specific configuration
<IfModule php7_module>
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    <IfModule dir_module>
        DirectoryIndex index.html index.php

@Ahmed Sagarwala 2018-08-14 19:07:06

Just to help other people with this issue. The httpd.conf file is located in /etc/apache2/httpd.conf If you're using Ubuntu, it would be apache2.conf in the same directory that needs to be modified for PHP7.

@ndasusers 2016-06-12 11:04:29

This just happened to me again, along with the server downloading html files, rather than processing. I had not use the webserver apache for some time on the computer and meanwhile Ubuntu updated like two more versions from originally installed LTS. Now it is

$ cat /etc/issue
Ubuntu 16.04 LTS

So the php worked after like so:

$ sudo apt-get install lamp-server^
$ sudo a2enmod php7.0
$ sudo service apache2 restart 

The webserver was now parsing the php. Maybe now got to update some webs since php7.0 now running where as it was before running php5. Oh well.

@RozzA 2017-05-10 21:38:26

you just reinstalled entire server..

@Nav 2016-05-27 01:02:52

I think the problem that it is showing code instead of the result is that it is not going to local host . recheck what address u r going in. are u going to a local file directory or to the local host.

from the screenshot u sent it is going to ur computer not to the localhost.

"file:/// " it should be "localhost/"

@Rogelio 2016-03-28 19:16:15

on my ubuntu 14.04, apache 2.4, php 5.5.9 install, I tried with a sample.php on /var/www/html (default document root) and it worked ok. So the problem was on my Virtual Servers config. The solution was to include, on the Directory def containing the .php, this line:

    php_admin_flag engine on

@suresh pareek 2017-08-21 12:45:48

and where should I add this line in Apache file in httpd.conf of my virtual server? and I am using Webmin

@Matt McDonald 2013-03-19 13:34:11

I'm running Apache on Ubuntu and my issue was that the /etc/apache2/mods-available/php5.conf file was missing this:

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler application/x-httpd-php

I added it back in and php was parsing php files correctly.

@Netrus 2016-03-20 17:59:11

i had similar problem but in my case solution was different. my file that held php code was called "somename.html" changed it to "somename.php" worked fine

@full_prog_full 2016-11-10 14:42:59

This also solved it for me. Does anyone know if the sever will execute php in a .html file or does the file ending always have to be changed to .php when there's a line of php to be executed?

@Netrus 2016-12-04 16:49:39

depends upon the server settings, for most cases php code that existing in anyfile.html will execute. and if it does not, it can be changed, although idk how :P

@Gui 2011-02-25 19:38:01

I've solved this by uninstalling XAMPP, and installing WAMP. Thanks for the help.

@Pie 2019-06-13 18:18:28

I am xampp but it works fine. did you find why it was showing php code @Gui

@user3257072 2014-01-31 11:15:08

I know it should sound silly... but seldom it happens.

Check if you are trying to execute php from


and not from


ps> you can notice that if you write from shell

php info.php 

it answer with the code (it means php functions)..

@muaaz 2015-06-17 08:08:57

PHP works fine (checked using command line). but, when I access the file using URL, it shows PHP code.

@Henry van Megen 2013-10-15 17:58:26

I'm posting this answer because my Virtualmin/Webmin admin interface decided it was a good idea to disable my PHP engine.. took me a while to find the solution, so I thought I'd share it with you guys:

Also, be sure to check that none of your website config files related to this specific host or virtualhost have any php_admin_value's in them that turn off PHP, like this:

php_admin_value engine Off

When in doubt, comment it...

# php_admin_value engine Off

And restart your webserver.

@cronoklee 2016-07-27 14:43:53

Where are these config settings exactly?

@Sheepy 2016-09-09 03:43:44

@cronoklee In vHost settings of httpd.conf. For existing hosts, you need to edit apache config in webmin. For future hosts, go to virtualmin > server template > apache website. Eitherway, this is not as secure as fastcgi - virtualmin's default. So the correct approach should be to troubleshoot why fcgi doesn't work, for example it may be caused by file permissions.

@Sam Malayek 2016-10-20 22:53:10

If you're using a version of Apache that doesn't have httpd.conf, look in /etc/apache2/mods-enabled/php7.conf or php5.conf

@Henry van Megen 2018-05-23 11:05:05

When in doubt about the location of a certain configuration setting, you can always use grep to find what you're looking for by (for example in this case) typing: sudo grep php_admin_value /etc/* -R

@Arrvi 2013-04-04 18:17:45

I found another problem causing this issue and already solved it. I accidentally saved my script in UTF-16 encoding. It seems that PHP5 can't recognize <?php tag in 16 bit encoding by default.

Related Questions

Sponsored Content

27 Answered Questions

[SOLVED] How do I get PHP errors to display?

16 Answered Questions

[SOLVED] Why shouldn't I use mysql_* functions in PHP?

  • 2012-10-12 13:18:39
  • Madara Uchiha
  • 208362 View
  • 2405 Score
  • 16 Answer
  • Tags:   php mysql database

37 Answered Questions

[SOLVED] Deleting an element from an array in PHP

  • 2008-12-15 20:28:55
  • Ben
  • 2377743 View
  • 2316 Score
  • 37 Answer
  • Tags:   php arrays unset

31 Answered Questions

[SOLVED] startsWith() and endsWith() functions in PHP

  • 2009-05-07 12:14:27
  • Click Upvote
  • 789942 View
  • 1383 Score
  • 31 Answer
  • Tags:   php string

18 Answered Questions

[SOLVED] Reference — What does this symbol mean in PHP?

28 Answered Questions

[SOLVED] How can I prevent SQL injection in PHP?

7 Answered Questions

[SOLVED] How does PHP 'foreach' actually work?

30 Answered Questions

[SOLVED] Convert HTML + CSS to PDF with PHP?

30 Answered Questions

[SOLVED] How do you parse and process HTML/XML in PHP?

5 Answered Questions

[SOLVED] Why PHP include is working on local server and not on website

Sponsored Content