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
Release: 2024-11-16 01:16:03
Original
594 people have browsed it

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
Copy after login
  1. Restart the Apache server:
service apache2 restart
Copy after login

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template