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:
$smysql = mysql_connect( "127.0.0.1:3307", "dbuser", "passphrase" );
mysql_select_db( "db", $smysql );
This will establish a connection to the remote database via the encrypted SSH tunnel.
Benefits
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3