Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2012, 03:58 AM   PM User | #1
mzimmers
New to the CF scene

 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
mzimmers is an unknown quantity at this point
MAMP and PHP files

Hi -

I'm trying to learn more about MAMP and PHP. I installed MAMP, and according to their status page, I did so successfully.

I would assume that now, if I drag a .php file to my browser, it would try to process the php in it. But, that's not happening; instead the file just "downloads."

The file in question is under my document root.

Am I doing something wrong, or am I incorrect in my expectation that the page should be processed?

Thanks.
mzimmers is offline   Reply With Quote
Old 01-23-2012, 04:31 AM   PM User | #2
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
MAMP installs a web server, with PHP and MySQL. This means that it will accept incoming HTTP requests and output results based on the web accessible directory. Which means, http://localhost/ or http://127.0.0.1/ will return your local web directory, which is where ever MAMP is installed.

It doesn't give MAC OS X the ability to interpret PHP, it creates a server environment that runs apache with PHP - the way you would find it on any web hosting provider all across the web.
__________________
Useful function to retrieve difference in times
The best PHP resource
A good PHP FAQ
PLEASE remember to wrap your code in [PHP] tags.
PHP Code:
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button 
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
BluePanther is offline   Reply With Quote
Old 01-23-2012, 04:40 AM   PM User | #3
mzimmers
New to the CF scene

 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
mzimmers is an unknown quantity at this point
OK, I sort of understand that explanation. So...what do I have to do to complete the configuration? Since I already have MAMP up and running, how do I get it to process a .php file?

I understand what you're saying about the Mac not having the native capability to interpret PHP. I thought that's what MAMP was going to do for me. Not so?

Thanks.
mzimmers is offline   Reply With Quote
Old 01-23-2012, 05:22 AM   PM User | #4
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
The way the web works, a client sends a request to a server and the server parses, then sends a response. In terms of PHP, the browser sends a request to a server, the server then parses any information sent in the request, runs the PHP file, then sends the output to the browser. Execution is done by the server software.

Apache is the server software, installed by MAMP. MAMP is a server package that installs apache with PHP enabled (and MySQL of course). So, like any other server, it returns a response based on a request, and processes scripts through apache. Any PHP scripts you want to run on your computer, will need to run through apache or the PHP command line. To run through apache (open the file in the browser) you need to put the file somewhere in your web root (probably www folder).

This is the one of the main (amoung many) differences between PHP and html. PHP is executed server side, meaning the client will only ever see the output from it after the web server has processed it.
__________________
Useful function to retrieve difference in times
The best PHP resource
A good PHP FAQ
PLEASE remember to wrap your code in [PHP] tags.
PHP Code:
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button 
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
BluePanther is offline   Reply With Quote
Old 01-23-2012, 06:07 AM   PM User | #5
mzimmers
New to the CF scene

 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
mzimmers is an unknown quantity at this point
In MAMP preferences, I have the option of setting something called the "Document Root." I imagine this is the same as the web root you mention above. But, when I navigate to that root, and click on a file (or just drop the file onto my browser), it merely downloads.

Sorry if I seem dense, but what am I not doing right here?
mzimmers is offline   Reply With Quote
Old 01-23-2012, 06:46 AM   PM User | #6
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
Quote:
Originally Posted by mzimmers View Post
In MAMP preferences, I have the option of setting something called the "Document Root." I imagine this is the same as the web root you mention above. But, when I navigate to that root, and click on a file (or just drop the file onto my browser), it merely downloads.

Sorry if I seem dense, but what am I not doing right here?
You're not really paying attention to what I'm saying . Document Root is what I'm referring to.

To put it simply, MAMP is a server on your computer. Opening your browser, and going to http://127.0.0.1/ will send a request to the server on your computer, which will fetch your website from document root. PHP is processed by the server (MAMP), separately from your computer.

Your browser is downloading it because it doesn't know what to do with it - it can't use PHP. Read over what I've said, and think about how the web works. Maybe even google "How PHP works" to get a better idea
__________________
Useful function to retrieve difference in times
The best PHP resource
A good PHP FAQ
PLEASE remember to wrap your code in [PHP] tags.
PHP Code:
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button 
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
BluePanther is offline   Reply With Quote
Users who have thanked BluePanther for this post:
mzimmers (01-23-2012)
Old 01-23-2012, 12:24 PM   PM User | #7
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by BluePanther View Post
You're not really paying attention to what I'm saying . Document Root is what I'm referring to.
You've explained it well.. for someone who understands all of this stuff but for someone who doesn't it's a bit.. whoa... what?

