Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    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 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    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 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #5
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    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 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    mzimmers (01-23-2012)

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    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.
    I can't really think of anything to write here now...

  • Users who have thanked tangoforce for this post:

    mzimmers (01-23-2012)

  • #8
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    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.
    I can't really think of anything to write here now...

  • #10
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #11
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    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.
    I can't really think of anything to write here now...

  • #12
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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):

    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...

  • #13
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #14
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    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.
    I can't really think of anything to write here now...

  • #15
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •