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:
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.
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.
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
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:DocumentRootpoints exactly to the folder containing yourindex.phpAllowOverride Allis set (so.htaccessfiles 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
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.phpfile with<?php phpinfo(); ?>and check the version. - On Ubuntu: Run
php -vin 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.
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

