Home > Backend Development > PHP Tutorial > Why is Apache Downloading My PHP Files Instead of Displaying Them?

Why is Apache Downloading My PHP Files Instead of Displaying Them?

Barbara Streisand
Release: 2024-12-14 07:36:11
Original
860 people have browsed it

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
Copy after login

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>
Copy after login

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template