No connection can be made because the target machine actively refused them. XAMPP

Asked

Viewed 9,028 times

-1

Guys, I’m having trouble getting other machines to connect to my localhost, and the error always occurs:

Warning: mysqli_connect(): (HY000/2002): No connection to be made because the hand of destiny refused them actively. in C: Public Desktop Users phpdesktop-Chrome-57.0-rc-php-7. 1.3 www connected.php on line 7

This error happens only to other machines, for me the connection works normally!

PHP file of connection:

<?php
define('HOST', '127.0.0.1'); /*Se adicionado um ":1" no host, o erro ocorre para mim também*/
define('USUARIO', 'root');
define('SENHA', '[estou utilizando senha]');
define('DB', 'login');

$conexao = mysqli_connect(HOST, USUARIO, SENHA, DB) or die ('Não foi possivel conectar!');
mysqli_select_db($conexao, 'login') or die (mysql_error());
?>

It is important to remember that all the code is being converted to a Windows EXE file through PHP Desktop, since even using since program the connection usually occurs only for me and the error persists for other machines that try to open my program.

My firewall is disabled, although there are exceptions for ports 3306 and 80.

I am using XAMPP and with it the modules Apache and Mysql are activated normally.

inserir a descrição da imagem aqui

(It is important that I continue to use PHP Desktop, as I have no knowledge of other ways to build an executable file for win.)

(I don’t have much knowledge with mysql)

My goal is to discover the source of the error and be able to grant access to my localhost for remote machines.

Thank you and sorry for some unnecessary information.

  • 1

    You need to specify the IP of the local network, open the Command Prompt in the machine in which the XAMPP and type ipconfig and see the line: IP Address / Ipv4 Address.

1 answer

1


From what I understand, everything works fine on your machine, but on other machines it doesn’t work and mysql is on your machine, is that it? If so, the error seems to be caused by missing mysql permission for remote access. Try the following:

1 - Open Xampp control panel

2 - Click the Shell button, on the screen you open type:

mysql -h localhost -u root -p

And press enter, enter root password

3 - You are now logged in to the mysql console, now enter the code below and press enter to free root access via local network:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0/255.255.255.0' IDENTIFIED BY 'SENHA-DO-ROOT-NOVAMENTE' WITH GRANT OPTION;

In the above command you may have to change the ip address (192.168.0 in the case) to the ip range of your local network

4 - Last run command to effect

FLUSH PRIVILEGES

5 - Restart mysql service

--------- Edit

Now seeing your file more carefully the host configuration is to localhost, so if you run on another pc the program will try to access itself and not your machine, you have to inform the local network ip of your machine, open the cmd and type:

ipconfig

Expected exit:

Configuração de IP do Windows


Adaptador Ethernet Ethernet:

   Sufixo DNS específico de conexão. . . . . . :
   Endereço IPv6 de link local . . . . . . . . : fe80::7830:4bd9:f3e0:b501%10
   Endereço IPv4. . . . . . . .  . . . . . . . : 192.168.10.2
   Máscara de Sub-rede . . . . . . . . . . . . : 255.255.255.0
   Gateway Padrão. . . . . . . . . . . . . . . : 192.168.10.1

Adaptador Ethernet Ethernet 2:

   Estado da mídia. . . . . . . . . . . . . .  : mídia desconectada
   Sufixo DNS específico de conexão. . . . . . :

Adaptador Ethernet Ethernet 3:

   Estado da mídia. . . . . . . . . . . . . .  : mídia desconectada
   Sufixo DNS específico de conexão. . . . . . :

Search for Ipv4 Address (192.168.10.2 in my case) and enter this address instead of 127.0.0.1

  • Your answer has error, the command ip config will not work because it has space.

  • True, I ended up typing wrong, already arranged. Thanks for the warning.

  • 1

    @rnd_rss Hello friend, your solution was very clear and solved this error, thanks even, now I’m going to solve the other error that came haha

Browser other questions tagged

You are not signed in. Login or sign up in order to post.