How to Set Up Coda 2 and MAMP for PHP Development

Coda 2 comes with PHP previewing right out of the proverbial box. Give it a try, create a new PHP doc and paste this code into it:

<?php echo "Hello World!" ?>

Then press the preview button and you should see the properly executed output “Hello World!”. This won’t work if you try dragging the PHP file to a web browser. Coda 2 is doing some magic behind the scenes.

The problem is PHP “includes” don’t work without some configuration. Instead you get a nasty error code telling you the file does not exist. I solved this with a few steps:

  1. Download and run MAMP. Make sure in the preferences that the Apache port is set to 80 (I don’t remember if this is default or not).
  2. Create a new site in Coda 2 and give it a nickname.
  3. The only really important fields for local development are Local URL and Local Root. Set the Local Root first by clicking the “Set” button and navigating to the “htdocs” folder that MAMP should have created when you installed it. The path should be Applications/MAMP/htdocs. Create a new folder within the htdocs folder and choose it as the Local Root.
  4. Now set the Local URL as http://localhost/the_name_of_the_folder.
  5. You can fill out the other two fields, Root URL (the URL it uses to make an icon for your site) and Remote Root (for uploading to a remote server when you’re ready to go live), if you want but you can leave them blank for local development purposes.
  6. Now save the site and you should be good to go. If includes still don’t work, try restarting Coda 2 and MAMP.

To test, make a PHP document in your root folder and paste this HTML into it:

<h1>includes work!</h1>

Save it as include.php. Now make another PHP document in your root folder and paste this into it:

<?php include('include.php') ?>

Save it as index.php then preview it and you should see in big bold letters “includes work!”

I would still like to know if it is possible to do this without having to save my site in htdocs, but rather, point MAMP to my websites folder in my home folder.

12 thoughts on “How to Set Up Coda 2 and MAMP for PHP Development

  • kate says:

    thank you so much!

  • domi says:

    “I would still like to know if it is possible to do this without having to save my site in htdocs, but rather, point MAMP to my websites folder in my home folder.”

    It is possible:

    First you have to configure MAMP:
    • start mamp and goto preferences
    • goto “Apache” and click onto the small folder next to the text “Document Root:”
    • choose the folder of your project anywhere on your computer and click ok

    Then create a new site in Coda 2:
    • Set the Local Root to the folder you just have chosen
    • Now set the Local URL to ” http://localhost: +PORT”,
    while PORT means your Apache Port, configured in MAMP

    Now start your new site and be happy :-)

  • Shane says:

    this helped a lot – thanks!

  • Rob Eardley says:

    Thanks. Been using MAMP pro at work for a while now but never actually set it up myself for local testing for personal projects. This page really helped!

  • Gido says:

    This was helpful, thanks for sharing

  • kct3937 says:

    Works fine if you point your Root to Sites

  • kct3937 says:

    I Changed the doc Root in Mamp Pro tho

  • Ranal says:

    Thank you! I’ve been struggling with this issue for many hours, glad I found this post!

  • If you have MAMP Pro you can have multiple development sites going. In Coda you set Local URL to http://mysite.dev (or whatever you call it) and Local root set to point to any folder on your HD that contains the index.php (web root) for that dev site. The include_path will work like a hot knife trought butter.

  • Andrea says:

    Is there a way to get Coda 2 to preview locally hosted WordPress theme php documents? I am a total newbie and I managed to get MAMP setup. But I cannot for my life figure out why I cannot get any preview working for the php documents through Coda 2. Everything shows up fine in all my browsers if I go to localhost in a browser and in Coda 2 on the ‘ project ” page where it shows icons of the projets – there I see the “preview” of the index.php page as a small icon but further in the program i can’t get any preview working. I’d be super thankful for your assistance :)

    Cheers,
    An.

  • janice says:

    Holy crap, just wasted so much time trying to troubleshoot my code. Followed the steps and it all worked perfectly. THANK YOU!

Leave a Reply

Wordpress theme JaeDubya © 2018 | All Right Reserved | Designed & coded by J. Arthur Wetenkamp