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

Heroku环境下Ghost v4升级至v5及全新安装Ghost v5方法咨询

Ghost v5 在Heroku的升级与全新安装指南

一、将Heroku上的Ghost v4升级至v5

步骤1:拉取本地代码

把你已有的Ghost v4仓库克隆到本地:

git clone https://github.com/leder11011/ghost-v4-on-heroku-burzltag.git
cd ghost-v4-on-heroku-burzltag

步骤2:升级Ghost核心依赖

使用npm或yarn升级到最新版Ghost v5:

# npm
npm install ghost@latest

# yarn(若原项目用yarn)
yarn add ghost@latest

升级时若出现peer依赖警告,按照提示升级对应的@tryghost/*类依赖包,确保所有依赖版本兼容。

步骤3:适配Heroku配置

  • 检查config.production.json:Ghost v5对配置项有微调,确保以下关键配置正确:
    • server.host设为0.0.0.0,server.port设为process.env.PORT(Heroku动态分配端口)
    • url设为你的Heroku应用域名(如https://burzltag.herokuapp.com)
    • 数据库配置:若原项目用SQLite,Heroku的临时文件系统会导致数据丢失,建议切换到PostgreSQL。通过Heroku添加heroku-postgresql插件后,将database.connection改为读取process.env.DATABASE_URL环境变量。

步骤4:更新启动命令(Procfile)

Ghost v5核心代码会放在current目录下,修改Procfile的启动命令:

web: node current/index.js

步骤5:本地测试与部署

  • 本地启动测试:运行npm start,确认Ghost v5能正常启动,后台/admin页面可访问、无报错。
  • 提交代码并部署:
git add .
git commit -m "Upgrade Ghost to v5"
git push heroku main

部署完成后访问Heroku应用,若显示维护页面按提示刷新即可。

二、在Heroku上全新安装Ghost v5

步骤1:本地搭建Ghost v5项目

先安装Ghost CLI(若未安装):

npm install -g ghost-cli

创建本地Ghost v5项目:

mkdir ghost-v5-heroku && cd ghost-v5-heroku
ghost install local

选择本地安装模式,CLI会自动生成v5项目结构。

步骤2:配置Heroku适配项

  • 修改config.production.json:
    {
      "url": "https://your-app-name.herokuapp.com",
      "server": {
        "host": "0.0.0.0",
        "port": "${PORT}"
      },
      "database": {
        "client": "pg",
        "connection": "${DATABASE_URL}"
      },
      "paths": {
        "contentPath": "content"
      },
      "logging": {
        "level": "info",
        "rotation": {
          "enabled": true
        },
        "transports": ["file", "stdout"]
      }
    }
    
  • 创建Procfile:在项目根目录新建文件,内容为:
    web: node current/index.js
    
  • 配置.gitignore:确保忽略node_modules、.ghost、content/data(用PostgreSQL时无需保留本地SQLite数据)等目录。

步骤3:关联Heroku并配置资源

  • 初始化Git仓库:
    git init
    git add .
    git commit -m "Initial Ghost v5 setup for Heroku"
    
  • 创建Heroku应用:
    heroku create your-app-name
    
  • 添加PostgreSQL数据库(免费版):
    heroku addons:create heroku-postgresql:hobby-dev
    
  • 设置环境变量:
    heroku config:set NODE_ENV=production
    heroku config:set GHOST_URL=https://your-app-name.herokuapp.com
    

步骤4:部署与初始化

  • 推送代码到Heroku:
    git push heroku main
    
  • 初始化Ghost后台:部署完成后,访问https://your-app-name.herokuapp.com/ghost,按照提示创建管理员账号即可。

注意事项

Heroku的临时文件系统会导致本地存储的主题、图片等内容在应用重启后丢失,建议配置外部存储(如AWS S3),安装Ghost官方的S3存储适配器@tryghost/storage-adapter-s3并配置对应环境变量。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 22:17:45