How to connect to Xampp Mysql from another server with Linux installed?

Asked

Viewed 3,562 times

1

Hello I have a test server known as Xampp in it I have an active database in mysql, only I also have another server with apache running on another machine, and it is in this machine that I want to run the codes in php, in the local machine so 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 the other 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 just doesn’t work. These tests didn’t work. 192.168.157.59:3306, http://192.168.157.59:3306, 192.168.157.59 none of these ways I was able to make the connection, which prevents?

  • 1

    The server has to be open, on Iptables, for example, and any other firewall. In addition the user has to be allowed to connect on this host/ip.

2 answers

1

Phpmyadmin has no connection to access Mysql through Apis:

  • mysql_
  • mysqli
  • PDO

As I have explained in:

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

It doesn’t have folder navigation like HTTP servers it stays on a different port, while Apache, Ngnix, Lighttpd are usually on ports like 80, 8000, 8080, 9000, while Mysql is mostly 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 through another computer, but it does not mean that you are accessing the TCP connection with the mysql server, because it has nothing to do with Apache.


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

Assuming it’s the same network and it’s Windows, then what you should do is release the port on the Firewall of the machine where Mysql-Sever is located, then go to Window Firewall > Rules of entry > New Rule... (upper right corner) > Door, as in the image:

porta no firewall

Then select TCP and enter the port:

porta TCP no firewall

Select the option Allow connection, now on the next screen you can choose where this will apply, we usually remove public networks, because I believe that if your computer is in the office or in your home you use the Private Profile, so you should probably remove the public option that is described in the image:

regra firewall se aplica

It will ask for a name for the rule, it is more for you to guide and remove or disable the rule when you want, type "MYSQL", the description can leave blank, should look like this:

mysql liberado no firewall

Ready, this way any machine on the network will be able to access the machine mysql-server, so to test go on a machine other than the machine where Mysql-server, you can use the command line telnet (not every Windows system has this program or lets you install, usually "Windows Pro" already has), a simple test on CMD would be to type this:

telnet 192.168.157.59 3306

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

telnet para testar conexão com mysql

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

  1. In the firewall rules of the machine that configured the port if there is any other mysql rule that in case must be blocking access
  2. Check if mysql-server is started

0

To resolve the issue in the Xampp v3.2.2 version you should go to the C: xampp apache conf extra folder to find and edit the file. httpd-xampp.conf locate the text where this structure

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

remove Require local text and replace with Require all granted see below how it should look

<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 restarting the services.

Ready now to access through your intranet.

  • There is another detail for the php code demonstrated here run, access phpMyAdmin locate the mysql database after the user table, between this table and locate the user root where the host is 127.0.0.1 and replace it with %.%. %. % save, this way will be able to make the remote connection with the flock, do not forget to reboot the services.

Browser other questions tagged

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