开发者

Setting up scripting and mysql database on separate servers

I have a unique setup for a web application that I need to get my head around.

I have two servers that will need to talk to each other. Server A will host the actual PHP-based application; Server B will host the MySQL database and the server connection details. Server B will also be within a closed network, so that only people on the local network will be able to access the server, whereas Server A will be web based.

If the visitor has access to the local network for Server B, they should then be able to, through the scripting on Server A, connect to and access the database on Server B to complete the pic开发者_如何学编程ture.

My first question is: is this possible? I think it is, but I am not 100% sure.

Secondly: How would I write the script for accessing the Server B script? Is it similar to accessing an include file or would it be a remote HTTPS call? I'm just not sure how to go about making this happen.


Remotely connecting to a MySQL database should be no problem. Here is a pretty thorough guide Enabling Remote MySQL Access. I was able to get this to work by a simple setting in WHM called Additional MySQL Access Hosts. Visiting this area from Server B you would be able to add the IP address of Server A, allowing Server A to connect to Server B's Database by using this format:
mysql_connect("IP Address of Server B","DB_username","DB_pass")
or whatever your preferred MySQL connection function is.

If this doesn't work right away though, you may need to make some changes to firewall settings, but to my knowledge what you need should be possible.


I'm not sure but I don’t think this is possible using PHP. PHP is server sided so It's the server that has to have access to the MySQL server, the client doesn’t come into play...

There is many way to secure the MySQL server to accept connection only from server A thought...


The first point is that it's not a good architecture for availability. If you just had a single machine running both PHP and DBMS, then you've got a single point of failure. This is not a good scenario for availability. With PHP and DB on separate machines you've now got two single points of failure! Worse!!

But we'll leave that for now.

Yes, it would be possible to gate access via PHP, but PHP does not natively implement the MySQL protocol - so you'd either have to

  1. do an awful lot of programming to implement a MySQL protocol proxy with additional functionality.

  2. update the MySQL permissions table to allow the remote host on a temporary basis

Really you don't want any access to your web server from outside your subnet.

However, if the machine has access to the "local network" then all you need to do is drop a port reflector somewhere on that not network and then point the clients at that instead of the DBMS. The DBMS would see the client address as that of wherever the port-reflector was running (it might even be running on a different port of the DBMS server itself.

However, we'd need to know a lot more about what you mean by "access to the local network".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