WordPress MU+MAMP error establishing database connection

Solution:

I have multiple websites running on my MAMP machine, and have found it easiest to use the default Apache and MAMP settings.

And you don’t want to specify MAMP porting in this way through the config-file, instead modifying your /etc/hosts file on your main Macintosh computer. You shouldn’t modify anything beyond the fe80::1%lo0 localhost, as it would mess up the way the hosting is read on your computer. You type your new virtual host below that line, the /etc/hosts file looking similar to this:

##
# Host Database 
# 
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry. 
## 
127.0.0.1         localhost
255.255.255.255   broadcasthost 
::1               localhost 
fe80::1%lo0       localhost 
127.0.0.1         localhost
127.0.0.1         examplesite.local

You can name examplesite.local however you want, this is the URL which will display your website in the browser. You save those changes to the /etc/hosts file, then going to the httpd.conf in your Apache folder (the location of the file being in Applications/MAMP/conf/apache/httpd.conf). You then add virtual hosts to the bottom of the file, with code like this, modifying the name examplesite.local to, again, whatever you want the URL to display in the browser:

NameVirtualHost *
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/examplesitename"
ServerName examplesite.local
</VirtualHost>

Once you make these changes to the httpd.conf file, make sure to reboot your MAMP, as the Apache server needs to take these changes into effect.

Here is the website I use since I forget command-line in order to edit the /etc/hosts file and the steps I presented to you in more detail: http://sawmac.com/mamp/virtual/

Here’s what the original /etc/hosts file off of the Macintosh looks like in case you ever lost it: http://thecoredump.org/2011/09/editing-the-hosts-file-in-mac-os-x-lion/

Also, make sure you have a separate database, user for the database, and folder in the htdocs folder for each website you run on MAMP.

Hope this helps you get up and running!