Local Community

Using Dropbox to sync Local sites between computers under Local Classic

Boom well that was going to my first question how can I sync with dropbox etc so I can work on projects between a desktop and a laptop.

Thank you will follow the guide to set up my first project this way.

Sorry to revive a zombie thread, but has anyone figured out how to do this with Local Lightning? I’d like to be able to work with the same files across machines but with the newer/faster setup!

With Local Lightning you simply make a symlink in the filesystem. Volumes Add-on isn’t really necessary any longer.

1 Like

Yes, but the specific steps you have to take and/or paths you have to symlink are different. This thread started out with step-by-step instructions, so that’s what I’m looking for, in case there are major differences between the old Local By Flywheel and the new Local Lightning under the hood.

And it looks to me like there are big differences. I imported some sites to an iCloud Drive directory on my iMac right before getting a MacBook Pro. Then I used Migration Assistant to set up the laptop. It seemed like both installs of Local were working fine, using the same paths rooted in iCloud Drive, as long as they weren’t running concurrently.

But then I realized the databases were getting out of sync. It seems like Local Lightning doesn’t actually store the raw db data inside the Site path, but rather in ~/Library/Application Support/Local/run/[site-specific ID]. So you may need to copy something in this part of the filesystem onto your cloud storage and them symlink it back to your ~/Library on each computer in order to keep stuff in sync.

I would be interested to know if anyone has worked out the details!

2 Likes

I, too, would be interested in a step-by-step guide to syncing databases between installations of Local 5.1.X, even if it’s not officially supported.

I’ve posted elsewhere how to store Local sites on a shared drive and use the same set of files on each installation. But my method for database syncing is kind of clunky. It involves backing up the database on one installation using a plugin like Updraft Plus and then restoring it to the other.

I was able to make this work with Local Lightening. I find it to be a bit more complex than the previous method (I wish there would be a way to sync sites directly through Local), but for someone who works from a desktop and laptop quite regularly, having my projects in sync is essential.

I’ll probably create a more thorough step-by-step article soon, but here’s how I achieved it:

  1. Create a new website with Local on each computer, ensuring they have identical names and settings.
  2. On your shared server / cloud folder, create a folder with the same website name (this will house the shared files).
  3. Move one website’s app folder to your shared/cloud directory.
  4. In Terminal, type ln -s then drag the app folder from the shared/cloud directory into terminal (this is a quick way to get the path) then drag your local website folder in right after. The command should look something like this: ln -s path/to/shared/app path/to/local/website then press enter (you should see a symlink app folder appear in your local website directory).
  5. Next, locate the database folder by going to the “Database” tab in Local and following the socket path. The folder you want to go to will be a random combination of letters and numbers (right before the mysql folder). This should look something like /Users/Username/Library/Application Support/Local/run/G0xUGB4jj (every site will have a unique letter/number combination).
  6. Go to that folder in the Finder and similarly to before, drag the mysql folder to the cloud/shared directory
  7. Create a symlink from the shared mysql folder to the local directory, which would look something like this: ln -s path/to/shared/mysql Users/Username/Library/Application\ Support/Local/run/G0xUGB4jj (or whatever your folder is called). Press enter and you should see a mysql symlink folder appear.
  8. On your second machine, delete the website’s app folder and locate the database in the same manner and delete its mysql folder as well.
  9. Repeat steps #4 and #7 to create symlinks on your second machine pointing to the shared/cloud app and mysql folders.
  10. Now, both sites should be sharing the same website folder and database. If you make changes on one, they will be reflected on the other (but make sure you never run the sites at the same time or this will cause database conflicts).

Hopefully this helps anyone else that is looking to do the same thing!

3 Likes

Thank you @hellojd! I haven’t tried this yet but I hope to soon. Coronavirus has temporarily rendered the point moot for me. :wink:

For others who are interested in syncing Local sites, I can report that iCloud is probably not the best place to keep them.

The attraction of iCloud (on MacOS) is that I can keep my Local sites in my Documents folder and they’re automatically synced between computers.

The problem is that iCloud suffers some lag when between when files are deleted from your computer and when they’re deleted from the server. In normal file operations, this is not an issue. But when I update a plugin, I often wind up with two copies of all the files in the plugin folder – I see things like “plugin.php” and “plugin-2.php.” The plugin developer didn’t put the second file in there, iCloud did.

Here’s what happens: If the original pre-update files don’t get deleted from iCloud before they’re replaced with the new ones, iCloud tries to sync back the originals from the cloud to your computer. And so you get two copies of the same file.

A workaround for this is to manually update the plugins by deleting the old version of the plugin, checking to see that its folder gone from the iCloud server, and then adding back the new version. But a better solution is probably to use a different cloud service.

Hello everyone. I would very much like to get local working with dropbox. I am able to have both installs of local look at the same folder so my theme and plugin files are synced but the database doesn’t seem to be synced. I am out of my depth but what is the file in app/public/sql/local.sql? Is that not the database? Shouldn’t that also be syncing?

Thanks.

The file you have discovered is indeed the database. Or, rather, it is a copy of the database as it stood when your site was stopped in Local. But it isn’t the working copy of the database. That’s stored elsewhere. Getting that to sync is what all the business with Terminal is about.

If you want to sidestep all that, you can sync your database manually in a couple of different ways:

  1. One way is to import the database copy that you have found app/public/sql/local.sql. You can do this using Sequel Pro, which you can download and then open from inside Local. You might have to delete all the tables in the database before importing. Or maybe you can just overwrite.
  2. Another way is to use a backup plugin (UpdraftPlus is a good one) to make a backup of your database on computer A, and then restore it on computer B.

I prefer method 2 because you always have a backup. But you do have to remember to backup computer A before you switch to computer B.

Okay! I’ve tried the database sync method described by @hellojd above. It works perfectly!!!

