Why are my PHP files showing as plain text?

Why are my PHP files showing as plain text?

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

Stefan Bogdanescu

Founder & Senior Architect

Why are my PHP files showing as plain text?

When you move from an all-in-one stack like WAMP to a manual installation of Apache and PHP, the browser's behavior changes in ways that can look like a configuration error but are often just a mismatch between what the server expects and what your application sends. You installed the latest Apache and PHP 5, verified that localhost responds with an HTML page, and added a test.php file containing:

<?php
    phpinfo();
?>

Yet the browser renders the source code as plain text instead of executing the script. The immediate question is whether you need to explicitly tell Apache to use PHP 5 or if there's a deeper integration issue.

How Apache handles scripts

Apache doesn't automatically know how to handle files with a .php extension. By default, it treats them as static text files and serves their raw contents. To execute PHP, Apache must be configured to recognize the file type and invoke the appropriate handler. In modern setups, this usually involves an AddHandler or SetHandler directive pointing to the PHP binary (e.g., php-cgi), along with a matching MIME type definition for application/x-httpd-php.

If you installed Apache without integrating PHP, or if the integration was done incorrectly during setup, the server will simply serve the file as-is. This is why you see the opening <?php tag and the rest of the code in your browser window.

Checking your Apache configuration

The most direct way to diagnose this is to inspect the httpd.conf or your virtual host configuration files. Look for a line that handles PHP requests:

AddHandler application/x-httpd-php .php

or, if using the CGI approach:

SetHandler "application/x-httpd-php-cgi"

If neither of these directives exists, or if they reference a different PHP version than the one you installed (e.g., pointing to php7 while you have php5), Apache won't invoke the interpreter. Additionally, ensure that the MIME type for .php files is defined in your mime.types file:

application/x-httpd-php  .php

Without this mapping, even with a handler directive, the server might not pass the request to PHP correctly.

The mod_php vs CGI dilemma

A common pitfall when switching environments is mixing mod_php (PHP as an Apache module) with CGI-FastCGI setups. If you are using php-cgi, your Apache config must explicitly point to the .exe or binary path for PHP 5:

ScriptAlias /cgi-bin/ "C:/php/cgibin/"
DirectoryIndex index.php

And ensure that the AddHandler directive is correctly set. If you installed PHP via a package manager (like XAMPP or WAMP) previously, your httpd.conf might have been templated for that environment and not updated for your new standalone installation.

Verifying the correct PHP binary

You can confirm which PHP executable Apache is trying to use by checking the error logs. Look in C:\Apache24\logs\error.log (or wherever you installed Apache) for messages like:

[Mon Jan 01 12:00:00 2024] [error] PHP fatal error: unable to load ...

If the log shows a missing php.ini or a path mismatch, it confirms that Apache isn't finding your PHP 5 installation. You may need to adjust the PHPIniDir directive or ensure that the cgi-bin directory has execute permissions if you're using CGI mode.

Trade-offs and best practices

When configuring a standalone PHP setup, decide early whether to use mod_php or FastCGI. mod_php is simpler for small applications but ties Apache's performance directly to PHP execution. FastCGI (via php-fpm) decouples the processes and scales better under load, though it requires more configuration steps like defining a Unix socket or named pipe.

If you're building production-grade applications, consider using a reverse proxy (like Nginx in front of PHP-FPM) instead of relying solely on Apache for PHP handling. This pattern is common in high-traffic environments and provides better separation of concerns.

For development, if you want to avoid wrestling with httpd.conf directives every time, tools like Laravel Valet or Docker-based stacks can abstract away the server configuration entirely. These approaches let you focus on application logic rather than server-side MIME types and handlers.

Final check

To resolve the issue immediately: ensure your Apache configuration has a valid handler for .php files pointing to your PHP 5 binary, that the mime.types file includes the correct mapping, and that no conflicting modules are intercepting the request. Once these pieces align, refreshing the page will trigger phpinfo() correctly instead of dumping raw source code.

Our network