Can mamp be used to locally test php?

Discussion in 'Web Design and Development' started by Dal123, Jul 31, 2010.

  1. Dal123 macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #1
    Recently found out about http://www.mamp.info/en/index.html to install wordpress locally (pretty cool - but haven't yet managed to install part of an existing wordpress database :p).
    So I spent all night last night trying to test it on mamp and it wouldn't work, then tested it on my local server and it worked.
    I wonder if I could somehow create a database and make the standard mamp make it work.
    So I'm thinking do I need mamp pro to do this sort of thing? I think I do, just want to be sure.:)
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    You don't need the pro piece. It's just a matter of getting everything configured properly to use your MAMP settings rather than your web host settings. See this WordPress Codex page for installing WordPress locally on your Mac with MAMP.
     
  3. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #3
    Thanks, I managed to configure wordpress and its working well, only thing is I already have blog pretty well halfway complete and can't afford to restart it. Trying to load an existing database in there is a bit tricky for me at the minute.

    The most pressing issue at the moment is if I can use it test php, at the moment I'm having to load it onto my server.
    Thanks :)
     
  4. jampat macrumors 6502a

    Joined:
    Mar 17, 2008
    #4
    I've never tried wordpress, but I had drupal and Joomla running PHP locally with free MAMP. Things worked remarkably well actually. Good luck.
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    No one said anything about restarting your blog. You can set them to look the same, using the same theme.

    It sounds like you're having trouble running PHP, but you haven't given any clear information on that.

    As for loading your local database, you'll first need to export your current DB on your site. If you can SSH into your server, it's pretty easy to export a DB. Here's one of many sites explaining how to export. In short though,
    Code:
    mysqldump -u username -ppassword database_name > FILE.sql
    Alternatively, your host may be able to export the DB from their cpanel or whatever they use. You'll have to consult your web host about that option.

    [IMPORTANT: as you are new to this type of activity, be sure to make backups of your MAMP setup before trying the import out so you have something to fall back on. If you mess up, it could require reinstalling WordPress]

    For importing the DB locally it's easy to import, but then you need to adjust some of the fields so it points to your local site instead of the server one. Below is a script I use for doing the modification. You'll need to update the script to match your DB credentials as well as the URLs. The script is run from Terminal and you give it the file name that you export to from the above command.

    Example usage:
    Code:
    sh script.sh File.sql
    script.sh:
    Code:
    #!/usr/bin/env bash
    
    # Local database credentials
    # Username
    U="db-user"
    # Password
    P="db-password"
    # Host
    H="localhost"
    # Database name
    D="db-name"
    
    # Import new/updated SQL DB
    import=$1
    mysql -u$U -p$P -h$H $D < $import
    
    # Modify to work for site.local
    mysql -u$U -p$P -h$H $D <<eoq
    UPDATE blog_posts SET guid = replace(guid, 'www.site.com', 'site.local');
    UPDATE blog_options SET option_value = 'http://site.local/blog/' WHERE option_name = 'siteurl';
    UPDATE blog_options SET option_value = 'http://site.local/blog/' WHERE option_name = 'home';
    eoq
    Items you will have to change:
    • All of the top variables. They are commented to tell you what's needed
    • www.site.com will be your web site URL
    • site.local will be whatever your MAMP is setup for, probably just localhost
    • blog_posts will depend on your WordPress setup. If you setup a prefix for the DB, but should end in "posts"
    • blog_options will depend on your WordPress setup. If you setup a prefix for the DB, but should end in "options"
     
  6. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #6
    Thanks for that, I found a little on transferring database to local host but couldn't understand any of it.
    I have created a local host of my new website which I'm trying to use php :p, and when I try to preview the file I get this appear.
     

    Attached Files:

  7. ezkimo macrumors regular

    Joined:
    Sep 12, 2002
    #7
    If you're still using MAMP (which is the easiest way to do it), you put your files in Applications->MAMP->htdocs, not where you are putting them.

    Next, launch MAMP, go to preferences->ports & click 'set to default Apache and MySQL ports'. Now when you go to http://localhost in your browser it should show your files in the MAMP folder.
     
  8. Dal123 thread starter macrumors 6502a

    Dal123

    Joined:
    Oct 23, 2008
    Location:
    England
    #8
    Cheers bud, I moved my htdocs folder and created my root in users so bit easier/ quicker to get to.
    I realise now that I cannot preview from dreamweaver, and instead must type local address in url. woo :)
     

Share This Page