Apache and the MAC

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
thetribster
Forum Newbie
Posts: 7
Joined: Thu May 14, 2009 11:07 am

Apache and the MAC

Post 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.
Last edited by Benjamin on Thu May 14, 2009 12:31 pm, edited 1 time in total.
Reason: Added [code=html] tags.
thetribster
Forum Newbie
Posts: 7
Joined: Thu May 14, 2009 11:07 am

Re: Apache and the MAC

Post 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....
Last edited by Benjamin on Thu May 14, 2009 12:30 pm, edited 1 time in total.
Reason: Added [code=perl] tags.
thetribster
Forum Newbie
Posts: 7
Joined: Thu May 14, 2009 11:07 am

Re: Apache and the MAC

Post 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...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Apache and the MAC

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
thetribster
Forum Newbie
Posts: 7
Joined: Thu May 14, 2009 11:07 am

Re: Apache and the MAC

Post 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).
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Apache and the MAC

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Apache and the MAC

Post 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 ;)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply