Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

403
Views
Connect to remote MSSQL server with PHP through SSH tunnel

Firewalled MS SQL server wants to supply data to Ubuntu server on the internet.

So I establish an SSH tunnel from the MS SQL server to Ubuntu server, asking Ubuntu to send its port 1433 traffic to MS SQL's port 1433.

According to this Stack Overflow answer, I think I should be doing this on the MS SQL server:

ssh -R 1433:localhost:1433 ubuntu.example.com

It's a Windows machine, so I did this in PuTTY:enter image description here

In the local network, I've tested using PHP to connect to the SQL server and it works.

$server = '192.168.0.12';
$user = 'buttle';
$pass = '1234';
mssql_connect($server,$user,$pass);

Now I want to try connecting the same two machines using an SSH tunnel instead of "direct" connection. So I change $server to this:

$server = 'localhost,1433';

And then I connect an SSH tunnel from the SQL Server machine to the Ubuntu machine with PuTTy. And perhaps this is where I'm going wrong, because I don't know what I'm doing.

PuTTY Tunnels configuration

I'm getting this PHP error on the Ubuntu machine:

Warning: mssql_connect(): Unable to connect to server: localhost,1433 

EDIT:

Also tried this:

enter image description here

And this:

[![Remote IPv4 with IP address specified in MS SQL server][5]][5]

FINALLY, I have solved it. See my answer.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

All of the online tutorials for using PHP's mssql functions assume you are running PHP in a Windows environment. Apparently, in Windows, IP and Port Number are separated by a comma, but in Linux by a colon.

// Linux running PHP
$server = 'localhost:1433';
// Windows running PHP
$server = 'localhost,1433';

As usual, hours of problems boil down to a single byte.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!