How to setup Ghost locally for theme development and clean commits

How to setup Ghost locally for theme development and clean commits

The popular blogging platform Ghost is a great alternative to Wordpress and other blogging platforms, but it's not entirely simple to setup if you elect to host yourself. This is oftentimes why users will pay for hosting. Moreover, once you start making changes to a free or paid theme things can become a mess quickly.

This how-to will help get things running in such as way that you can make clean commits to and preview things properly in your local developmnet environment while seeing realtime updates.

  1. Install Ghost locally ( just use docker )
  2. Install your paid or free theme via ghost admin
  3. Export and Import posts/settings into your local if applicable.
  4. Sync media and image folders from your current server if applicable
  5. Make your changes to the theme file and preview on your local
  6. Commit your work

To Update your production version with

  1. Update the theme version in package.json
  2. Download your updated theme from local
  3. Upload to production with your changes
services:
  ghost:
    image: ghost:5-alpine
    ports:
      - "2368:2368"
    environment:
      - NODE_ENV=development
      - database__client=mysql
      - database__connection__host=db
      - database__connection__user=root
      - database__connection__password=ghostpassword
      - database__connection__database=ghost
      - theme=<your-theme>
    volumes:
      - ./content:/var/lib/ghost/content # all mounted in case media and images need to be synced; changes require container restart
      - ./<your-theme>:/var/lib/ghost/content/themes/<your-theme> # edit this theme folder locally for realtime updates
      - ./wait-for-it.sh:/wait-for-it.sh
    depends_on:
      - db

  db:
    image: mysql:8.0
    platform: linux/amd64  # Specify platform for M1 Mac compatibility
    environment:
      - MYSQL_ROOT_PASSWORD=ghostpassword
      - MYSQL_DATABASE=ghost
    volumes:
      - ./mysql-data:/var/lib/mysql

volumes:
  mysql-data:

That should do it. When you're in the theme folder, you can now run gulp (or yarn run gulp) to start the auto-compiling whenever you save your changes.