Apache shows PHP code instead of executing it


I have recently been trying to install PHP and Apache on my computer. After many hours, they're installed. I have modified the httpd.conf and php.ini files like everyone says. I then created a simple PHP script:

<?php phpinfo(); ?>

But when I try to run it with it just shows the source code instead of executing it. I am using Apache 2, PHP 5 and Windows Vista.



short_open_tag = On


LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
PHPIniDir "C:/php"
7/1/2020 12:03:18 PM

Accepted Answer

You must enable php! Check the folder mods-enabled in the Apache directory (default: /etc/apache2/) to see if you find a file named php. I don't remember the extension but I think it's .so.

Also check in /var/log/apache2/error.log to see if you have any other errors.

2/21/2020 11:54:20 AM

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

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

Run this from the terminal:

sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7

Then don't forget to restart Apache so it knows you changed stuff:

sudo service apache2 restart

This is a summary from:


open the file


and change

#LoadModule php5_module libexec/apache2/


LoadModule php5_module libexec/apache2/

So just uncoment the PHP module load in httpd.conf


I found this to solve my related problem. I added it to the relevant <Directory> section:

<IfModule mod_php5.c>
    php_admin_flag engine on

A different answer that worked for me. Is that, to install [sudo] apt-get install libapache2-mod-php5.X


Alright if you've tried what you've been told above or earlier(which are possible reasons) and it still displays the code instead of executing it then there is one thing which you are doing wrong that hasn't been addressed. The url you used to access your php code; some people try to execute their php code by just dragging the .php file into the web browser. this is wrong practice and could lead to this kind of problem. if you have saved a file as "test.php" in the C://wamp/www folder then you must access this file this way: localhost://test.php. this kind of mistake will arise when you access it this way: localhost://wamp/www/test.php

Hope I helped someone out there. o/ ~Daniel