Do you do web stuff? Do you work on your projects using multiple Macs? Do you want to take your work on-the-go and sync it one-to-one to your laptop? Well for me this is the situation I was facing – and had to find a solution for.
In this article I will describe, how you can keep a local MAMP installation in-sync across multiple Macs with macOS (formerly OS X).
Before going into detail, here are some basic requirements you will need – and a simple, alternative approach to what follows:
Alternative approach, without a sync tool
Instead of syncing all the files between your Macs automatically using the mentioned sync tool, you can do this by just keeping all the files on one portable USB disk drive. Of course you will need to plugin the drive to whichever Mac you are currently working on!
How-to configure MAMP to sync across multiple Macs
Briefly explained:
the key to keep MAMP in-sync across multiple macOS is to place a few important files & folders at a central place (not inside the MAMP directories), sync those extracted files to all your Macs and link them on each of them – using symbolic links – back at their original place. But let’s have a look at this in detail.
Pre-requisites
- MAMP installed on all Macs (v4.0.4 used for this how-to)
- Resilio Sync installed on all Macs (formerly known as: BitTorrent Sync)
- Stop all MAMP servers, in case they are already running
- Keep the Terminal.app ready
/Applications/Utilities/Terminal.app
1) Create the Shared Folder structure to be synced
Setup the to-be-synced folder hierarchy somewhere in your macOS.
I personally prefer the ~/Sites/ folder in my macOS user’s home directory.
~/Sites/ MAMP-conf/ MAMP-db/ MAMP-htdocs/ → place any of your web-projects' files & folders here
2) Move files & folders out of MAMP directory and Replace them with symbolic links
- Navigate inside the MAMP directory located in
/Applications/MAMP/
- Move the following configuration files to the previously created shared folder:
/MAMP/conf/apache/httpd.conf → ~/Sites/MAMP-conf/httpd.conf
If applicable (= if you changed any of these for your MAMP setup), also include any files from the /extra/-folder. For example:
/MAMP/conf/apache/extra/httpd-vhosts.conf → ~/Sites/MAMP-conf/httpd-vhosts.conf
- Move all the contents from the MAMP htdocs folder to the shared folder:
/MAMP/htdocs/* → ~/Sites/MAMP-htdocs/*
- Move the following database folder(s) to the shared folder:
/MAMP/db/mysql56 → ~/Sites/MAMP-db/mysql56
/MAMP/db/sqlite → ~/Sites/MAMP-db/sqlite
Time for symbolic link magic using the Terminal.app
Place a symbolic link from the shared folder back to the MAMP directory, for all moved files & folders: launch the Terminal.app and use the following commands (adjust & repeat for more, if necessary):
$ ln -s ~/Sites/MAMP-conf/httpd.conf /Applications/MAMP/conf/apache/httpd.conf $ ln -s ~/Sites/MAMP-conf/httpd-vhosts.conf /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
$ ln -s ~/Sites/MAMP-htdocs /Applications/MAMP/htdocs
$ ln -s ~/Sites/MAMP-db/mysql56 /Applications/MAMP/db/mysql56 $ ln -s ~/Sites/MAMP-db/sqlite /Applications/MAMP/db/sqlite
Validate all changes in MAMP
Now start MAMP to test, if Apache & MySQL are still launched. If all lights are “green“, you did everything right.
3) Setup the Sync Tool to sync your new shared folder to each Mac
- Launch the Resilio Sync.app
- Add the previously created new shared folder via “Add Folder”
- Configure a share link for other peers (= your other Macs) with “Read & Write” permissions
- Copy or send the share link to your other Mac…
4) On your 2nd Mac only*, replace the MAMP files & folders with symbolic links
* also applies for any 3rd, 4th,… Mac you are going to sync to
Pre-requisite: remove existing folders before creating symbolic links
Some users have experienced issues with overwriting existing MAMP folders with symbolic link. So you may want to delete those folders from within the MAMP directory first:
$ sudo mv /Applications/MAMP/htdocs ~/.Trash/ $ sudo mv /Applications/MAMP/db/mysql56 ~/.Trash/ $ sudo mv /Applications/MAMP/db/sqlite ~/.Trash/
A) Setup the sync tool in order to start syncing the shared folder
On your other Mac(s), follow only these steps:
- Launch the Resilio Sync.app
Note: you may change the Resilio Sync-folder’s location in the app’s settings or when adding the shared folder link, if you want to!
- Click on “Enter a key or link”
- Now add the share-key from the primary Mac & confirm
- Choose the destination folder where to sync the contents of the original shared folder’s contents to – I recommend using also the ~/Sites/ folder on the additional Mac(s)
B) Now place symbolic links into the MAMP directory
Launch the Terminal.app and use the following commands to overwrite the files & folders in the MAMP directory with symbolic links to each file & folder from the shared folder (adjust & repeat for more, if necessary):
$ ln -sf ~/Sites/MAMP-conf/httpd.conf /Applications/MAMP/conf/apache/httpd.conf
$ ln -sf ~/Sites/MAMP-htdocs /Applications/MAMP/htdocs
$ ln -sf ~/Sites/MAMP-db/mysql56 /Applications/MAMP/db/mysql56
$ ln -sf ~/Sites/MAMP-db/sqlite /Applications/MAMP/db/sqlite
Now start MAMP to test, if Apache & MySQL are still launched. If all lights are “green“, you did everything right.
AND THAT’S IT! Enjoy working with MAMP in-sync on all your Macs from now on.
Some questions you may have…
Why not syncing the files using Dropbox?
Dropbox cannot properly handle to sync files like e.g. all the MySQL-database files. And additionally, it will fail or get stuck to sync files, which are currently in use/open on any of your Macs.
Why do you set the permissions for the synced folder to “Read & Write” and not “Read only”?
You CAN just allow one (or more) Macs to just receive all files & folders from your primary Mac – something like in a Master-Slave scenario. But of course it will not be possible to sync back any changes to the Master-Mac – additionally, local changes will be overwritten next time the same files are modified on your primary Mac.
Hi Oliver,
thanks for sharing your guide.
I’ve a problem with the PhpMyAdmin sharing.
I’ve a localhost with wordpress and on the primary machine works fine. In the other mac don’t connect to db (Error Establishing a Database Connection). If I open the phpmyadmin panel in my other mac I don’t have the DB I’ve created in the primary machine.
I followed your step by step tutorial, do you have any idea?
Thank you very much.
Hi Letizia,
I’m happy to hear that this guide was helpful for you.
Regarding your problem with the missing DB on the second Mac: have you compared the following folder between both machines and are the folders & files properly synced?
~/Sites/MAMP-db/mysql56
I guess i had the same problem. On the second Mac i first had to delete the folders htdocs and inside /db the mysql56 and sqlite folders before placing the symbolic links. Otherwise it would place these symbolic links inside the folders which made a lot of nested folders of databases.
Thank you for the hint. I updated the post accordingly with such a step
It’s not clear what is meant here:
/MAMP/htdocs
→ ~/Sites/MAMP-htdocs
are we supposed to put the folder /MAMP/htdocs into the folder ~/Sites/MAMP-htdocs or should we move the folder to ~/Sites/ and then rename to MAMP-htdocs?
Thank you for the hint, Karl.
I updated the instructions to be more clear – hope this helps.
Hi Oliver, thank you for this great tutorial! I’m just about to start the process but I was wondering if anything goes wrong is there a way to revert everything back?
Thanks,
Jeff
Hi Oliver,
I followed all the steps and I’ve synced all files between my devices. MAMP lights are green but when I go to my local project I get a “404 not found”. Do I need to change the paths into my httpd-vhosts.conf file? I’ve tried that but it’s still not working.
Any help would be appreciated.
Thanks,
Jeff
Hi Jeff
Well I’m not sure… I didn’t have to update the paths in the httpd-vhosts.conf file – my entries are looking like the following:
I use the GasMask app for configuring the local Hosts file entries (e.g. “127.0.0.1 test.local”): https://github.com/2ndalpha/gasmask
But did you check the Apache log files from MAMP about the 404 error? It should give you enough information to find the cause and fix it. It’s located under