How to make Apache serve index.php instead of index.html?

How to make Apache serve index.php instead of index.html?

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

Stefan Bogdanescu

Founder & Senior Architect

Why Apache Ignores PHP Inside index.html

When you place a <?php include("/Live/ls_client/index.php"); ?> block inside an index.html file and expect Apache to execute that code, you are encountering a fundamental misunderstanding of how web servers handle file types. The reason your browser displays the raw text <!--?php include("/Live/ls_client/index.php"); ?--> is not a bug or a misconfiguration; it is the server correctly interpreting the MIME type based on the file extension.

Apache determines which handler to invoke for a request primarily by looking at the file extension. When a client requests index.html, the web server immediately identifies it as an HTML document and serves it with an application/html (or similar) MIME type. Because the content is treated purely as static text, the PHP module is never called upon to parse or execute any code found within that file. The PHP tags are rendered exactly as they appear in the source file.

To make Apache serve index.php logic instead of displaying the HTML container, you must change the entry point file itself. You cannot rely on a static .html file to trigger dynamic execution through simple inclusion statements unless you are using JavaScript to load the PHP file via an AJAX request, which changes the architectural pattern entirely.

If your goal is to have the root URL serve the contents of index.php, the solution lies in configuring the document root or adjusting the default index file settings. You can modify the .htaccess file in your web root (if you have access and allow overrides) to rename the default index file:

DirectoryIndex index.php

Alternatively, if you are working within a framework like Laravel or a custom application structure where index.html is currently acting as a shell for your PHP logic, the architectural approach needs shifting. Modern web development often separates static assets from dynamic entry points. If you strictly need to include one file into another on the server side before serving it, the standard practice is to make the outer file a .php extension rather than .html.

Rename your wrapper file to index.php:

mv index.html index.php

Now, when Apache receives a request for /index.php, it recognizes the extension and engages the PHP processor. The server will parse the <?php include("/Live/ls_client/index.php"); ?> statement, execute the inclusion logic, and output the resulting HTML to the client. This is the standard behavior expected by the Common Gateway Interface (CGI) protocol and how most frameworks operate.

There are scenarios where you might see raw PHP tags in an HTML file even when the extension is correct. This usually indicates that the php_flag or SetHandler directives are misconfigured, but in a standard Apache installation with default modules, the extension check is the primary gatekeeper. If your directory contains mixed static and dynamic files, ensure that you aren't inadvertently serving PHP scripts as plain text via URL rewriting rules that strip extensions prematurely.

If you are building a Single Page Application (SPA) where client-side routing renders views without server requests, using index.php for the initial load is often preferred to ensure the server can inject necessary meta tags or authentication tokens before handing control to the JavaScript router. This hybrid approach allows you to maintain SEO-friendly URLs while leveraging dynamic PHP entry points.

For those managing legacy systems where renaming files feels like a disruption, another option exists: configuring Apache to treat .html requests as if they were .php. While possible via SetHandler, this is generally discouraged because it creates ambiguity in your deployment structure and can break caching strategies that rely on file extensions. It is cleaner to align the file extension with the execution requirement.

Ultimately, the distinction between static and dynamic content is enforced by the server's MIME type mapping. By ensuring your entry point carries a .php extension, you guarantee that Apache routes the request through the PHP interpreter, allowing your include statements to function as intended without falling back to raw text output.

Our network