Mysql – How to connect to MySQL database running on WAMP server from other computers in same LAN

MySQLphpmyadminwamp

I'm new in web development. I'm requesting help from all of you. My problem is:

I installed WAMP server in my desktop computer. My desktop computer has a static LAN IP (192.168.0.101).

I'm able to access WAMP server homepage from my other computers connected to the same network by using the LAN IP (192.168.0.101).
But while I was trying to access phpMyAdmin from other computer it says:

Forbidden. You don't have permission to access/phpmyadmin/ on this server. Apache/2.4.9(Win64) PHP/5.5.12 Server at 192.168.0.101 Port 80.

I also tried to connect to the MySQL database running on my desktop computer using cmd in other computer by the following code, mysql -h 192.168.0.101 -u root -p (there is no password for root user).

Please help me how could I be able to access phpMyAdmin and MySQL database from other computer connected to the same network.

Best Answer

WAMPServer is primarily designed for use on a single machine i.e. a developer writing and testing code locally on that PC.

So to protect the beginner from his/her self the Apache & MySQL configuration by default is setup so no access can be made to the Apache or MySQL server form anywhere but the PC running Apache and MySQL.

When changing this configuration great care should be taken to only allow access that you intend and not global access. So be VERY CAREFUL with any help/tutorial that suggest adding Allow from all or Require all granted as they either dont really know what they are doing or the help is based on giving access to the site to the whole internet.

To allow access to phpMyAdmin you need to change the Alias configuration for phpMyAdmin, so edit wamp\alias\phpmyadmin.conf and add an instruction to allow access from any ip address on your internal network like so :-

Alias /phpmyadmin "d:/wamp/apps/phpmyadmin4.1.14/"

<Directory "d:/wamp/apps/phpmyadmin4.1.14/">
   Options Indexes FollowSymLinks MultiViews
   AllowOverride all
  <IfDefine APACHE24>
    Require local
-->     Require ip 192.168.0
  </IfDefine>
  <IfDefine !APACHE24>
    Order Deny,Allow
      Deny from all
      Allow from localhost ::1 127.0.0.1
-->     Allow from 192.168.0
    </IfDefine>
  php_admin_value upload_max_filesize 128M
  php_admin_value post_max_size 128M
  php_admin_value max_execution_time 360
  php_admin_value max_input_time 360
</Directory>

If you actually want to access MySQL via the mysql.exe processor and other tools like it from another IP address you have basically the same problem.

MySQL user account are made up of 2 parts, a UserId and a Host. The Host part tells MySQL where this userid is allowed to connect from. If you look using phpMyAdmin at the user accounts that are pre-created in MySQL you will see that the Host part of all the account is either 127.0.0.1 or localhost or ::1 all of which equate to The PC running MySQL. Again for the security of the beginner no access allowed from outside the PC running MySQL.

So to use mysql.exe etc, I suggest you create a new MySQL User Account, lets say MAKhan with a Host of 192.168.0 AND OF COURSE A PASSWORD. That account will them be allowed to login to MySQL from any ip on your local network. You will of course have to give rights to this new account so that it can access some or all of the databases on the MySQL server.