-1

I'm trying to connect my Drupal 8 website to a mysql database hosted on a different server, which is only accessible through SSH. I can connect my database manager (heidiSQL) with a SSH tunnel, but i was wondering if it's possible to connect Drupal via SSH too?

thanks in advance!

Edit; To clear things up a bit: The drupal setup is running localhost on my pc, the database is running on a webserver at our ISP. I could download the database to my pc and connect to it locally, but we're working on this site with multiple developers and want to share just one database so we all have the same data.

Edit 2; The SSH connection is made with a SSH key, so no username/password pair.

  • Did you try Drush? – Kevin Feb 8 '19 at 16:26
  • @Kevin: please read my addition, i think my initial question was a bit ambiguous ;-) – Sander Feb 8 '19 at 16:35
  • Nah, that's a very bad idea. Connect to the live database from your local site during development? What could possibly go wrong? – leymannx Feb 8 '19 at 17:27
  • 1
    but we're working on this site with multiple developers and want to share just one database so we all have the same data this will get messy as config inevitably changes and trying to manage exports. Among other things. – Kevin Feb 8 '19 at 20:10
  • 1
    What Kevin says. Imagine one developer adding a new module and enabling it. And all other devs not having that module added to their local code base at that time, nor at the instance from where you want the shared database to be used. Very, very bad idea. Instead provide a little bash script/command all your devs can use to pull down and import the shared database easily. – leymannx Feb 9 '19 at 11:29
2

If you can connect to mysql over ssh using another client (like the mysql command line client or something like SequelPro) then Drupal should also work with the same settings. I don't have experience with heidiSQL, but I suggest just copying the settings that worked in heidiSQL into your Drupal settings file and see how it goes.

One concern: This might make your page load very slow, though, as Drupal makes a lot of queries with each page load and my experience is that the network overhead of mysql-over-ssh is a bit high.

  • Thanks Greggles, but i'm not sure i can just copy the settings from HeidiSQL to the drupal settings.php. As far as i know i can only use direct mysql connections but i'm looking for a way drupal can connect through a SSH tunnel to my mysql server. In heidiSQL my settings are like this: cinnamon-vms.nl/heidisql.png How do i create a SSH tunnel via settings.php in drupal? – Sander Feb 11 '19 at 8:14
0

after some more digging i found a way to connect to the database through an SSH tunnel;

https://www.linode.com/docs/databases/mysql/create-an-ssh-tunnel-for-mysql-remote-access/

I hoped for a solution within the drupal config file (perhaps with some extra extensions) but this will do the trick.

  • Glad you got it working. This is what I assumed you meant in the original post when you said you had the ssh tunnel setup and working with heidisql. For good StackExchange flow, it's ideal to copy and re-state the key elements of the article that has been linked in case that 3rd party site goes offline. – greggles Feb 12 '19 at 22:06
  • @Sander When you are ready for performance tuning, view my profile, Network profile. – Wilson Hauck Aug 15 '19 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.