@OP: Put your php files into that 'root' folder you've found. Then as BP has said, open up your 'browser' (th thing you use to look at websites) and visit:

http://localhost

You'll see the php scripts that you have in that directory will then work behind the scenes and do their magic.

PHP is not a file you can double click like a normal file, it can (for the purposes of getting you up and running) only an instruction file to your webserver.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
mzimmers (01-23-2012)
Old 01-23-2012, 03:38 PM   PM User | #8
mzimmers
New to the CF scene

 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
mzimmers is an unknown quantity at this point
Ohhhhhh...OK, now I think I get it. Thanks for your patience. I guess I didn't realize that one couldn't "activate" Apache (if that's the right term) except by navigating to the document root.

Interestingly enough, I'm not getting the web page I expected. I pointed the document root to a file containing a phpinfo() call, but I'm getting an "It Works!" banner instead. Weird, since the only file in my document root is the one containing the phpinfo() call...

Thanks again.
mzimmers is offline   Reply With Quote
Old 01-23-2012, 05:42 PM   PM User | #9
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Then its not in the correct directory OR you have a file called index.htm, index.html etc.

Apache by default will serve the .htm extension before .html before .php etc.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 01-23-2012, 05:52 PM   PM User | #10
mzimmers
New to the CF scene

 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
mzimmers is an unknown quantity at this point
The directory I'm using has one file, the index.php. The contents of this file are:

Code:
<?php phpinfo(); ?>
But instead, it's picking up some file with the contents:

Code:
<html><body><h1>It works!</h1></body></html>
So, clearly something's amiss, but I can't identify it (yet). I even stopped and restarted the servers with MAMP; same results.
mzimmers is offline   Reply With Quote
Old 01-23-2012, 06:25 PM   PM User | #11
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
So you have the wrong document root.

Look for a folder called public_html, www, public, default etc. Better still, read the MAMP documentation and see where it tells you to place your files.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 01-23-2012, 06:44 PM   PM User | #12
mzimmers
New to the CF scene

 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
mzimmers is an unknown quantity at this point
I just re-read the online MAMP documentation...apparently, there's a whole host of directories that cannot be used for the document root (even though you can select them from Preferences):

Quote:
Note: The user, whose account runs the web server must possess at least read permissions for the selected folder. The field may not be empty. The following folders can not be used:

/Developer
/Applications
/Library
/Network
/Volumes
/bin
/cores
/dev
/etc
/mach
/private
/sbin
/tmp
/usr
/var
/System (incl. subfolders)
So, I created a root-level folder, with my index.php in it, and I still got redirected to the "it works" page. Then I shut down MAMP, and I STILL got the "it works" page. So, I'm not as far along as I had thought.

There isn't much more information on the MAMP site; their docs are pretty brief. Guess I'll keep playing with it...
mzimmers is offline   Reply With Quote
Old 01-24-2012, 12:27 AM   PM User | #13
mzimmers
New to the CF scene

 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
mzimmers is an unknown quantity at this point
Well, I have a little more information. It appears that it works only when I use the URL "localhost:8888" and not with "127.0.0.1" or just "localhost." I don't know if this is now it's now supposed to work, or if I still have something misconfigured. I've tried posting to the MAMP forum, but it's evidently fairly sparsely used.

Thanks for the help...I'll see if I can get any further with this.
mzimmers is offline   Reply With Quote
Old 01-24-2012, 01:53 PM   PM User | #14
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
You need to go into your httpd.conf file and change the default port to 80 (from 8888), save and then restart apache.

That should make it do what you want accessible without the :8888 being tagged on the end.

httpd.conf will be somewhere in the apache folder.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 01-25-2012, 07:22 PM   PM User | #15
mzimmers
New to the CF scene

 
Join Date: Feb 2007
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
mzimmers is an unknown quantity at this point
Thanks, tango...that did work, though it brought a side effect of my having to provide a password whenever starting/stopping the servers. I think I prefer it the old way.

MAMP now appears to be working, so I guess it's time to figure out why WordPress doesn't like it. But, that's probably a topic for another thread.

Thanks again for the help, everyone.
mzimmers is offline   Reply With Quote
Reply

Bookmarks

Tags
mamp, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:49 PM.


Advertisement
Log in to turn off these ads.