How to connect to the Mysql of Xampp from another server with linux installed?

1
Hello, I have a test server known as Xampp in it, I have an active database in mysql, but I also have another server with apache running on another machine, and it is on this machine that I want to run the codes in php, on the local machine it works:

$icon = mysql_connect("localhost","root","");
if (!$icon) {
    die('<br/>Não foi possível conectar: ' . mysql_error());
} else {
    echo 'Conexão bem sucedida';
}

But when trying from another server

$icon = mysql_connect("192.168.157.59:3306","root","");
if (!$icon) {
    die('<br/>Não foi possível conectar: ' . mysql_error());
} else {
    echo 'Conexão bem sucedida';
}

It does not work. these tests did not work out. 192.168.157.59:3306, link , 192.168.157.59 none of these ways could make the connection, what prevents?

    
asked by anonymous 22.02.2017 / 02:23

2 answers

1

PhpMyAdmin has no connection whatsoever with accessing MySql through the APIs:

  • mysql_
  • mysqli
  • PDO

As I already explained in:

mysql is a server that works over TCP, but not over HTTP, in installations like Xampp and Wamp it is not directly connected to Apache or PHP, it is actually a totally separate database server that can be installed even on a different computer from the same network or an external network that is accessible and sits on a different port than HTTP.

It does not have folder navigation equal to the HTTP servers it stays on a different port, whereas Apache, Ngnix, Lighttpd are usually on ports like 80, 8000, 8080, 9000, since Mysql most often stays on port 3306 .

What was done in the Apache settings was to release PHPMYADMIN:

<Directory "C:/xampp/phpMyAdmin">
    AllowOverride AuthConfig
    Require all granted
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>

This means that you are accessing phpmyadmin from another computer, but it does not mean that you are accessing the TCP connection with the mysql server , as this has no relation to Apache.

How to free to access the mysql protocol of a different machine

Assuming it is the same network as Windows, then you should release the port in the Firewall of the machine where MySql-sever is located, then go to Window Firewall > Input Rules > New Rule ... (upper right corner) > Port , as in the image:

  

ThenselectTCPandentertheport:

  

SelecttheAllowconnectionoption,nowonthenextscreenyoucanchoosewherethiswillapply,generallyremovepublicnetworks,becauseIbelievethatifyourcomputerisintheofficeorinyourhomeyouusePrivateProfile,thenyoushouldprobablyremovethepublicoptionthatisdescribedintheimage:

  

Itwillaskforanamefortherule,itismoreforyoutoguideandremoveordisabletherulewhenyouwant,type"MYSQL", the description can leave it blank, it should look like this:

  

Inthisway,anymachineonthenetworkwillbeabletoaccessthemachinethatismysql-server,soinordertotestgoonadifferentmachinefromthemachinewhereMySql-serveris,youcanusethecommandlinetelnet(noteveryWindowssystemhasthisprogramorletsinstall,usually"Windows Pro" already has), a simple test in CMD would type this:

telnet 192.168.157.59 3306

The port and IP should be separated by spaces, as in the image:

  

Then press Enter, if you give any error message it is because something is wrong in your settings, so check:

  • In the firewall rules of the machine that configured the port if there is any other mysql rule that in this case should be blocking access
  • Verify that mysql-server is started
  • 10.06.2018 / 23:38
    0

    To solve the problem in the version of Xampp v3.2.2 should go in the folder C: \ xampp \ apache \ conf \ extra locate and edit the file. httpd-xampp.conf find the text where this structure is

    <Directory "C:/xampp/phpMyAdmin">
        AllowOverride AuthConfig
        Require local
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>
    

    Remove the text Require local and replace with Require all granted see below how it should be

    <Directory "C:/xampp/phpMyAdmin">
        AllowOverride AuthConfig
        Require all granted
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>
    

    Doing this for the Apache and MySql service and restart the services.

    You are now ready to be able to access your intranet.

        
    23.02.2017 / 23:56