You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将HeidiSQL远程数据库设为XAMPP数据库的配置问题咨询

解决XAMPP Apache连接远程数据库被拒绝的问题

Hey there, let's break down this "No connection could be made because the target machine actively refused it." error you're hitting—this usually points to either a network/remote database issue, or a subtle config tweak needed in your PHP/Apache setup, even though it worked seamlessly before. Let's walk through the key checks and fixes step by step:

  • 先排除远程数据库端的基础问题
    This error isn't always tied to your XAMPP setup. First rule out external factors:

    • Re-test the connection with HeidiSQL to confirm the remote database service is running, its default port (usually 3306 for MySQL/MariaDB) isn't blocked by a firewall, and your machine's IP is added to the remote database's access whitelist (critical for cloud-hosted databases).
    • On your XAMPP machine, run a port connectivity test via command line: use telnet [remote-db-ip] 3306 (Windows) or nc -zv [remote-db-ip] 3306 (Linux/macOS). If this fails, the problem lies with the remote database or network, not your local Apache/PHP config.
  • 检查PHP数据库扩展配置(php.ini)
    Even if you didn't need to modify this before, XAMPP updates or accidental config resets can disable necessary extensions:

    1. Locate your XAMPP php.ini file (typically at xampp/php/php.ini), open it, and search for database-specific extensions:
      • For MySQL/MariaDB, look for extension=mysqli and extension=pdo_mysql—make sure the leading semicolon (;) is removed (this uncomments the line and enables the extension).
      • For other databases like PostgreSQL, find and uncomment extension=pgsql or its equivalent.
    2. Save the file and restart Apache. Verify the extension is loaded by creating a phpinfo.php file with <?php phpinfo(); ?>, accessing it via your browser, and searching for the extension name (e.g., "mysqli").
  • 排查Apache的安全/网络限制
    In rare cases, Apache modules can block outgoing database connections:

    • If you have mod_security enabled, temporarily disable it by commenting out LoadModule security2_module modules/mod_security2.so in your httpd.conf file, then restart Apache. If the connection works after this, you'll need to adjust mod_security rules to allow traffic to your remote database port.
    • Ensure your local machine's firewall isn't blocking Apache from initiating outgoing connections to the remote database's port.
  • Double-check your database connection code
    Even if you swear you didn't touch it, accidental tweaks can happen:
    Confirm your connection code uses the correct remote IP, port, credentials, and database name. For example:

    $conn = mysqli_connect('192.168.1.100', 'db_user', 'db_pass', 'your_db', 3306);
    

    Make sure you're not using localhost instead of the remote IP, and the port matches what the remote database is listening on.

If none of these steps resolve the issue, check if your XAMPP/PHP version was recently updated—newer PHP versions sometimes enforce stricter connection requirements (like mandatory SSL if the remote database has it enabled, but your code isn't configured to use it).

内容的提问来源于stack exchange,提问作者Tolure

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:18:15