Jump to content

PHP with separate SQL server


RyanF109
 Share

Recommended Posts

I've been trying to do this for days on multiple Linux distros with no luck.

I decided (out of sheer curiosity) to attempt to build from source...

  • Apache
  • PHP
  • MySQL

I wanted MySQL server on a separate server from the PHP and HTTP ones; but I can't seem to get PHP to connect to MySQL.

./configure --with-mysql

doesn't seem to include the SQL libraries (I think I'm using the correct terminology) and

phpinfo();

shows no sign of MySQL, only SQLite. I tried installing a MySQL "Connector" for PHP.

My question is.... How on earth do I configure PHP for a remote MySQL server?

Link to comment
Share on other sites

Would it not be a security issue if you could?

(not an expert on the subject, I work with PHP/SQL on a daily basis but it's more building content/systems rather than server type stuff)

Link to comment
Share on other sites

Install MySQL as you would with that machine, even though you're running --with-mysql, to my knowledge if it can't find the appropriate libraries it will stop configuring MySQL.

You can easily install MySQL on another machine/server, and set it up as normal. PhpMyAdmin would help here, you need to edit the users for MySQL and allow connections from your other servers host (by default they are only set to allow connections from localhost/127.0.0.1).

Providing you lock it down and don't add wildcards to open up MySQL to everyone, it'll be fine just allowing an additional host in - I've done it numerous times when doing client work etc.

Link to comment
Share on other sites

Would it not be a security issue if you could?

(not an expert on the subject, I work with PHP/SQL on a daily basis but it's more building content/systems rather than server type stuff)

Surely it's more secure since the server with MySQL isn't being directly accessed by the WWW. Instead the Local HTTP machine will be connecting to the local mysql machine, which can then be locked down so as only to allow access to the HTTP machine.

Link to comment
Share on other sites

It wouldn't be a security issue, no as you would set the DB server security appropriately and only allow access from the webserver IP address.

What distribution are you installing Apache/PHP on? You will need the php-mysql module installed and enabled for PHP to find it.

On Ubuntu (and possibly Debian) the package you need is php5-mysql (assuming your using PHP5), which can be installed with 'apt-get install php5-mysql'. On Fedora its php-mysql, installable with 'yum install php-mysql'. I know this is the default install rather than from source, but may still help.

As far as I'm aware PHP doesn't really care where your DB server is, so you just need to configure it for MySQL rather than remote access to a remote MySQL server, which is just done by specifying the IP address etc on your mysql_connect calls.

You will need to make sure that the MySQL user account is set up to allow access from the webserver host by having a user record allowing access from the host rather than just from localhost. Good luck!

Link to comment
Share on other sites

GRANT ALL ON database.* TO [email protected]'000.000.000.000' IDENTIFIED BY 'password';

Is what you want, obviously substituting in the values at the end - it's a fairly simple process thumbsup.gif

Edited by Alex_H
Link to comment
Share on other sites

Solved the problem. Thanks for all your replies.

The problem was as follows...

I noticed that on phpinfo() the build timestamp was the first ever time I'd attempted to build php (when I hadn't included "--with-mysql" so when I was running

./configure --with-mysql
make
mae install

It wasn't overwriting some files that already existed so I had to remove files first then rebuild with the correct options.

I just ran...

find / | grep "/php/"

and removed any resulting directories.I then recompiled PHP with the correct options set.

Edited by RyanF109
Link to comment
Share on other sites

There is usually a "make clean" argument to clear up after a failed / different previous make call as well.

As for the security risk of a different MySQL server - it isn't really much of one. Almost any largish PHP/MySQL project will use seperate servers for each due to scaling issues. If you think about it and configure things appropriately it is actually likely to be more secure than just an out of the box apt-get install or whatever.

Link to comment
Share on other sites

 Share

×
×
  • Create New...