How To: Set up LAMP Server Under OS X

For development and testing reasons, I wanted to set up a local server on my Mac Pro so that I could operate a local copy of PCMech.com. I thought I would document how I went about it for the benefit of others down the road.

The easiest method to set up a quick LAMP server under OS X is to use MAMP. MAMP stands for Mac, Apache, MySQL and PHP. Now, both Apache and PHP do come bundled with OS X, but you’re going to get into command line hell if you want to set it up. MAMP is much easier because you just download, drag to the Applications folder, and you’re done.

Once you’ve done this, let’s do the following:

  1. Navigate to the new MAMP folder and start the MAMP app.
  2. Change any preferences you might want to change, but otherwise go ahead and click “Start Servers”.
  3. Click on “Open Start Page” and your default web browser will load up the default homepage at localhost. You will see a menu of options, too, because MAMP has PHPMyAdmin and other utilities built right in.

Being that MAMP is completely independent, it does not run in the background. So, you’ll need to start up MAMP like any other application in order for your server to be operational. To remove MAMP, just drag the MAMP folder to Trash. No config files for OS X are altered, so a simply drag to Trash means everything is gone.

To work with any files, you will need to place your website files into the “htdocs” sub-folder off of the MAMP folder. Yes, this means your website files reside in the Applications folder which is  odd. But, this is how MAMP maintains its independent nature.

Lastly, you might want to get command line access to MySQL so that you can run MySQL commands via Terminal. For instance, I needed to import the PCMech database into my local database and it was way too large to be imported via PHPMyAdmin. The tedious way would be to manually split up your SQL file. The much easier way is to set up the MAMP version of MySQL to be able to take commands via Terminal. To do so, execute the following commands in Terminal:

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
sudo chown _mysql /var/mysql/mysql.sock
sudo chmod 777 /var/mysql/mysql.sock

Once that is done, you can import an SQL file via the following command via Terminal:

/Applications/MAMP/Library/bin/mysql -hlocalhost -uroot -proot [DBNAME] < ‘/Users/[USER]/Documents/Database Backups/[NAME OF SQL FILE].sql’

Replace [DBNAME] with the name of your local database, [USER] with your username under OS X, and [NME OF SQL FILE] with whatever the file name is for your SQL backup from which you want to restore. You’ll want to make sure the file path for your SQL file is correct, too. I use a folder called “Database Backups”, but that’s me.

With this, you should be good to go. I now have a copy of PCMech.com running locally on my Mac.

Free eBook!

Like what you read?

If so, please join over 28,000 people who receive our exclusive weekly newsletter and computer tips, and get FREE COPIES of 5 eBooks we created, as our gift to you for subscribing. Just enter your name and email below:

Post A Comment Using Facebook

  • http://www.kitamuracomputers.com Tidosho

    Dave,

    Thanks for this! I’ve been looking for a solution like this for my x86 Hackintosh, as I use WAMPServer under Windows. This Mac equivalent isn’t as configurable, but it does the job, and I can now edit my company website under OS X.

    Top Man, keep it up!

What’s Your Preference?

Daily Alerts

Each day we send out a quick email to thousands of PCMECH readers to notify them of new posts. This email is just a short, plain email with titles and links to our latest posts. You can unsubscribe from this service at any time.

You can subscribe to it by leaving your email address in the following field and confirming your subscription when you get an email asking you to do so.

Enter your email address for
Daily Updates:

Weekly Newsletter

Running for over 6 years, the PCMECH weekly newsletter helps you keep tabs on the world of tech. Each issue includes news bits, an article, an exclusive rant as well as a download of the week. This newsletter is subscribed to by over 28,000 readers (many who also subscribe to the other option) - come join the community!

To subscribe to this weekly newsletter simply add your email address to the following field and then follow the confirmation prompts. You will be able to unsubscribe at any time.

Enter your email address for
Free Weekly Newsletter: