Setting Up My Mac Without MAMP

Building on OS X's Standard Services for Local Development

I recently got a new Mac and needed to configure it as a local web server for the many Drupal sites I work on. I used to use MAMP for this, but lately have been using the built-in functionality that comes on a Mac instead. MAMP is easy to install, but it creates a duplicate version of PHP and a duplicate version of Apache. That takes up space on my machine and occasionally causes trouble when some operation uses the wrong version of PHP because of confusion about which installation should take precedence. Setting up a Mac without MAMP used to be sort of complicated, but it's been getting easier and easier with every version of Mac OS, and it's not that hard any more. I thought I'd share the process I'm using now.

Helper Apps and Terminal Window

To start with, I install a couple of apps that make all of this much easier to do. Pathfinder is a replacement for Mac's Finder that adds a number of nice improvements. The most important feature is that you can view invisible files with it. Once installed, go to the View option in the menu bar at the top of the page, and check the option to view invisible files.

The other handy app I depend on is Text Wrangler. The thing I especially like about that is that it makes it easy to edit protected files. When I try to edit a protected file using Text Wrangler it asks if I want to unlock the file. If I say yes, the file is unlocked while I make my changes, then reset to its previous permissions. Without this tool I would either have to edit it in my terminal window using sudo, or keep changing the permission on the file before I edit and then change it back again afterward.

You need to use the terminal window for many of these steps. To find that, click on the Launchpad icon in the dock, then choose Others and then Terminal.

PHP

Next install PHP. This is easy, it's already installed! To confirm that type the following to see where it is located:

  
which php
  

And type the following to see what version is installed:

  
php --version
  

Set up php.ini, if it doesn't already exist, by copying php.ini.default:

  
sudo cp /etc/php.ini.default /etc/php.ini
  

You may need to edit it to do things like increase memory.

Apache

Apache is also already installed. There is a default web root located at

  
/Library/WebServer/Documents/
  

You can put a web root in other places, but that makes configuration more complicated, so I've been leaving that alone.

To start Apache, using the terminal type:

  
sudo apachectl start
  

To stop Apache:

  
sudo apachectl stop
  

To restart Apache:

  
sudo apachectl restart
  

To test this, start Apache and go to http://localhost in a browser.

You should see 'It works!'

You'll be dropping our Drupal files in the web root, so add a bookmark to that using Pathfinder. Go to

  
/Library/WebServer/Documents/
  

Then choose Go from the menu at the top, then Favorites and Add to Favorites

Now you have a quick bookmark to the web root. Go to that location to add the Drupal files for your web site.

There are a couple final tweaks to Apache. One is to enable it's handling of PHP by enabling the PHP module. Using Pathfinder, navigate to

  
/private/etc/apache2/httpd.conf
  

Using Text Wrangler, uncomment the line in that file by removing the '#' in front of it:

  
LoadModule php5_module libexec/apache2/libphp5.so
  

If you want to use Virtual hosts, set them up in

  
/private/etc/apache2/extra/httpd-vhosts.conf
  

Edit http.conf and remove the '#' in front of the following line so the Virtual hosts get used:

  
Include /private/etc/apache2/extra/httpd-vhosts.conf
  

Finally, to get clean URLs working find and change the following in http.conf. Find:

  
<Directory "/Library/WebServer/Documents">
….
    AllowOverride None
….
</Directory>
  

And change it to:

  
<Directory "/Library/WebServer/Documents">
….
    AllowOverride All
….
</Directory>
  

Homebrew

The easiest way to do the remaining tasks is to install Homebrew. In a terminal window type the following:

  
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
  

Once it's installed, keep typing brew doctor until all errors are fixed. It should be pretty self-explanatory.

MYSQL

The dead easy way to install MYSQL is with Homebrew. Once you have that, just type:

  
brew install mysql
  

Check where it's located and which version you have:

  
which mysql
mysql --version
  

Confirm that it's working:

  
mysql
  

MYSQL is set up without a my.cnf file. You may want to create one at /etc/my.cnf with your preferred configuration settings.

MYSQL is set up without a root password by default. You should set a MYSQL root password using your terminal window, where 'ROOT_PASSWORD' is whatever password you want to use for this:

  
cd /usr/local/share/mysql
mysqladmin -u root password 'ROOT_PASSWORD'
  

Once last step. Some programs expect to find the mysql.sock file at /var and it isn't there by default. Using the terminal window:

  
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
  

PHPMyAdmin

Use Homebrew to Install phpmyadmin, which requires some additional dependencies. In the terminal window type:

  
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install phpmyadmin
  

Once that's installed, in the terminal type:

  
sudo cp /usr/local/share/phpmyadmin/config.sample.inc.php /usr/local/share/phpmyadmin/config.inc.php
  

Use Pathfinder to navigate to the Apache http.config file at:

  
/etc/apache2/http.config
  

Edit it using TextWrangler. Add the following to the bottom of http.config:

  
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>
  

Update: Note that the above only works in versions prior to Yosemite, in Yosemite change

  
Order allow,deny
Allow from all
  

to

  
Require all granted
  

Restart apache. Now navigate to http://localhost/phpmyadmin in a browser and you should see a place to log into PHPMyAdmin.

To change the way the login works, using PathFinder go to:

  
 /usr/local/share/phpmyadmin/config.inc.php
  

Edit config.inc.php using TextWrangler.

If you don't want to have to log in each time, add the following to the Server config:

  
$cfg['Servers'][$i]['user']          = 'root';
$cfg['Servers'][$i]['password']      = 'ROOT_PASSWORD';
$cfg['Servers'][$i]['auth_type']     = 'config';
  

Change the following to bypass the root password. You can do this if you want to change the root password or if you can't get logged in. Change the root password using the UI in PHPMyAdmin, then reset it to false to go back to using the password:

  
$cfg['Servers'][$i]['AllowNoPassword'] = true; 
  

Once logged in, set up the users and databases you need.

Git

You will probably want to be able to use Git to checkout projects and files. It should already be installed. To confirm that, and see where it is and what version you have, in the terminal type:

  
which git
git --version
  

Drush

That's enough to get a local version of a web site working, but for Drupal you'll probably also want to install Drush, which makes management of a Drupal site much much easier. To do that,

  
cd /usr/local/library
git clone drush
sudo chmod u+x /usr/local/Library/drush/drush
sudo ln -s /usr/local/Library/drush/drush /usr/bin/drush
  

Go to your home location, /Users/YOURNAME.
Look for a file called .profile (the name starts with a dot, it is a protected file). If it doesn't exist already, created it. Edit .profile with TextWrangler, and add this line:

  
alias drush="/usr/bin/drush"
  

Done!

That's it, everything necessary for a local installation of your web site should be working at this point. It's a little bit of work, but not terrible. Even installing MAMP requires a few extra steps that will send you to a terminal or require that you have a way to find hidden files and edit them, so this process is not a huge amount of extra effort.

Get in touch with us

Tell us about your project or drop us a line. We'd love to hear from you!