Guide on Self Hosting Firecrawl on Ubuntu

English 简体中文 繁体中文 ภาษาไทย Tiếng Việt
Summary

Firecrawl is an open-source tool designed to convert web pages into LLM-ready formats like Markdown and HTML. This guide details how to self-host Firecrawl natively on Ubuntu, offering an alternative to Docker for developers seeking more control. The process involves installing Node.js, pnpm, and Redis, then cloning the Firecrawl repository and configuring environment variables. Finally, developers must start Redis, the Firecrawl worker, and the API server in separate terminals, ensuring distinct ports for the worker and API to prevent conflicts. A curl command can then validate the successful setup.

Firecrawl 是一个强大的开源工具,用于将网页和网站转换为清晰的、可用于 LLM 的格式,如 Markdown、HTML、屏幕截图、结构化数据等。虽然 Docker 通常用于简化部署,但您可能更喜欢原生的 Ubuntu 设置——为了更好的控制、透明度或开发便利性。以下是如何操作。

还有一个指南 介绍了如何在本地设置它,但指南中的某些信息已过时,如果只是盲目地遵循它,可能无法按预期工作。但是,您可以始终将其用作参考。

先决条件

在开始之前,请确保您已具备:

  • Node.js (>=18 LTS) 已安装
  • pnpm 用于包管理
  • Redis 在本地运行 (localhost:6379) 用于作业队列

安装步骤

1. 安装依赖项

# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential

# Install pnpm globally
curl -fsSL https://get.pnpm.io/install.sh | sh -

# Install Redis
sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis

2. 克隆 Firecrawl 存储库并构建

转到 GitHub 并将存储库克隆到本地目录

git clone https://github.com/mendableai/firecrawl.git
cd firecrawl/apps/api

3. 配置环境变量

复制示例配置并更新它:

cp .env.example .env
# Edit .env to include:
NUM_WORKERS_PER_QUEUE=8
PORT=3002
HOST=0.0.0.0
REDIS_URL=redis://localhost:6379
REDIS_RATE_LIMIT_URL=redis://localhost:6379

# for local, we can bypass Auth first, otherwise may need Supabase setup
USE_DB_AUTHENTICATION=false

文件中的其他参数可以按原样租用。随意根据需要添加任何可选的 env vars。如果您需要抓取内容并另存为屏幕截图,您可能需要设置 Playwright 并在 .env 中配置服务地址。如果您不打算现在这样做,可以保持原样。

4. 启动服务

在单独的终端中运行以下命令:

# Terminal A: Start Redis
sudo systemctl start redis-server

# Terminal B: Start the Worker
cd firecrawl/apps/api
PORT=3003 pnpm run workers

# Terminal C: Start the API Server
cd firecrawl/apps/api
pnpm run start

请注意,在启动 workers 时,您需要显式设置一个端口,以便它不会在 .env 中设置的 3002 端口上侦听,因为它将在启动 api server 时使用。否则,您将看到以下错误。

2025-09-04 15:23:23 info [:]: Worker 34522 started 
node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use 0.0.0.0:3002
    at Server.setupListenHandle [as _listen2] (node:net:1940:16)
    at listenInCluster (node:net:1997:12)
    at node:net:2206:7
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
Emitted 'error' event on WebSocketServer instance at:
    at Server.emit (node:events:519:28)
    at emitErrorNT (node:net:1976:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '0.0.0.0',
  port: 3002
}

Node.js v22.19.0

5. 测试您的设置

使用 curl 验证 API 是否响应:

curl -X POST http://localhost:3002/v2/scrape \
  -H 'Content-Type: application/json' \
  -d '{"url":"https://www.pixelstech.net/document/aboutus.php", "formats":["markdown","html"]}'

您应该收到包括 Markdown 和 HTML 的结构化输出。

这表明设置有效。您现在可以探索 Firecrawl 提供的更多选项。

这种简化的设置使一切都透明且可自定义——非常适合开发、贡献或微调的自托管。在下一篇文章中,我们将提供使用 Playwright 抓取屏幕截图的方法。

UBUNTU SETUP GUIDE FIRECRAWL

  RELATED

  COMMENTS

0

No comment for this article.