Can mamp be used to locally test php?

Dal123

macrumors 6502a
Original poster
Oct 23, 2008
903
0
England
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.:)
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
7
USA
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.
 

Dal123

macrumors 6502a
Original poster
Oct 23, 2008
903
0
England
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 :)
 

jampat

macrumors 6502a
Mar 17, 2008
682
0
I've never tried wordpress, but I had drupal and Joomla running PHP locally with free MAMP. Things worked remarkably well actually. Good luck.
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
7
USA
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
  • http://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"
 

Dal123

macrumors 6502a
Original poster
Oct 23, 2008
903
0
England
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.
 

Attachments

ezkimo

macrumors regular
Sep 12, 2002
216
0
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.
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.
 

Dal123

macrumors 6502a
Original poster
Oct 23, 2008
903
0
England
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 :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.