简体   繁体   English

使用php连接到本地计算机上的生产服务器

[英]Using php connect to production server in local machine

I have some existing code in php for server side coding and the db is MySql. 我在php中已有一些用于服务器端编码的代码,而数据库是MySql。 Both resides on the production(realtime) database. 两者都驻留在生产(实时)数据库上。

Some job is given to me to fetch the records from the actual server and display in some format on local machine. 我得到了一些工作,可以从实际服务器中获取记录并以某种格式显示在本地计算机上。 I cannot duplicate the data onto my local system due to security reason. 由于安全原因,我无法将数据复制到本地系统上。 Any ideas how can i connect to production server and get my query run. 任何想法如何连接到生产服务器并运行查询。 I am ready to recreate the server side coding also....any help is appreciated.... 我也准备重新创建服务器端编码。

You will need to grant access to the production machine from your local machine. 您将需要从本地计算机授予对生产计算机的访问权限。 You can do so by granting all privileges on your IP address. 您可以通过授予IP地址上的所有特权来做到这一点。 For example, if your username was remote and your public IP address was 10.1.0.8 , you would use this: 例如,如果您的用户名是remote用户,而您的公共IP地址10.1.0.8 ,则可以使用以下命令:

GRANT ALL PRIVILEGES ON *.* TO remote@'10.1.0.8';
FLUSH PRIVILEGES;

Remember to flush your updated privileges! 记住要刷新更新的权限!

You can now connect to the production machine using PHP. 现在,您可以使用PHP连接到生产机器。 For example, if your production machine was at production.example.com , you would use this: 例如,如果您的生产机器位于production.example.com ,则可以使用以下命令:

mysql_connect("production.example.com", "remote", "My-p@ssw0rd");
mysql_select_db("example_db");

If you don't have root access to the production machine or can't grant privileges for some reason, you can also try to set up an SSH tunnel, if you have access to SSH. 如果您无权访问生产计算机或由于某种原因不能授予特权,那么如果您有权访问SSH,则还可以尝试建立SSH隧道。

Instructions on how to set up an SSH tunnel can be found here (Windows/PuTTY). 有关如何设置SSH隧道的说明,请参见此处 (Windows / PuTTY)。

You can then connect to whatever you used as local port using PHP as PuTTY will route all traffic through its SSH tunnel to the remote production server, making the production server to believe you connected from localhost : 然后,您可以使用PHP连接到您用作本地端口的任何端口,因为PuTTY会将所有流量通过其SSH隧道路由到远程生产服务器,从而使生产服务器相信您已从localhost连接:

mysql_connect("localhost", "remote", "My-p@ssw0rd");
mysql_select_db("example_db");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用PHP连接到本地计算机上的SQL Server - Cannot connect to SQL Server on local machine using PHP 本地机器上的PHP服务器? - PHP server on local machine? 为什么 unix 时间戳在本地机器与生产服务器 PHP 上出现不同:round(microtime(true) * 1000) - Why is unix timestamp appearing differently on local machine versus production server PHP: round(microtime(true) * 1000) PHP 图像:生成的图像在生产服务器上有右下角黑色边框,但在我的本地机器上没有 - PHP Image: generated image has right and bottom black border on production server, but not on my local machine PHP:生产服务器上的内存使用率非常高,而本地计算机上的内存使用率很低 - PHP: Very high memory usage on production server while memory usage is low on local machine 尝试使用php连接到本地服务器(ftp_connect) - trying to connect to local server using php (ftp_connect) 无法使用php函数将文件从本地计算机上传到服务器 - Unable to upload the file from local machine to server using php function 如何使用php将文件夹从Web服务器下载到本地计算机 - How to download a folder from web server to local machine using php 无法从本地计算机连接到Apache服务器 - Cannot connect to apache server from local machine PHP cURL无法连接到本地计算机上的IIS - PHP cURL cannot connect to IIS on local machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM