I’m trying out the new Trellis/Bedrock/Sage setup for the first time and I’m running into some questions;
My previous workflow for development websites was with MAMP Pro where I synced my database and htdocs folder with dropbox so I could work from both my computer at work and at home on the same project. Managing my databases was done with phpMyAdmin so I could export my database, find and replace path and domain names and import to my production environment.
Now with Trellis I would like to have a similar setup where I can continuing working on a project on a different computer, so my first question is:
Where are the databases stored created with MariaDB with the vagrant up command? Can’t seem to find them anywhere? I read it is embedded in the virtual machine file, but can’t seem to locate that either? And if it’s outside the main project folder, could I somehow either:
Move them inside the main project folder and keep that synced through dropbox?
Symlink them to a separate database dropbox folder?
How can I manage the database through an graphic interface, so I can export etc.?
It doesn’t have to be phpMyAdmin, Sequel Pro is fine too. When I try to enter my database credentials as entered in group_vars/development in the Sequel Pro quick connect I get an error:
Unable to connect to host (null) because access was denied.
Double-check your username and password and ensure that access from your current location is permitted.
The host should be localhost right?
Since I don’t have SSH access on most of my production servers, I can’t use the last Deploying to remote servers step in Trellis. So my last questions would be;
Should I only FTP the contents of the site folder to my production server or is the ansible folder also being used on the production environment?
Which configuration files should I edit on the production server in order to have it running just like it would with deploying it with Trellis? Just the .env file or are there any other files that need editing?
Sorry if any of these questions are too nooby or already being answered somewhere else, but it seems everyone over here somehow has SSH access to all of it’s production servers…
The new example_dev directory could be synced via dropbox.
My assumption and hope is that you could sync this directory with the DB on the VM at /var/lib/mysql/example_dev using some variation on how the Vagrantfile syncs the bedrock site directory (see sync folder declarations and helper functions).
The directory is empty till the VM creates your DB, etc.
So, when you are working with Trellis (or any virtual machine for that matter), you can share folders with it. But remember, this is another virtualized computer, in essence. So just like you have all your system files on your computer, this virtualized system has all it’s own system files and folders. This is why a typical Ubuntu Trellis box is ~2-3gb.
Not every folder is shared between your computer and the virtual machine. So the database files are not being stored directly on your host system like OS X. You will most likely find a ~/VirtualBox\ VMS/VM_name/box-disk1.vmdk or something similar. That is the virtual hard drive of the virtual machine. It’s not directly accessible.
Ok that clears things up, thanks!
So basically I can’t sync the database directly because it’s not accessible on the host machine where dropbox is running, but I could sync the whole VM box? Only disadvantage is that it needs to sync 3 gb every time the VM changes…
correct. BUT, the Vagrant sync folder feature bridges the gap. Once you set up a sync folder, vagrant keeps the folder on your regular host machine in sync with a folder on the guest machine, so, it’s almost like having dropbox sync the database directly.
No, don’t do it!
Only ever pick the folders you want to sync and set them up as vagrant sync folders (see my various links above). For the DB, your dropbox will only be syncing the example_dev db folder, which is only about 4K on a new Trellis VM. Of course, you’ll add to the DB making it bigger, but not as big as 3GB.
If it seems confusing, like we’re saying contradictory things…
“you can’t access folders on the VM”
“just sync a folder on the VM”
…read up on Vagrant sync folders. They let a folder on your regular (host) machine sync with – or mirror – a folder from inside the VM guest machine, which VM might otherwise be a black box to your regular host machine.
Just FYI - you should never, under any circumstances, sync the raw files of any InnoDB tables using Dropbox, or something similar. MyISAM is a bit safer, but you will eventually corrupt your InnoDB tables - it’s just a matter of time.
I haven’t tried syncing raw database files and it sounds like those who have tried saw corrupted tables. Maybe someone else will have better ideas, but you may just have to do an sql dump to a dropbox folder when you leave one work location, then import the db when you arrive at the other location. You could dump/import with Sequel Pro, WP CLI, WP Migrate DB Pro, etc. Maybe you could automate it.
Maybe someone familiar with RDS could comment on whether an RDS setup would work, but maybe that’s overkill for syncing two dev DBs.
All that said, yes, you need to manage owership on sync folders using vagrant-bindfs, as is used with site_path. I think the user:group of the raw db is root:root (you could double-check if you haven’t already), but again, it’s probably best to not sync the raw db files. You tried root:root and it failed, but I suspect it would work once you add in the bind folder. For reference on implementation, here is where Trellis began using vagrant-bindfs to handle permissions: roots/trellis#82
As for how to access variables from wordpress_sites in the Vagrantfile, you could use wordpress_sites['example.com']['env']['db_name'], but maybe there is a smarter way. Replace example.com with whatever your site key is. site['env']['db_name'] would work if you were looping over the sites, each site represented by the site object.
Wordpress is installed correctly, and all the database tables are in my db folder and I can see them changing when changing options in wp. However when running vagrant halt and then running vagrant up --provision again, the database is already corrupted and I get the following error:
One or more database tables are unavailable. The database probably needs repairing.
Not sure if there’s a fix for that, but for now I’m not gonna bother anymore…
Thanks for all your help!
Good progress. As @kalenjohnson mentioned, you might check out the approach VVV is using. Looks like they’re syncing the entire /var/lib/mysql directory instead of just the db and they use some different options on the sync folder. There are a few other database notes in their README that might have ideas for you.
You might also try to get the vagrant sync part working to your satisfaction and only then make the folder a dropbox folder, to isolate any possible issues dropbox may cause in its handling of the folder.
I didn’t look carefully at VVV, but after a quick glance it looks like they have it working, so you could keep digging in to their approach if you’re set on making it happen. Maybe vagrant-triggers (also used in VVV) could automatically dump/import and sql file on each halt/up. I haven’t used any of the above, however. Good luck!