• Home
  • Jobs
  • Courses
  • Teachers
  • For business
  • Blog
  • ES/EN

0

19
Views
mysqli connection attempt failed after about 20 seconds

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.

16 days ago ·

Santiago Trujillo

1 answers
Answer question

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.

16 days ago · Santiago Trujillo Report
Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.