TechJunkie is a BOX20 Media Company

Home Web How To: Set up LAMP Server Under OS X

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.

How-To: Quick Wireless Setup With Ubuntu 8.04

Read Next 

One thought on “How To: Set up LAMP Server Under OS X”

Tidosho says:
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!

Leave a Reply

Your email address will not be published. Required fields are marked *


Adam

Sep 10, 2008

643 Articles Published

More