I did it a little bit differently on my setup, though. I began with an existing site folder that I was already sharing between two computers on a cloud drive (iCloud for now, although see my cautions about iCloud above). I created it in the following way:

  1. Create a site in Local on Computer A, with the site path on the shared drive.
  2. Hide the site folder that was just created by moving it inside another folder (or just delete it – see below).
  3. Create a site in Local on Computer B, with the site path in exactly the same location as the site you created on Computer A.
  4. Delete the hidden folder. You no longer need it because Local on both computers will use the same site folder on the shared drive (the one you created from Local on Computer B).
  5. If you’ve already got a working site from computer A on the shared drive and you want to be able to access it from Computer B, then instead of deleting the site folder from Computer A, delete the one you’ve just created from Computer B and unhide the one from Computer A.
  6. If the existing site from computer A is not on the shared drive and you want to have a single shared site folder, then export the site on computer A to a zip file (right click the site in Local and choose "Export) and then reimport it with a site path on the shared drive (choose “Advanced Options” when you import the site).
  7. If you’re doing all this on iCloud be careful that the cloud is updated with all the file operations before you continue or you may find that your local files are being overwritten by older files not yet deleted from the cloud. iCloud can be slow about file operations (see my caution above). If you’re not sure, go to your iCloud Drive at iCloud.com and do the file operations there.

Now, you could just stop here and sync the databases manually as I described in the previous post. But if you want to go farther and sync the databases automatically, as described by @hellojd above, it’s a simple two-step process.

1. On Computer A, find the mysql folder and drag it to the site folder on the shared drive.

  • It’s located in /Users/Username/Library/Application Support/Local/run/G0xUGB4jj where “G0xUGB4jj” is the unique, randomly generated name of the folder containing the database for your site. The name of your folder will, of course, be different.
  • You can find the name and location of your database folder by clicking the Database tab in Local and looking under “Socket”.
  • If the Library folder doesn’t appear in your User folder, right click inside the User folder and choose “Show View Options” and select “Show Library Folder.”
  • Open the folder (“G0xUGB4jj”) that contains your database. Inside this folder is a folder named “mysql.” This is the folder you want to sync.
  • Move the mysql folder to the site folder on your shared drive. Don’t worry about keeping a copy of it in its original location. You don’t want it there anyway, because you’re going to replace it with a symlink to its location on the shared drive. If it doesn’t disappear when you drag it to the shared drive, then delete it (just make sure it’s present on the shared drive first).

2. Create the symlink.

  • A symlink is a UNIX feature that is similar to a MacOS alias. Unlike an alias, it can’t be made from within the Finder. You have to use Terminal. But for this purpose an alias won’t work (at least it didn’t for me).
  • Open the Terminal app
  • Type ln -s
  • Drag the mysql folder from the shared drive into Terminal to copy its location
  • Drag the database folder (e.g. “G0xUGB4jj”) into Terminal to copy its location
  • You should now see something like this in Terminal: ln -s path/to/shared/folder/mysql Users/Username/Library/Application\ Support/Local/run/G0xUGB4jj (or whatever your folder is called).
  • When you press Return, UNIX will create a symlink inside the G0xUGB4jj folder. Open up the folder and see. It looks just like an alias, with a little arrow in the lower left corner, but it’s really a UNIX symlink.

You should now be able to run Local normally. Start the site and it should work just like a normal installation.

On Computer B, the process is the same, except that in step 1 you’re just going to delete the mysql folder from the “G0xUGB4jj” folder rather than copy it to the shared drive. You’ve already got a copy of mysql on the shared drive from Computer A. Local will use that one for both computers. You’ve still got to create the symlink, though, so step 2 on Computer B is just the same.

If everything is as it should be you should now be sharing the database on the two computers. It actually takes less time to do than it does to describe it.

Try running the site from each computer, one at a time, to check your work. Remember not to run the site on both computers at the same time or you’re likely to run into database conflicts. You don’t have to quit Local, just stop the site on Computer A before you start it on Computer B.

Finally, if these are not both new sites (i.e., if you’re creating a copy of an existing site on a different computer), make sure that it is indeed the database from Computer A that you want to share with both computers before deleting the mysql folder from Computer B.

1 Like

Thank you so much for such a considered and thorough reply. Of course I wish it could just be synced as easily as any other file. That said, I will try some of these ideas. Best regards.

Man this seems like such a convoluted way to do it. I am surprised that Local has not put this into the software since it gets talked about so much. This is the main reason I am still using MAMP Pro. If they brought in this feature and it worked as easy as MAMP Pro does I would never touch it again.

Please, can’t one of the wizards at Local add this feature for us? I for one would be more than willing to pay a yearly fee. I often switch from my desktop in my home office to my laptop when I’m out and about. Pushing and pulling from a live site just for the sake of this, when other solutions like MAMP Pro have had this capability for years, feels clunky and wrong, not the future.

2 Likes

Hi @MikeThomasDev!

Thanks so much for the feedback and I am happy to say this request is already on our radar! If you haven’t already upvoted this request on our public feature request board I’d recommend it. We use this board to help us prioritize work.

Also, would you mind sharing how you accomplish this with MAMP? This info will really help our team understand what we could be doing to make this workflow possible for you!

I switch between machines and OSes frequently. I found it easier to use docker to bring up sites, work on them, save them and bring them down with files saved and synced in dropbox. Its as easy as docker-compose up.

The easiest method is to use the docker-compose.yaml on this site:

I have forked that code to add mailhog and a plugin that works with mailhog (there are also some experimental features that can be ignored). That system is here:

It would be ideal if local could just launch a site from a folder in dropbox without any issues or hoops to jump through. Until then, Docker is easier.

Thanks for those links! Are there specific OSes that you are using? I’d especially be interested if you are syncing between Windows and a more Unix-y OS like Mac or Ubuntu (or other!)

One other aspect of this – are you ever working on two computers at once, or are you always shutting down the docker containers before going to work on the other machine?

It looks like the nezhar/wordpress-docker-compose repo stores the raw database files in a folder called wp-data after the site is docker’d up. I’d be curious if you ever run into issues with the raw DB tables being corrupted due to syncing with Dropbox.

I use Linux Mint primarily, followed by MacOSX, and Windows when I have to. It is better on Windows now that Docker is integrated with WSL2. All of the same scripts work.

When I create a new site, I increment the external port numbers by 1. That way, I can work on multiple sites at the same time on “localhost”. If I run the WP container on port 80, I can give access to the LAN, or the Internet to share the site. I also use ngrok for this purpose.

It would not be advisable to work on the same sites on separate computers at the same time, since you would get sync errors or clobbering.

The WP-data folder stores the entire dB in a SQL script. This is created when you run the export.sh script. It is advisable to run this frequently while working on a site. This way you have previous versions of the DB. I also make file backups, but having the site and dB in Dropbox means that you have automatic versioning and backups. The SQL script is loaded as soon as you run Docker-compose up.

Once in a long while the SQL doesn’t load and I have to reload it with PhpMyAdmin or an import script (the opposite of the export script).

2 Likes

Thank you! This still works great for me via Dropbox between two macOS Big Sur PCs.

1 Like

I have a Mac laptop and a Windows Desktop. Has anyone tried to do a setup like this? I am thinking it is not possible as the file structures are different…?

This might be tricky if you are trying to sync the actual “run” folder (ie the raw DB files and server config) if you are just syncing the Local Sites folder, then it might be easier.

The new Cloud Backups add-on doesn’t sync between computers at this time, but being able to sync a site is on the radar for improvements to the add-on and should be worked on soon. To be specific – syncing a site would be creating a backup on one machine and restoring on another.