1

I am trying to install Apache on my Mac (OSX 10.8.2).

I am using MAMP, it runs, but whenever I try to view a page (html or php) other than the phpinfo.php, I only see the source code.

There are no errors in the log file.

I have also tried with the pre-installed webserver, same result. Same for XAMP.

How can I get the server to interpret the logic instead of printing it?

Brianna Singer
  • 119
  • 1
  • 1
  • 8
user1803531
  • 29
  • 1
  • 3
  • including index.php ? the first page you see when you access localhost – Andrei Cristian Prodan Nov 06 '12 at 15:20
  • That is why I hate these "pre-installed" webservers. What is different between the php script that works and the one that shows source code? Different directories? – Salman A Nov 06 '12 at 15:31
  • Are you sure it's working correctly and you are not accessing the folder directly? You should be going to http://127.0.0.1/FOLDER/FILE – frustratedtech Nov 06 '12 at 15:35
  • let me get this straight: If you create a new file in your mamp/www or wamp/www folder, name it file.php and inside you write , then if you access in your browser: localhost/file.php you will see something the whole code instead of the text "Sample Text"? – Andrei Cristian Prodan Nov 06 '12 at 15:36
  • What's "the phpinfo.php"? You only get PHP executed if you name the file "phpinfo.php"? – Álvaro González Nov 06 '12 at 15:37
  • i think he is referring to a common test page that only has the phpinfo() function http://php.net/manual/en/function.phpinfo.php – thescientist Nov 06 '12 at 15:46
  • OP, it would be helpful if you code the code that isn't work. Ideally putting it right into the same page that works using phpinfo, so canr educe environment/testing variables – thescientist Nov 06 '12 at 15:47

2 Answers2

4

Educated guess. You've tried this code and it runs flawlessly:

<?php
phpinfo();
?>

Now you've copied some PHP code that looks like this:

<?
foo();
bar();
?>

... and it's being ignored by the PHP interpreter. Please note the important difference: <?php vs <?.

If that's they case, you need to do one of these:

  1. Replace your short open tags with <?php.
  2. Enable short open tags either in .htaccess or your php.ini file. You'll find the path to php.ini in the outout of phpinfo().
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
2

Try typing instead of localhost 127.0.0.1 like 127.0.0.1/index.php

Khalid Dabjan
  • 2,697
  • 2
  • 24
  • 35