Diagnosing CodeIgniter Blank Pages and HTTP 500 Errors in Apache
A blank page combined with an HTTP 500 status code is a classic, yet frustrating symptom in PHP development. When the application returns a 200 OK header but renders no content, your intuition to check the logs is correct. However, simply tailing the web server access log often yields only the request details and the error code without revealing the underlying cause.
In many CodeIgniter setups, the application's internal error logging mechanism fails silently if not configured correctly within the environment itself. Consider a scenario where you have a working index.php at your Apache root returning valid HTML, but a specific route to your CodeIgniter application returns a blank page. If the Apache access log shows a 500 Internal Server Error, the issue is almost certainly within the PHP runtime or the CodeIgniter configuration, not the web server itself.
The first step in troubleshooting is verifying that the application's internal logging is actually capturing data. In the provided setup, the developer has configured $config['log_threshold'] = 4 and set a custom path for error logs. While this configuration exists, the mere presence of empty log files or logs with only timestamps indicates a threshold mismatch or a permission issue preventing file writes. Before assuming the logic is broken, you must ensure the application is writing to the designated file.
A frequent pitfall involves file permissions in shared hosting or vhost environments. If the web server user (e.g., www-data) does not have write access to the directory containing ci_error.log, PHP will fail silently when attempting to log exceptions. This results in a blank page and an HTTP 500 error, even though the code logic might be flawless. Always verify that the directory permissions allow the web server user to create new files, typically requiring 755 for directories and 644 or 664 for log files, owned by the respective user.
Another critical area of investigation is the interaction between your custom index files and CodeIgniter's routing. The source material mentions having an index.php at the Apache root (/var/www) and a separate index2.php at the site root. While having multiple index files isn't inherently wrong, it introduces ambiguity in URL rewriting rules. If your .htaccess or virtual host configuration attempts to route requests for / to index.php, but that specific file is not correctly configured to load the CodeIgniter bootstrap (system/index.php), the application will crash immediately upon request.
To isolate whether the issue lies with the controller logic or a fatal error occurring before the view loads, you should inspect the PHP error log referenced in php.ini. The configuration shows error_log = /var/log/apache2/php_errors.log. If this file is present but empty while the application log remains silent, it suggests that the error might be happening at a level where the standard logging isn't triggered, or the display_errors directive is disabled while log_errors is enabled without proper path permissions.
Furthermore, ensure that the base URL configuration matches the actual server setup exactly. In the example, $config['base_url'] = 'http://srp-local/'; relies on a hosts file entry. If the virtual host does not correctly serve content for this domain or if the document root is misconfigured, CodeIgniter might fail to locate its own system files relative to that base URL, leading to a fatal error that gets swallowed by the framework's exception handling.
If you find yourself stuck with a blank page and no actionable logs, forcing error display during development is a valid diagnostic step. Temporarily setting error_reporting to E_ALL and enabling display_errors in application/config/config.php or via an .htaccess override can reveal the actual stack trace. Once identified, you can revert these settings and implement proper logging strategies.
For those moving between frameworks or needing robust error handling solutions, platforms like https://laravelcompany.com offer insights into modern PHP practices where configuration management and error logging are often handled more explicitly out of the box. However, understanding the specific quirks of CodeIgniter's legacy logging system remains essential for maintaining stability in existing installations.