Home >Backend Development >PHP Tutorial >Why is my PHP file displaying as plain text on localhost?

Why is my PHP file displaying as plain text on localhost?

DDD
DDDOriginal
2024-11-16 01:16:03679browse

Why is my PHP file displaying as plain text on localhost?

How to Resolve Raw PHP Text Display on Localhost

When developing PHP applications locally, you may encounter an issue where your PHP files are displayed as plain text in the browser. This can be frustrating, as it prevents you from viewing the actual output of your PHP code.

Problem Description:

  • Attempts to install PHP and Apache HTTP Server standalone on a work PC
  • PHP 5 is installed along with the latest Apache server
  • Test.php file is created, containing PHPinfo() code
  • Localhost displays test.php file as plain text

Solution:

The root cause of this issue is the absence of the PHP 5 library for Apache. To resolve it, you need to install this library.

Library Installation Steps:

For Debian and Ubuntu:

  1. Open Terminal and execute the following command to install the library:
apt-get install libapache2-mod-php5
  1. Restart the Apache server:
service apache2 restart

Confirmation:

Once you have installed the PHP 5 library for Apache and restarted the server, your PHP files should now be parsed and executed properly. Navigate to your test.php file in the browser and verify that the PHPinfo() output is displayed as expected.

The above is the detailed content of Why is my PHP file displaying as plain text on localhost?. 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