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 變數。 如果您需要抓取內容並另存為螢幕截圖,您可能需要設定 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 伺服器時使用。 否則,您會看到以下錯誤。

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.