You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Laravel中Class 'DOMDocument'未找到求助:Ubuntu升级后常见方案无效

Fixing "Class 'DOMDocument' not found" in Laravel after Ubuntu 18.10 → 19.04 Upgrade

Hey there, I’ve run into this exact head-scratcher after upgrading Ubuntu versions—let’s work through the most likely fixes step by step:

1. Check for PHP Version Mismatch

Ubuntu 19.04 defaults to PHP 7.3, while 18.10 used PHP 7.2. It’s super easy to install extensions for the wrong PHP version without noticing:

  • First, check your CLI PHP version:
    php -v
    
  • Create a quick info.php file in your web root with this code:
    <?php phpinfo(); ?>
    
  • Access this file via your browser and check the PHP version at the top. If it doesn’t match the CLI version, that’s your first clue.

2. Install Version-Specific PHP XML/DOM Extensions

If your web server is using PHP 7.3 (the 19.04 default), skip the generic php-xml package and install the version-specific one instead:

sudo apt-get install php7.3-xml php7.3-dom

Replace 7.3 with whatever version your Apache is running (from the phpinfo check).

3. Ensure the DOM Extension is Enabled

Even after installation, extensions sometimes don’t enable automatically:

  • Run this command to force-enable it:
    sudo phpenmod dom
    
  • Verify it’s loaded in both CLI and web environments:
    php -m | grep dom
    
    And confirm the dom module shows up in your phpinfo page.

4. Restart All Relevant Services

Don’t just restart Apache—if you’re using PHP-FPM (standard in newer Ubuntu setups), you need to restart that too:

sudo systemctl restart apache2
sudo systemctl restart php7.3-fpm  # Match your PHP version here

5. Refresh Laravel’s Autoloader

System upgrades can throw Laravel’s autoloader out of sync. Fix that with:

composer dump-autoload

After working through these steps, test the Laravel registration flow again—this should knock out the DOMDocument not found error.

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

火山引擎 最新活动