Setting up a local subdomain/virtual host on MAMP

I've had this one partially written for a while, so I figured I would finish it out so that anyone who needs that extra shove has yet another reference to read from!

I was a native Windows user for many years. I used XAMPP for all my local development and life was good. I won't get into all the details of how or why I started using Mac, but suffice to say I enjoy it a bit more than Windows. There are a lot more tools available out of the box that I don't need to install and finagle with. Anyway, I started using MAMP instead of XAMPP when I made the switch. As you may or may not know MAMP is a tad bit different than XAMPP is out of the box. MAMP defaults the webserver to use port 8888 and the MySQL database to use port 8889. While those are not really problems, they are something to pay attention to as they add a couple more steps into the process of setting up subdomains.

The first thing you want to do is figure out the subdomain you want and edit your hosts file to include it.

sudo vim /private/etc/hosts/ 

I added in the line:

127.0.0.1 levi.local

Then I went over to my virtual host file in MAMP located at /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf and I added the following:

<VirtualHost *:8888>
    ServerName leadingchange.local
    DocumentRoot /Applications/MAMP/htdocs/usm/leadingchangenetwork>
    <Directory /Applications/MAMP/htdocs/usm/leadingchangenetwork/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

Pay attention the VirtualHost line to note that it has apache listening on port 8888. Now if you restart apache/mysql and visit http://levi.local:8888 it will load the site that would normally show up at http://localhost:8888/levi/

If you have any feedback for me, I'd love to hear it - corrections, alternative paths, you name it! Send me an email levi@levijackson.xyz