-1

I have Joomla installed in my computer, but recently have been writing php files that aren't related to the Joomla-managed site. For some reason, when I try to open those php files in the web browser using xampp (note: Joomla also is using xampp), the browser doesn't process the code w/in the tags as php code.

For example, after opening a basic page (a page with title "test", no content except in the body tags) in the web browser and going to the source code, the following is shows up in the source code:

<body>
<?php echo "hello"; ?>

</body>

instead of the HTML conversion. (i.e. just "hello")

Does anyone have an idea about what's going on here?

Thanks.

jake
  • 19
  • 1
  • 1
  • 3
  • 6
    Browsers do **NOT** run PHP code. They simply accept HTML and render/display it. It's up to your webserver to run the PHP code, and since you're getting raw PHP code, your server is misconfigured. – Marc B Aug 03 '11 at 20:33
  • yes... it isn't the web browser's duty to process PHP – mike3996 Aug 03 '11 at 20:34
  • Seems like the file is not in the htdocs-directory...? And make sure it has a php extension and that the apache is running. And don't just open it, but call http://localhost/test.php if it's in htdocs. – Quasdunk Aug 03 '11 at 20:35
  • is the file a .phtml or .php file? – Nathaniel Wendt Aug 03 '11 at 20:35
  • Ok, it worked. I moved it to the htdocs-directory and called localhost/test.php. Why is it that you can't open php files from outside the htdocs directory? – jake Aug 03 '11 at 20:43
  • Because the 'htdocs' directory is the directory that is acting as the 'server', and since php is serverside it needs to be where the server can see it to process it appropriately. – Hanny Aug 04 '11 at 15:45

6 Answers6

3

It's probably because PHP module isn't loaded in your apache. Be sure it is enabled

genesis
  • 50,477
  • 20
  • 96
  • 125
2
  1. PHP is interpreted in the server, not the browser. Whatever's going wrong, you need to look at the SERVER side to resolve it.

  2. My first guess: maybe you didn't suffix the file ".php" (so the server doesn't recognize it as a PHP file?)

  3. Second guess: is the directory containing your PHP files configured to parse PHP?

If you have Joomla, you probably have PHP. You probably also have Apache.

So check your Apache configuration, and check your file naming conventions.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
1

Is the file extension .php? The server doesn't magically know when you're serving php files, this is a good way to ensure it knows what you're doing.

Cyclone
  • 17,939
  • 45
  • 124
  • 193
0

if the problem in php module it better to re install php5 in to the system and it will work fine. probably the problem is in php module you should try re installing php in your system.

learnwhat
  • 177
  • 2
  • 15
0

Just restart httpd service. It will work fine.

sudo systemctl restart httpd.service

if it has not worked please reinstall PHP once again.

0

Apache is looking into your localhost's defined root directory for files it can parse. In this case htdocs. This is the default for XAMPP. As far as Apache is concerned, it will not interpret any files outside of that folder.

user1934587390
  • 451
  • 5
  • 13