Home >Backend Development >PHP Tutorial >How to Securely Connect to a Remote MySQL Server Over SSH in PHP?
Securely Connect to a Remote MySQL Server over SSH in PHP
To establish a secure tunnel for PHP database connectivity, the following SSH tunnel solution offers a robust approach.
SSH Tunnel Setup
ssh -fNg -L 3307:10.3.1.55:3306 [email protected]
PHP Connection
Once the SSH tunnel is established, you can connect to the database securely through PHP using:
<code class="php">$smysql = mysql_connect( "127.0.0.1:3307", "dbuser", "passphrase" ); mysql_select_db( "db", $smysql ); </code>
This will establish a connection to the remote database via the encrypted SSH tunnel.
Benefits
The above is the detailed content of How to Securely Connect to a Remote MySQL Server Over SSH in PHP?. For more information, please follow other related articles on the PHP Chinese website!