Home >Backend Development >PHP Tutorial >Why is Apache Downloading My PHP Files Instead of Displaying Them?
Solving Apache PHP File Download Issue
You are experiencing an issue where Apache is downloading PHP files instead of displaying them. This problem typically arises after a PHP upgrade and is often caused by incorrect configurations.
Configuration Changes
To resolve this issue, firstly, verify that you have the following lines in your httpd.conf:
AddHandler application/x-httpd-php .php AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
Secondly, in your php.conf, ensure the following lines are present:
<IfModule !worker.c> LoadModule php5_module modules/libphp5.so </IfModule> <IfModule worker.c> LoadModule php5_module modules/libphp5-zts.so </IfModule>
Correct AddType Directive
Ensure that the AddType directive for PHP is set to application/x-httpd-php, not text/html. The correct setting should be:
AddType application/x-httpd-php .php
Module Loading
Verify that your PHP module is loaded correctly. In your httpd.conf file, look for a line that starts with LoadModule. It should resemble the following:
LoadModule php5_module modules/mod_php55.so
Cache Issue
Clear your browser cache and try accessing the PHP page again. Chrome and other browsers can sometimes cache incorrect responses, leading to persistent download issues.
By implementing these configuration changes and ensuring that your PHP module is loaded, you should be able to resolve the issue and have Apache display your PHP files as expected.
The above is the detailed content of Why is Apache Downloading My PHP Files Instead of Displaying Them?. For more information, please follow other related articles on the PHP Chinese website!