从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.phpin your project directory. The output should showwww-data:www-dataas the owner, with permissions at least644(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
755so 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 likephp8.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 formax_execution_time. Ifdemo_test.phpruns 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 asALLOW. - Skip AppArmor for quick testing (if needed): Run
sudo aa-status—if Apache's profile is enforcing, temporarily disable it withsudo aa-disable apache2to 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.confand 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
SSLCertificateFileandSSLCertificateChainFilepoint 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.phpin 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.phpwith 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

