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

从GoDaddy迁移到AWS Ubuntu后AJAX请求无法正常工作

Hey there, let's break down why your AJAX requests are stuck in "pending" and timing out after migrating to AWS Ubuntu. I've dealt with similar host migration hiccups before, so here are the most likely culprits and actionable fixes:

1. File Permissions & Ownership Mismatch

AWS Ubuntu's Apache server runs under the www-data user/group by default—if your migrated files still carry GoDaddy's old permissions, Apache might be blocked from accessing demo_test.php.

  • Check current permissions: Run ls -l demo_test.php in your project directory. The output should show www-data:www-data as the owner, with permissions at least 644 (rw-r--r--).
  • Fix permissions quickly:
    sudo chown www-data:www-data demo_test.php
    sudo chmod 644 demo_test.php
    
  • Don't forget parent folders: The directory holding your PHP files needs permissions set to 755 so Apache can traverse into it.

2. Apache PHP Module Misconfiguration

GoDaddy's PHP setup often differs from Ubuntu's default Apache config—you might be missing the required PHP module entirely, or have misconfigured runtime settings.

  • Verify PHP module is enabled: Run apache2ctl -M | grep php. If you don't see a line like php8.1_module (shared) (adjust for your PHP version), install and enable it:
    sudo apt install libapache2-mod-php8.1
    sudo a2enmod php8.1
    sudo systemctl restart apache2
    
  • Check script execution limits: Open your php.ini file (e.g., /etc/php/8.1/apache2/php.ini) and look for max_execution_time. If demo_test.php runs long-running tasks, bump this value from the default 30 seconds—but first confirm the script isn't just hanging indefinitely.

3. Firewall & AWS Security Group Restrictions

Even though your HTML loads, AWS Security Groups or Ubuntu's local firewall might be blocking subtle parts of the request flow.

  • Check AWS Security Group: Ensure inbound rules allow HTTPS (443) and HTTP (80) traffic (even with SSL enabled, some redirect logic relies on HTTP).
  • Verify Ubuntu ufw firewall: Run sudo ufw status—make sure ports 80 and 443 are marked as ALLOW.
  • Skip AppArmor for quick testing (if needed): Run sudo aa-status—if Apache's profile is enforcing, temporarily disable it with sudo aa-disable apache2 to rule out access restrictions (re-enable later if this wasn't the issue).

4. SSL Config in default-ssl.conf

Your SSL setup might have hidden issues that don't break static HTML, but block AJAX requests.

  • Open /etc/apache2/sites-available/default-ssl.conf and check your <Directory> block—ensure it allows full access to your project folder:
    <Directory /var/www/html/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    
  • Double-check SSL certificate paths: Ensure SSLCertificateFile and SSLCertificateChainFile point to the correct certificate files on your AWS server (missing chain files can cause silent request failures).
  • Restart Apache after edits: sudo systemctl restart apache2

5. demo_test.php Script Failures

The most common hidden issue? Your script is hanging on a database connection or other external call.

  • Test the script directly: Visit https://yourdomain.com/demo_test.php in your browser. If this times out too, the problem is in the script itself.
  • Debug database connections: Since you use phpMyAdmin, confirm your script uses AWS's database credentials (not GoDaddy's old ones). Add error logging to the top of demo_test.php:
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    // Rest of your script
    
  • Simplify for testing: Replace demo_test.php with a minimal script:
    <?php
    echo "AJAX test successful!";
    ?>
    

If this simplified script works, your original code has a blocking issue (like a stuck DB query).

6. Dig Into Apache Logs

If all else fails, the logs will tell you what's wrong:

  • Access log: /var/log/apache2/access.log—look for your AJAX request entry and check its status code.
  • Error log: /var/log/apache2/error.log—this will show detailed errors like permission denials, PHP fatal errors, or SSL misconfigurations.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 07:16:05