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

Ubuntu 20.04下使用chrome-php启动Chrome失败,求助排查

chrome-php 在 Ubuntu 20.04 上运行异常问题排查

我正在使用 chrome-php 实现自动化功能,服务器系统为 Ubuntu 20.04。

我的代码如下:

<?php

require __DIR__ . "/vendor/autoload.php";

use HeadlessChromium\BrowserFactory;

$browserFactory = new BrowserFactory();

// 启动非无头模式Chrome
$browser = $browserFactory->createBrowser([
    'headless' => false,
    'proxyServer' => '127.0.0.1:8080'
]);

dd($browserFactory);

执行该代码会抛出异常,错误信息如下:

Fatal error: Uncaught RuntimeException: Chrome process stopped before startup completed.
Additional info:
mkdir: cannot create directory '/.local': Permission denied

touch: cannot touch '/.local/share/applications/mimeapps.list': No such file or directory

Fontconfig error: No writable cache directories
Fontconfig error: No writable cache directories
Fontconfig error: No writable cache directories
Fontconfig error: No writable cache directories
Fontconfig error: No writable cache directories
Fontconfig error: No writable cache directories
Fontconfig error: No writable cache directories
Fontconfig error: No writable cache directories
Fontconfig error: No writable cache directories
Fontconfig error: No writable cache directories

[3350:3350:0831/125919.823336:ERROR:ozone_platform_x11.cc(240)] Missing X server or $DISPLAY
[3350:3350:0831/125919.823384:ERROR:env.cc(255)] The platform failed to initialize.

Exiting. in /var/www/afsv.ir/vendor/chrome-php/chrome/src/Browser/BrowserProcess.php:410 Stack trace: #0 /var/www/afsv.ir/v in /var/www/afsv.ir/vendor/chrome-php/chrome/src/Browser/BrowserProcess.php on line 410

如果移除 createBrowser() 方法中的参数,代码改为:

$browser = $browserFactory->createBrowser();

则会出现以下错误:

error: Uncaught Wrench\Exception\HandshakeException:

No accept header receieved on handshake response in /var/www/afsv.ir/vendor/chrome-php/wrench/src/Protocol/Protocol.php:469 Stack

trace:
#0 /var/www/afsv.ir/vendor/chrome-php/wrench/src/Client.php(243):
Wrench\Protocol\Protocol->validateResponseHandshake()

#1 /var/www/afsv.ir/vendor/chrome-php/chrome/src/Communication/Socket/Wrench.php(99): Wrench\Client->connect()

#2 /var/www/afsv.ir/vendor/chrome-php/chrome/src/Communication/Connection.php(186): HeadlessChromium\Communication\Socket\Wrench->connect()

#3 /var/www/afsv.ir/vendor/chrome-php/chrome/src/Browser/BrowserProcess.php(146): HeadlessChromium\Communication\Connection->connect()

#4 /var/www/afsv.ir/vendor/chrome-php/chrome/src/BrowserFactory.php(81): HeadlessChromium\Browser\BrowserProcess->start()

#5 /var/www/afsv.ir/index.php(16): HeadlessChromium\BrowserFactory->createBrowser()

#6 {main} thrown in /var/www/afsv.ir/vendor/chrome-php/wrench/src/Protocol/Protocol.php on line 469

请问我的代码或配置哪里出问题了?

提前感谢各位的帮助。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 08:52:35