Diagnosing the Silent PHP Failure on Apache
A blank page in a browser is one of the most frustrating symptoms in web development. It feels like the server is ignoring your requests, yet standard diagnostics often fail to reveal why. You might see phpinfo() output nothing, static HTML files load perfectly, and CLI execution works fine, but anything with a .php extension vanishes into thin air.
Consider a scenario on a CentOS DigitalOcean droplet where Apache and PHP 5.3 are installed. The httpd service is running, confirmed by checking the PID. Static .html files serve correctly with a 200 response code. However, visiting any PHP file results in a white screen. Even worse, the browser never sends a request for the PHP file; Apache's access log remains silent regarding these specific paths.
This behavior points to a configuration mismatch rather than a runtime crash. The key clue lies in the interaction between Apache's handler directives and how it processes filenames.
The Handler Mismatch
In the httpd.conf file (or included via conf.d/*.conf), the setup typically includes:
AddHandler php5-script .php
AddType text/html .php
The first line, AddHandler, tells Apache to pass files ending in .php to the PHP module for execution. The second line, AddType, is where the issue usually hides. By explicitly setting the MIME type of .php files to text/html, you are instructing Apache to serve these files as static HTML documents before the content handler (PHP) has a chance to process them.
When Apache receives a request for index.php:
- It checks the file extension.
- Because
AddType text/html .phpexists, Apache immediately decides, "This is an HTML document," and serves the raw file contents if they were static. - However, because PHP execution requires a specific handler (
php5-script), the conflict arises when the MIME type directive overrides or interferes with the processing logic expected by the module. In many configurations, particularly on older setups like PHP 5.3, this directive can effectively bypass the script processor entirely, resulting in the server not logging the request as a dynamic execution and potentially returning an empty response if the file parsing fails silently or if the content is interpreted differently than expected.
Resolving the Configuration
To fix this, you must remove the AddType text/html .php line from your Apache configuration files. The correct configuration should look like this:
AddHandler php5-script .php
# Remove or comment out the following line to allow PHP execution:
# AddType text/html .php
By removing that line, Apache reverts to its default behavior for .php files, which is to treat them as scripts requiring execution by the registered handler. Once you apply this change and restart Apache (service httpd restart), the phpinfo() page should render correctly, and the access logs will begin recording GET requests for your PHP files with a 200 status code.
Verifying Error Reporting
If the blank page persists after fixing the MIME type, ensure your error logging is actually capturing output. In the source scenario, the user set display_errors = On in php.ini. While this controls what appears on the screen, it does not prevent Apache from failing to pass the request if the handler is misconfigured.
Additionally, check the log location specified in php.ini:
error_log = syslog
If logging is set to syslog, verify /var/log/messages or journalctl. However, since the access logs showed no GET requests for PHP files at all, the root cause was almost certainly the handler configuration preventing Apache from even recognizing the file as a script needing execution.
For modern Laravel projects hosted on similar infrastructure, this same principle applies. If you are using a production environment where error pages must be hidden and logged securely, ensure your .htaccess or virtual host configuration does not inadvertently set MIME types that bypass the PHP handler. While laravelcompany.com often provides robust deployment guides for such scenarios, understanding these underlying Apache directives ensures you can troubleshoot issues regardless of the framework used.
