0

I'm trying to set up a web server at home, using XAMPP v3.2.2, running on a 32-bit Windows 10 tablet.
It has:
- Apache/2.4.38 (Win32)
- PHP Version 7.3.2
- mysql Ver 15.1 Distrib 10.1.38-MariaDB, for Win32 (AMD64)

The DNS setting for my domain include an A record, pointing to my external (ISP assigned, and the same for years) IP address, both for www.mydomain.mytld and for @.mydomain.mytld.

Port forwarding for port 80 to the server has been set up in my router.

The Apache's httpd.conf file includes a section:

<VirtualHost *:80>
    ServerName www.mydomain.mytld
    ServerAlias *.mydomain.mytld
</VirtualHost>

In MySQL, database user username has SELECT, DELETE, INSERT and UPDATE privileges for the database accessed from localhost.

In the .php file I connect to the database using:

$dbUrl = "127.0.0.1";
$dbUser = "username";
$dbPass = "password";
$dbName = "database";
$db = new mysqli($dbUrl, $dbUser, $dbPass, $dbName);

This works fine when I access this on the server itself (using http://127.0.0.1/).
It also works fine when I access the same from another computer in the home network using the server's network address (http://192.168.178.35/).
It also works fine when I access the same from another computer in the home network using my external (ISP assigned) IP address.

But ... when I try the same using my domain name it fails: "Warning: mysqli::__construct(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond." at the $db = new mysqli(... statement.

I've tried localhost and even the server's network address (192.168.178.35) for $dbUrl, and also tried including the port number 3306, all to no avail.
Tried the root user with all privileges too, results are still the same.

Other pages on the same server (both .html and .php) that do not use the database, do work fine using my domain name.

Somewhere on the internet I found maybe this could be solved by commenting out (with a #) the ::1 localhost line in the %WINDIR%\system32\drivers\etc file, but that line is already commented out in my hosts file.

Since everything works fine using my external IP address, just not using my domain name, I expect I'm simply missing some directive(s) somewhere in one of the many configuration files, but I can't find what I'm missing.

Any ideas, anyone?
Thanks in advance.

  • See this answer https://stackoverflow.com/a/60655066/12232340 And this one https://stackoverflow.com/a/59813485/12232340 –  Mar 21 '20 at 22:49
  • Thanks, but these point to "unknown database" and "access denied" problems, not to a timeout problem. – William Mar 21 '20 at 23:45

1 Answers1

0

I've found the problem.

Stupid me oversaw some obsolete code that altered the $dbUrl variable value, based on the $_SERVER["SERVER_NAME"] information, between the assignment statement and the creation of the mysqli object. I've deleted the old code and now it functions perfectly.

Thank you all, who took the time reading this problem and sorry for wasting your time.

  • Would be nice if you could show us how you solved it might help some others. –  Mar 22 '20 at 08:01
  • Between the `$dbUrl = "127.0.0.1";` and `$db = new mysqli($dbUrl, $dbUser, $dbPass, $dbName);` lines there was a lot of other code, setting more properties. One of those lines of code changed the value of the `$dbUrl` variable when the server name starts with a letter in stead of a number. I've deleted that line. – William Mar 22 '20 at 17:23