Tuesday, June 28, 2011

How to connect mysql database from joomla web server on local network

SITUATION

you have 2 Server one is joomla web server(192.168.1.52) and 2nd is database server (192.168.1.51)

Now you want to connect your joomla webserver to database server.Install Ubuntu server 10.10 in both server and also install LAMP with openSSH server with Client.
Connect with same local area network.

Step -1 (in database server)

configure mysql configuration file by typing following command:

sudo nano /etc/mysql/my.cnf

Make sure line skip-networking is commented (or remove line) and add following line

bind-address=192.168.1.51 (YOUR-DATABASE SERVER-IP)

now save and Close the file then reboot the server

Step-2 (In database server)

Grant access to a new database

Connect mysql localy by typing following command

mysql -u root -p mysql

If you want to add a new database called shah for user joomla and remote IP 192.168.1.52 then you need to type the following commands at mysql> prompt:

mysql> CREATE DATABASE shah;
mysql> GRANT ALL ON shah.* TO joomla@'192.168.1.52' IDENTIFIED BY 'PASSWORD';

How Do I Grant Access To An Existing Database?Let us assume that you are always making connection from joomla web server IP called 192.168.1.52 for database called shah for user joomla, To grant access to this IP address type the following command At mysql> prompt for existing database, enter:

mysql> update db set Host='192.168.1.52' where Db='shah';
mysql> update user set Host='192.168.1.52' where user='joomla';


Type exit command to logout mysql:

mysql> exit

you can also do this by phpmyadmin

just use following setting while making new database in phpmyadmin

user name = joomla (you can use your own name)
password = password (you can use your own)
host = any host (you can also put here your joomla webserver static ip so only your web server will be able to access in your local net)
Priveliges = check all (check all and Grant all Access)

Step-3 (In joomla web server)

Test your database connecting properly.

mysql -u joomla –h 192.168.1.51 –p


Where,
-u joomla: joomla is MySQL username
-h IP or hostname: 192.168.1.51 is MySQL server IP address or hostname (FQDN)
-p : Prompt for password

Step-4 (In Joomla web server)

You can now install joomla into your joomla web server (192.168.1.52)
and put database server ip address(192.168.1.51) in host filed

Lets assume that you want to connect another server called audio.joomla.com so
you just copy and past your joomla installed folder i.e. /var/www
into new server in the folder /var/www
and chenge the configuration.php file as follows:

host = 192.168.1.51 (your database server ip)