PHP code is returned instead of executed

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I have L-Ubuntu 11.04. I've installed Apache2 and I'm trying to simulate a server on my local file system by navigating to localhost in the browser.

The problem is that I can't seem to get php to execute when on localhost. The PHP code is simply printed in the browser (instead of being executed and the result being printed).

  • libapache2-mod-php5 is installed and the latest version.
  • The Apache module php5 is enabled.

How can I get PHP to run on localhost?

profilepic.png
manpreet 2 years ago

The configuration file /etc/apache2/mods-available/php5.conf controls which files Apache recognizes as php scripts (based on their extensions).

Be default (in PHP 5.3.2), the file contains the following code:


    SetHandler application/x-httpd-php

This affects files with the following extensions:

From our discussion in chat, I know that your files have a html extension. The server was configured to treat .html files as php files, but your home computer is not. That leaves you with two options:

  1. Rename your .html files that contain php code to one of the above extensions.

  2. Replace the line

    
    

    in your php5.conf by

    
    

    and reload apache by executing the following command:

    sudo service apache2 reload
    

    In addition to the previously mentioned extensions, the new configuration also affects:

    • .htm
    • .html

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.