[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

How to configure PHP & MySQL so that Apache+PHP in one Linux server can work with MySQP at another Linux server

Hi,

Assumed that Apache+PHP are installed in a server (private IP Address: 192.168.0.3) and MySQL is installed in another Linux server (private IP address: 192.168.2.5). What I should do to configure PHP and MySQL so that they can work with each other (the same as when we install all of them in only Linux server)?

Thanks a lot for your help,

rfr1tz
0
rfr1tz
Asked:
rfr1tz
  • 3
  • 2
1 Solution
 
VGRCommented:
nothing.

Just make sure your MySql server (mysqld) accepts commands and requests from host#1 (Apache+PHP)

And set up your MySql connections to use IP@ of the MySql server, like this :

$linkID=mysql_connect('192.168.1.2',"$dbLogin","$dbPassword") or die ("bad connect".mysql_error());

mysql_select_db($dbName,$linkID) or die ("bad select DB ".mysql_error());

$query=" [snip]

basically, it's just a rights/IP@/login/password thing to check. Should be easy.
0
 
rfr1tzAuthor Commented:
Hi VGR,

Thanks a lot for your reply. I think you've put out very good details on MySQL sides. For Apache+PHP side, I've a question: how Apache+PHP knows that it should send any communication with MySQL to the server with IP address: 182.168.2.5 and don't look to anywhere else? Should I need to set something about IP Address and port number for database connection on Apache+PHP?

Thanks,

rfr1tz
0
 
VGRCommented:
yes, that exactly what "$linkID=mysql_connect('192.168.1.2',"$dbLogin","$dbPassword") or die ("bad connect".mysql_error());" is about 8-)
It is the PHP (as an Apache module or not) code to access a remote MySql DB on the host '192.*' with user/pw

with a simple GRANT *.* ON ... on the MySql side (flush privileges too, see dox) you should be on in a minute 8-)
0
 
rfr1tzAuthor Commented:
Hi VGR,

Thanks a lot for details you've put out. Because I'm pretty new to both Apache+PHP and MySQL, may you give more details about how to set $linkID; for example, which system file I need to set this or can I do it via GUI (KDE). The same for mysql_select_db, $query="[snip].
For $query=..., I see only 1 quote, do we need another quote at the end?
On MySQL side, do I need to do anything else besides successfully starting MySQL so that MySQL accepts commands and requests from Server #1? For example, do I need to set MySQL needs to listen to any port or any connection, etc?

Thanks  a lot for your help and sorry if the questions are trivial,

rfr1tz

0
 
VGRCommented:
the (pseudo, $query is not erminated, right :D ) code I posted is PHP code.

I suppose you've some front-end language to MySql

Look in its 'MySql functions'.

I may help for PHP though
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now