levye
By:
levye

How to connect remote MySQL via Apache and SSL?

November 5, 2017 131 views
MySQL Apache Ubuntu 16.04

Hi,

I have MySql installed on my server and I am using Apache as a proxy server to my Tomcat. I have SSL certificate installed. My current configuration is,

Apache :443 port requests ---- direct to-----> tomcat :8080
Apache :80 port requests -----direct to -----> web site

MySql installed and listening to default port 127.0.0.1:3306

So I have apache in front of everything and accepting :443 secure and :80 connections only.

I am trying to connect to my MySQL server remotely so any idea how can I do with SSL or without (i don't prefer)

I have tried such solution below but it seems not working.

  • I have configured Apache to listen also 444 port for SSL
  • I have defined another virtual host on Apache to direct requests coming from 444 port to 127.0.0.1:3306

ANY SOLUTION?

thanks

2 Answers

Apache doesn't speak the mysql protocol, so your vhost is trying to relay http to a mysql port.

If you're just doing some one-off stuff and you can live with a web interface you could install phpmyadmin and you can run queries through it.

If you have an query tool type application like mysql workbench on your local machine and you want to talk to mysql on your droplets it's best to use an ssh tunnel via ssh -L3306:localhost:3306 yourdroplet. As long as your ssh tunnel is alive port 3306 on your local machine will be connected to port 3306 on the mysql server on your droplet. Then you just tell the application to connect to localhost with the same user details. This trick isn't the best if you want to use it for unattended jobs and one-off changes - it's not stable enough for automated use.

Hi ,

Thanks for the response.

I have tried it and getting error (either connection is being refused or getting timeout.)

1- As far as i understand, I need to add tunelling when i connect to my droplet through SSL (I am using putty so i added tunelling to my connection via putty)
So that i believe that ssh -L3306:localhost:3306 yourdroplet. command will be executed on my droplet. So 'localhost' there is my droplet actually. *Is that correct ? *

I am using below options for tunelling on Putty
Source port: 3306
Destination: [mydropletip]:3306
Local

2- I have also changed bind-address in my mysql config to 0.0.0.0 in order to accept remote connections. (it was 127.0.0.1 before for security) Is that step also correct?

3- I am not also sure if i should choose "Standart TCP/IP over SSH" or " Standart TCP/IP " on MySQL Workbench ? I am trying to connect with below parameters after making tunellign

SSH Hostname: [mydropletip]:22
SSH Username : [mydropletlogin username]
MySQL Hostname: 127.0.0.1
MySQL Server port: 3306
Username: [MySQL login user name]

4- Lastly my firewall output is shown below,

root@yarimelma:~# ufw status
Status: active

To Action From


8080 ALLOW Anywhere
Apache Full ALLOW Anywhere
22 ALLOW Anywhere
8080 (v6) ALLOW Anywhere (v6)
Apache Full (v6) ALLOW Anywhere (v6)
22 (v6) ALLOW Anywhere (v6)

should i also allow 3306 port?

I am not sure where i am doing wrong ? Any idea?

Many thanks

Have another answer? Share your knowledge.