Configure XAMPP LAN network

0

I have 2 computers under the same LAN, in both I have installed XAMPP, but I want to have the site mounted on one, and on the other PC the DB. In the php connection file I changed "localhost" to the local ip of the other pc, but it does not work for me.

When loading the page I get this error:

  

mysqli_connect (): (HY000 / 2002): Unable to establish a connection anymore   that the destination team expressly denied such connection.

Any other information, I will be attentive to the comments.

Datos del pc con el sitio : 192.168.0.3
Datos del pc con la BBDD : 192.168.0.23

My PHP connection:

private $server = "192.168.0.23";
private $usr = "root";
private $pass = "";
private $db = "abm";

MySQL configuration file of the PC with the BBDD (192.168.0.23):

# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# You can copy this file to
# C:/xampp/mysql/bin/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is C:/xampp/mysql/data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients [client] 
# password       = your_password  port            = 3306  socket          = "C:/xampp/mysql/mysql.sock"


# Here follows entries for some specific programs 

# The MySQL server
[mysqld]
port= 3306
socket = "C:/xampp/mysql/mysql.sock"
basedir = "C:/xampp/mysql"
tmpdir = "C:/xampp/tmp"
datadir = "C:/xampp/mysql/data"
pid_file = "mysql.pid"
# enable-named-pipe
key_buffer = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log_error = "mysql_error.log"

# Change here for bind listening
# bind-address="127.0.0.1" 
# bind-address = ::1          # for ipv6

# Where do all the plugins live
plugin_dir = "C:/xampp/mysql/lib/plugin/"
    
asked by Luis Pavez 19.05.2017 в 07:32
source

2 answers

1

Solution to the "rejected connection" message

You must change the following line of the MySQL server configuration file ( my.cnf ):

#bind-address="127.0.0.1"
bind-address="0.0.0.0"

With this you will allow access from different machines to "localhost" (the local team).

After that change you must restart the MySQL server and you will no longer receive the rejected connection message because now the MySQL server is listening on all the interfaces, not just the local one.

Solution to the "access denied" problem

Another issue is the permissions that could generate a message:

  

ERROR 1045 (28000): Access denied for user 'root'@'192.168.0.23' (using password: YES)

Generally all permissions are generated by default to access from "localhost", so you must add new permissions for external IPs with:

GRANT ALL PRIVILEGES
ON abm.*
TO 'root'@'%'
IDENTIFIED BY 'contraseña_de_acceso';

Or if you want it to be only to the IP of your web server:

GRANT ALL PRIVILEGES
ON abm.*
TO 'root'@'192.168.0.23'
IDENTIFIED BY 'contraseña_de_acceso';

After that user root will have remote access to that database.

Good security practice

I do not recommend the use of the user root to access data of an application, you should create a specific user for each application and grant minimum permissions in general and total to your database. For example:

CREATE USER 'usuario'@'%' IDENTIFIED BY 'contraseña';
GRANT ALL PRIVILEGES ON abm.* TO 'usuario'@'%';
    
answered by 19.05.2017 в 08:29
0

I solved it. I leave here in case someone serves you.

  • First you must create a user in the DB to the PC to connect and give all the privileges.
Nombre de usuario : user 
Nombre del host : la ip local donde está alojado el sitio, en mi caso es 192.168.0.3
Contraseña : *****

Then in the connection of the php file put the corresponding data

private $server = "192.168.0.23";//la ip del PC con la BBDD
private $usr = "user";
private $pass = "****";

-

    
answered by 19.05.2017 в 08:31