apache php

PHP code is not being executed, but the code shows in the browser source code


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

The Code..:


The print


  • 54

    Are you using short tags <? instead of <?php?

    Feb 25, 2011 at 19:09

  • 38

    Don’t EVER use short tags. ( <? ). They are deprecated, don’t really work in a lot of places, and are otherwise completely unneccessary. Saving three keystrokes is not a valid reason to allow potential for your code to fail on probably half of the servers it may run on.

    – mopsyd

    Feb 11, 2015 at 19:53

  • 14

    @mopsyd Where does it say that short tags are deprecated? Please note that short tags are not the same as short echo tags, and short echo tags have been supported by default since PHP 5.4, regardless of the short_open_tag setting.

    Mar 15, 2016 at 19:23

  • 6

    I am aware that short tags are not short echo tags, which is why I specified which I was talking about in the comment. At the time of writing, short tags were flagged for deprecation for the php 6 release, though that has apparently changed since. The problem still exists that a lot of servers have them disabled, which makes your code significantly less portable. This does not apply to short echo tags (<?=), which should run fine on php 5.4+ regardless of server settings.

    – mopsyd

    Mar 18, 2016 at 0:44

  • 5

    silly talk about short tags. Long tags suck and they’re ugly. I’ve never had a problem in 10 years of php programming. They are almost never the problem

    – Danial

    Dec 7, 2016 at 21:35


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.


  • 19

    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!!

    – MatuDuke

    Jul 25, 2012 at 2:03

  • 8

    @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.

    Oct 28, 2013 at 16:35

  • 3

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

    – KawaiKx

    Jul 6, 2014 at 15:24

  • 9

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

    – ulkas

    Sep 16, 2014 at 20:41

  • 3

    @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.

    – shmeeps

    Apr 18, 2016 at 3:29


php7 :

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


  • 38

    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.

    Feb 6, 2017 at 18:31

  • 6

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

    Apr 24, 2017 at 11:53

  • 4

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

    – Goose

    May 5, 2017 at 20:57

  • 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.

    Nov 21, 2017 at 12:49

  • Please add an explaination

    – tmath

    Oct 12, 2020 at 0:12


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.