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

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

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

PHP Code Visible in Source Indicates Server-Side Execution Failure

When you open a .php file in a browser and the raw code—including <?php include_once(...); ?> tags—appears in the HTML source, the server is treating the file as plain text rather than executing it. This symptom almost always points to a misconfiguration of the web server or an incorrect file association, not a logic error within your PHP script itself. Since Apache is running on XAMPP and the files are being served correctly (you see them load), the issue is isolated to how the server interprets specific files.

The most common culprit is that the web server cannot find the PHP executable or is explicitly configured to disable PHP processing for certain directories or file types. In a standard XAMPP installation, this often happens if the LoadModule directive in Apache's configuration file (httpd.conf) has been commented out or disabled. Without this specific module loaded, Apache defaults to treating .php extensions as static files.

To resolve this, you must verify that the PHP handler is active. Open your primary Apache configuration file (usually located at C:\xampp\apache\conf\httpd.conf on Windows) and search for the line referencing PHP. You are looking for a directive similar to:

LoadModule php_module modules/libphp.so

If this line is preceded by a semicolon (;), the module is disabled. Remove the semicolon to enable the handler. However, enabling the module alone isn't always sufficient; Apache also needs to know which files should be processed by PHP. Look for the AddType or AddHandler directives associated with .php. Ensure it reads something like:

AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php

If these lines are missing or commented out, add them. This tells Apache to treat files ending in .php as PHP scripts rather than raw text. After making changes to httpd.conf, you must restart the Apache service in XAMPP Control Panel for the settings to take effect.

Another frequent cause is file permission issues or incorrect MIME type mappings defined in a .htaccess file within the project directory. If your project contains an .htaccess file with a directive like AddType text/html .php, it will explicitly force the browser to render the PHP code as HTML. Conversely, if you accidentally set the content type to text/plain, the browser might display source code depending on how strictly it renders non-executable scripts. Check your .htaccess file for any rules overriding the global Apache configuration regarding PHP handling.

It is also worth verifying that the PHP version bundled with XAMPP is compatible with your project requirements, though this rarely causes execution to fail entirely unless syntax errors occur. If you are using a specific PHP version via php-version.ini or similar overrides in XAMPP, ensure that the path to the libphp.so (or equivalent) matches the actual installed library.

If you have recently updated your project files or moved them to a new directory, ensure that no hidden characters or encoding issues are present at the very beginning of the file. Sometimes, invisible BOM (Byte Order Mark) characters can interfere with older PHP versions or specific server configurations, preventing execution. Save the file as UTF-8 without BOM in your editor (like Dreamweaver) to rule this out.

Finally, check the Apache error logs located in C:\xampp\apache\logs\error.log. If the configuration is correct but execution still fails, the logs will often reveal specific messages about syntax errors or module loading failures that are not visible in the browser. Reviewing these logs provides the definitive clue needed to pinpoint whether the issue lies with the server's ability to parse the script or with the script itself.

For developers looking for a robust alternative to managing complex PHP configurations across multiple environments, platforms like https://laravelcompany.com offer pre-configured development stacks that abstract away many of these low-level setup headaches, allowing you to focus on application logic rather than server modules.

Our network