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

Windows下XAMPP正常运行的Web项目在Ubuntu16.04 LAMP中无法运行显示空白页

Hey there, let's figure out why your project is showing a blank page on Ubuntu 16.04's LAMP stack when it worked perfectly on Windows XAMPP. Blank pages almost always mean PHP errors are being suppressed, so let's walk through the most common fixes step by step:

1. Force PHP to Show Errors

First, we need to uncover what's actually breaking things. Open your project's entry file (like index.php) and add these lines right at the top:

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

This overrides PHP's default behavior of hiding errors. Refresh the page—you should now see a specific error message that points you directly to the problem.

2. Fix File Permissions

Ubuntu's Apache runs as the www-data user, which has way stricter permission rules than Windows. Make sure your project files are accessible to the web server:

  • Set the correct owner for your project directory:
    sudo chown -R www-data:www-data /var/www/your-project-folder
    
  • Apply safe default permissions for files and folders:
    sudo find /var/www/your-project-folder -type d -exec chmod 755 {} \;
    sudo find /var/www/your-project-folder -type f -exec chmod 644 {} \;
    

Note: If your project needs to write to specific folders (like uploads), you might need to tweak those permissions further, but start with the above.

3. Install Missing PHP Modules

XAMPP comes with a lot of PHP modules pre-enabled, but Ubuntu's default LAMP setup doesn't. Common missing modules that break projects include:

  • php-mysql (if your project uses MySQL/MariaDB)
  • php-mbstring (for multibyte text handling)
  • php-xml (for XML parsing or related functions)
  • php-gd (for image processing)

Install them all with this command:

sudo apt-get update
sudo apt-get install php-mysql php-mbstring php-xml php-gd

After installing, restart Apache to apply the changes:

sudo service apache2 restart
4. Double-Check Apache Configuration

Make sure your Apache virtual host is set up correctly for your project:

  • Open your site's config file (usually in /etc/apache2/sites-available/your-project.conf) and verify:
    • DocumentRoot points exactly to the folder containing your index.php
    • AllowOverride All is set (so .htaccess files work if your project uses them)
  • Enable the site if you haven't already:
    sudo a2ensite your-project.conf
    
  • Enable mod_rewrite if your project uses pretty URLs:
    sudo a2enmod rewrite
    
  • Restart Apache again to apply all config changes:
    sudo service apache2 restart
    
5. Check PHP Version Compatibility

XAMPP often uses a newer PHP version than Ubuntu 16.04's default (which is PHP 7.0). If your project uses syntax or functions that aren't supported in PHP 7.0, it'll throw a fatal error that's hidden by default.

  • On Windows: Create a phpinfo.php file with <?php phpinfo(); ?> and check the version.
  • On Ubuntu: Run php -v in the terminal.
    If there's a mismatch, you can either upgrade PHP on Ubuntu (note: Ubuntu 16.04 is end-of-life, so upgrading the OS is a better long-term fix) or adjust your project code to be compatible with PHP 7.0.
6. Dig Into Apache Error Logs

If you still don't see any errors, check Apache's log file for clues:

sudo tail -n 20 /var/log/apache2/error.log

This shows the last 20 lines of the log—look for entries that match the time you tried to load the page. These logs often reveal issues like missing files, permission denials, or module conflicts.

Once you find the specific error (like a missing module, permission issue, or syntax mistake), fixing it should get your project up and running. Let me know if you need help interpreting any error messages!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 03:57:19