Page 1 of 1

Apache and the MAC

Posted: Thu May 14, 2009 11:32 am
by thetribster
This piece of code just draws a blank form in the browser:

Code: Select all

 
<HTML>
<HEAD>
<TITLE><www.StrataLighting.com></TITLE>
</HEAD>
<BODY>
<? phpinfo(); ?>
</BODY>
</HTML>
 
Why? I launch it by http://localhost:8888/phpscript.php.

Also, I don't understand how Apache is looking to launch things: 127.0.0.1, localhost:8888, 192.168.1.6 - it seems that every locations is pointing to a different directory. I know how to set the MAMP directory but even that doesn't seem to launch things correctly as defined from the above code - I get the title and then a blank page.

When I try and connect to my user page directly (http://localhost:8888/!davetribbett/index.html I get an authentication window from PEAR requiring me to login - i have know idea what the credentials are since none of mine work - effectively I am unable to launch from the directoy!

I suspect I have installed something that stomped on stuff but I don't know what. I uninstalled MAMP and reinstalled - no help. Could be a conflict between the original Apache install and MAMP? The PEAR thing is a PITA as well - no idea why I am getting that.

Any ideas or suggestions would be appreciated - this is frustrating and I'm relatively new to the MAC world.

Re: Apache and the MAC

Posted: Thu May 14, 2009 11:37 am
by thetribster
Here is another piece of code (PERL) I can only execute via terminal:

Code: Select all

 
#!/usr/bin/perl
use strict;
my @a = ("Market", "Cranberry", "Bush", "Geitner");
my $url = "http://www.cnn.com";
my $sysstring = "curl -s $url";
my $count = 1;
my $totalcount = 1;
print "Opening...\n";
open(FOO, "$sysstring|");
print "Searching...\n";
while (<FOO>){
   my $lineout = $_;
   foreach my $search (@a) {
      $totalcount++;
      if ($lineout =~ /$search/){
         print "$count. $search found.\n";
         $count++;
      }
   }
}
print "$totalcount\n";
close FOO;
print "Complete.\n";
 
When I execute this with the following browser entry: http://localhost:8888/firsttest.pl is actually just puts the code in the browser window like its a text file.

I have to say that things seemed easier in the world of Windows but I don't want to go back....

Re: Apache and the MAC

Posted: Thu May 14, 2009 12:02 pm
by thetribster
Alright, it seems that PHP embedded in HTML doesn't work. If I run the code as a straight PHP it works when I embed in HTML it doesn't although the HTML works fine...

Re: Apache and the MAC

Posted: Thu May 14, 2009 2:15 pm
by pickle
The file has to have a .php extension in order for PHP to be executed. Apache looks at that extension and says "Oh - this is a PHP file - I should send this request to the PHP interpreter". Only then will the PHP be executed. If you have PHP code in a file with a .html extension, Apache will say "The user wants this HTML file - ok, I'll open it up & send it to them" - the PHP interpreter is never started for that request.

Re: Apache and the MAC

Posted: Fri May 15, 2009 11:29 am
by thetribster
No, you can embed PHP in HTML by using the <? <php code> ?> construct. I have this working now, but I am still having issues with things executing correctly from any location (192.168.1.6 vs localhost:8888 vs 127.0.0.1).

Re: Apache and the MAC

Posted: Fri May 15, 2009 11:39 am
by John Cartwright
thetribster wrote:No, you can embed PHP in HTML by using the <? <php code> ?> construct. I have this working now, but I am still having issues with things executing correctly from any location (192.168.1.6 vs localhost:8888 vs 127.0.0.1).
What Onion was saying is the file extension you want to run needs to be intepreted by the PHP parser. Whether or not you have <?php ?> tags is irrelevant, because if the file extension is not recognized as PHP it will never be intepreted to begin with.

Re: Apache and the MAC

Posted: Wed May 20, 2009 10:40 am
by pickle
John Cartwright wrote:What Onion was saying is the file extension you want to run needs to be intepreted by the PHP parser.
That's exactly what I was saying ;)