• How To: Keep a Web development environment incl. MySQL synchronized on multiple Macs using Dropbox and MAMP PRO

    As a freelancer i like to work from home as well as from the office, since i have an iMac in the office and a MacBookPro at home (or wherever i am) i have to deal with Projects that i develop on both machines. This little tutorial will show you a solution!

    What you need:

    • A Dropbox account (2GB are free!)
    • MAMP Pro on OS X (i am currently using MAMP Pro as Trial, but the same setup should be doable with the free version of MAMP as well), make sure to install the same version on each of your machines!
    • A little time for each new Project since the Setup takes a few minutes, but its worth it since you never have to deal with “ah, which is the most recent version”-problem again!

    Allright, after you installed Dropbox and MAMP PRO i created the following Folders:

    All those are in a Folder “Sites” within my local Dropbox Folder.

    Next we create an empty database, fire up Terminal and type in:

    mysql --socket=/Applications/MAMP/tmp/mysql/mysql.sock -u root -p

    You might need to install some MySQL binaries, but you can use any other MySQL-Client (i.e. Navicat, phpMyAdmin) as well.

    The Password is usually just “root” (should be changed due to security reasons!)

    Once you are connected to the MySQL Server, create the Database:

    create database my_project;

    now, quit the MySQL-Client and shutdown the local MySQL Server:

    The easiest way to stop the server is by using the MAMP PRO UI:

    allright, now we need to move the physical location of the database:

    Go back to the Terminal and execute:

    cd /Library/Application\ Support/living-e/MAMP\ PRO/db/mysql/
    mv my_project/ ~/Dropbox/Sites/My\ new\ Project/database/

    This will move the created Database to your Project-Folder:

    And now the magic: We create a symlink to the folder which contains the database:

    ln -s ~/Dropbox/Sites/My\ new\ Project/database/my_project/ my_project

    Now we start the local MySQL Server again:

    allright, lets create a Table and see what happens:

    reconnect to MySQL:

    mysql --socket=/Applications/MAMP/tmp/mysql/mysql.sock -u root -p
    use my_project;
    CREATE TABLE `table` (  `id` bigint(20) NOT NULL auto_increment,  `column` varchar(255) NULL,  PRIMARY KEY  (`id`),  UNIQUE KEY `id` (`id`)) ENGINE=MyISAM;

    Resulting, you should see the some files popping up in the folder:

    Picture 6.png

    I like to have a localhost for each project, which can be easily accomplished in MAMP PRO as well:

    Well, thats it, now you can access “myProject.local” in any browser on your machine:

    Note: There is no index-file, that is why it shows the Forbidden-message.

    All changes that you make to the database and to the files within the project will be synced with Dropbox smoothly!

    On other Machines you won’t need to create the Database first since we can just link the DB-Folder to the MySQL-Datadir, do it this way:

    • Stop local MySQL-Server
    • Open Terminal
    • Execute:
    • ln -s ~/Dropbox/Sites/My\ new\ Project/database/my_project/ my_project>
    • Create the VirtualHost with MAMP PRO
    • Start MySQL and Apache again

    Another note, this wont (!) work with InnoDB-Databases since MySQL stores them differently!

    Enjoy

    Wednesday, 19th August of 2009. 04:41:00 pm

  • HOME
  • MY JOB
  • PREV
  • NEXT
  • i am fabian, a guy living in berlin and this is my tumblog.

    mail me: hello at fabian dot mu
    or @fabianmu me

    don't take this too serious.