Home >Backend Development >PHP Tutorial >Why Is Apache Displaying My PHP Code Instead of Executing It?

Why Is Apache Displaying My PHP Code Instead of Executing It?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-22 20:25:14873browse

Why Is Apache Displaying My PHP Code Instead of Executing It?

Apache Rendering PHP Code Instead of Executing: Diagnosis and Resolution

In the described issue, PHP code is displayed on the browser instead of being executed by Apache. To resolve this, follow these troubleshooting steps:

Enable PHP Module:

  • Navigate to the mods-enabled folder in the Apache directory (typically /etc/apache2/).
  • Check if a file with a name like "php.so" or similar exists. If not, enable the PHP module by creating a symbolic link from the php5apache2_2.dll (or similar) file located in the PHP installation directory.

Verify HTTP Configuration:

  • Ensure that the AddType directives in the httpd.conf file are correctly configured:

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

Check PHPIniDir:

  • Ensure that the PHPIniDir directive in httpd.conf is set to the correct PHP installation directory, as in the example provided.

Check Error Logs:

  • Examine the error.log file in /var/log/apache2/ for any additional error messages that may indicate the root cause of the issue.

Additional Considerations:

  • Restart the Apache service after making any configuration changes.
  • Verify that the phpinfo() function is correctly implemented in the PHP script.
  • If using Windows, check that the PHP extension is enabled in the PHP Manager module.

The above is the detailed content of Why Is Apache Displaying My PHP Code Instead of Executing It?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:Adding Spaces to a StringNext article:Adding Spaces to a String