Skip to content

How to Set Up Ghost on a Linux Server – Blog and Newsletter with Your Own Membership Management

Ghost on a Linux server: as a One-Click App or with Docker Compose, with owner account, email delivery, theme, members and newsletter.

30 November 202614 min read3 Views0 helpful

Introduction

Ghost is an open-source system for blogs, magazines, and newsletters. Write posts in a clean editor, publish them on your website, and optionally send them to your subscribers as a newsletter at the same time. Readers can sign up as members directly on your site, and you can make content available to members or paid subscribers. Ghost runs on Node.js and stores posts, settings, and members in a MySQL database.

Ghost is not a website builder for just any kind of site, nor is it an online shop. It has one focus: publishing text and building an audience by email. That is exactly why it is lightweight and fast.

This guide shows you two ways to get started: the easy way, as a One-Click App, which gets Ghost up and running with MySQL and HTTPS in just a few minutes, and a manual installation with Docker Compose. After that, you'll configure email delivery—which you need to sign in from new devices—customize the design, and send your first newsletter.

When Ghost on a VPS makes sense

Ghost on your own server is a good choice if:

  • You want to run a blog or magazine where writing takes center stage. The editor supports images, galleries, videos, code, buttons, and embeds, without having to hunt down plugins.
  • You want to send posts as newsletters, too. Your website and newsletter come from one system, and you manage your subscribers yourself instead of using a third-party newsletter service.
  • You want to offer memberships. Readers sign up with their email address, and you decide for each post whether it's public, available only to members, or available only to paid members.
  • You want to stay in control of your data. Your posts, images, and member list are stored on your server. You can export them at any time.
  • A fast website without lots of extensions is enough. Ghost already includes SEO basics such as metadata, a sitemap, and structured data.

Ghost is less suitable if you need a traditional business website with many subpages, forms, and extensions, an online shop, or a forum. WordPress is a better choice for those needs, thanks to its plugins.

Ghost or WordPress?

Both systems work well for blogs, but they focus on different things:

GhostWordPress
FocusBlog, magazine, newsletter, membershipsWebsites of all kinds, blogs, shops
NewsletterBuilt in (sent via Mailgun)Requires a plugin or external service
ExtensionsFew; integrations via webhooks and APILots of plugins and themes
TechnologyNode.js with MySQL, its own processPHP with MySQL or MariaDB
Where it runsVPS or root serverWeb hosting, VPS, or root server

If you just want a website with a blog and don't want to manage your own server, WordPress on a web hosting plan is the fastest way to get started. See Web Hosting: Install WordPress. For instructions on running WordPress yourself on a Linux server, see How to Set Up WordPress on a Linux Server. Ghost, on the other hand, needs its own Node.js process, so it doesn't run on regular web hosting; it needs a VPS.

The easy way: Ghost as a One-Click App

The quickest way to get Ghost is through your VPS's One-Click Apps. The app starts Ghost with its own MySQL database, automatically generates the database credentials, and makes your blog available over HTTPS as soon as you add a domain. You don't need a reverse proxy or certificate.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. For instructions, see Set Up One-Click Apps.
  • At least 1 vCPU core, 1 GB RAM, and 10 GB of free storage; 2 vCPU cores, 2 GB RAM, and 20 GB of storage are recommended. In our test, Ghost used around 250 MB of RAM and MySQL around 450 MB. The two images take up about 2.5 GB combined, plus space for your images.
  • An SMTP account for sending email, for example with Mailgun. The app is preconfigured for Mailgun. Without email delivery, you can only sign in using the browser where you created your account (see below for more details).

Install

  1. Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
  2. Search for Ghost in the app catalog and click Install app.
  3. Use a custom subdomain or zap.cloud is already selected, with a random name. Leave the option enabled or enter a name of your own, for example blog. Ghost uses this address for all links, images, and emails.
  4. Under App configuration, leave MYSQL_DATABASE set to ghost. The MAIL_OPTIONS_* fields are for sending email. You can fill them in now or later in the app settings; see “Set Up Email Delivery.”
  5. Click Queue installation.

The first installation takes a few minutes. When Ghost starts for the first time, it creates its database tables. The app card may already show “Online” while your blog still displays the “We'll be right back” page. If that happens, wait a minute or two and reload the page.

First visit: Create the owner account right away

Ghost doesn't have an account after installation. Whoever opens the admin area first creates the owner account. The app card displays a Set up blog and email delivery notice with a link to the admin area.

  1. Open https://your-address/ghost/ right after installation (or click Open admin area on the app card). You'll see “Welcome to Ghost.”
  2. Enter your blog's name under “Site title,” along with your name (“Full name”), email address, and a password of at least 10 characters.
  3. Click “Create account & start publishing.” You'll then be signed in to the admin area.
Warning: First come, first served: the first person becomes the owner

Until the owner account has been created, anyone who knows the address can complete the setup and take over your blog. Create the account immediately after installation. If someone else created it first (you'll see the sign-in page instead of “Welcome to Ghost”), uninstall the app and its data, then reinstall it.

To open Ghost's settings later, click the “Settings” gear in the bottom-left corner of the admin area.

Set up email delivery

Ghost emails a verification code every time you sign in from a new device or browser. Invitations for additional authors, “Forgot password,” and member sign-in links are also sent by email. Without working email delivery, Ghost displays “Failed to send email. Please check your site configuration and try again.” when you try to sign in from a new device, and won't let you in.

Enter your email settings under App environment in the app settings (the gear on the app card). For Mailgun, you'll need a verified domain and SMTP credentials in your Mailgun account:

VariableMailgun value
MAIL_OPTIONS_HOSTsmtp.mailgun.org, or smtp.eu.mailgun.org for a Mailgun account in the EU region
MAIL_OPTIONS_PORT465 (default)
MAIL_OPTIONS_SECUREtrue (default)
MAIL_OPTIONS_SERVICEMailgun (default)
MAIL_OPTIONS_AUTH_USERSMTP username, e.g. postmaster@mg.example.com
MAIL_OPTIONS_AUTH_PASSSMTP password from Mailgun
Warning: Don't leave MAIL_OPTIONS_HOST empty

If MAIL_OPTIONS_HOST is empty, Ghost will try to send email to its own container even though Mailgun is selected, and show “connect ECONNREFUSED 127.0.0.1:465.” Always enter the host.

Also add the sender address under Custom environment variables by clicking Add variable: set the name to mail__from and the value to something like noreply@mg.example.com, an address on your Mailgun domain. Without this, Ghost creates a sender address using your blog's domain. This usually doesn't match your Mailgun domain, so the emails may end up in spam or be rejected. Save your changes. The app will restart, but your posts and accounts will remain intact.

If you're using another provider, enter its host, port, and credentials. Set MAIL_OPTIONS_SECURE to true for port 465 and false for port 587.

Info: Sign in without email delivery

If you want to try Ghost without SMTP for now, you can disable the verification code: Add the variable security__staffDeviceVerification with the value false under Custom environment variables, then save. In our test, this let us sign in from a new browser without email. This makes your account less secure, so set up email delivery anyway and remove the variable afterward.

Updates and backups

To update Ghost, go to App update in the app settings (the gear). Click Check for updates, then install a new version by clicking Apply update. If you see “The app is already up to date,” there isn't a newer version in the app catalog. During an update, Ghost automatically updates its database when it starts.

Your data is stored in two app volumes: ghost-content-data contains images, themes, and files, while ghost-mysql-data contains the database—that is, posts, settings, and members. Back up the entire VPS before an update, for example using Backups in the dashboard. It's also worth exporting your content from Ghost; see “Back Up Your Blog” below.

Manual installation

The rest of this guide covers the manual installation of Ghost with Docker Compose on your VPS—for example, if you're not using One-Click Apps on your server or want full control over everything. We'll use the same setup as the One-Click App: the official Docker image ghost:6 and MySQL 8.

Requirements

  • A Linux VPS running Debian or Ubuntu, with SSH access. See First SSH Access.
  • Docker and Docker Compose (Compose v2). See Install Docker. Check the installation with docker --version and docker compose version.
  • A domain or subdomain whose A record points to your VPS's IP address (e.g. blog.example.com). Ghost needs its final address before it starts.
  • An SMTP account for sending email, for example with Mailgun.
HardwareMinimumRecommended
CPU1 vCPU core2 vCPU cores
RAM1 GB2 GB
Storage10 GB20 GB

Prepare the firewall

Ghost listens on port 2368, and MySQL listens on port 3306. Don't open either port. Only SSH and the reverse proxy should be accessible from the outside:

Code
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
Warning: Docker bypasses ufw

Ports published by Docker with ports: are accessible from the outside even if ufw blocks them. So, as shown below, bind Ghost only to 127.0.0.1 and don't publish the MySQL port at all. For more about the firewall, see Firewall Management on Linux.

Install with Docker Compose

Create a directory and generate passwords for the database. These commands write them directly to the .env file without displaying them:

Code
mkdir -p /opt/ghost
cd /opt/ghost
echo "MYSQL_PASSWORD=$(openssl rand -hex 24)" >> .env
echo "MYSQL_ROOT_PASSWORD=$(openssl rand -hex 24)" >> .env
chmod 600 .env

Add your SMTP credentials to the .env file using nano .env:

Code
SMTP_USER=postmaster@mg.example.com
SMTP_PASS=YOUR_SMTP_PASSWORD

Then create the docker-compose.yml file:

Code
services:
  ghost:
    image: ghost:6
    restart: unless-stopped
    depends_on:
      mysql:
        condition: service_healthy
    ports:
      - "127.0.0.1:2368:2368"
    environment:
      url: https://blog.example.com
      database__client: mysql
      database__connection__host: mysql
      database__connection__user: ghost
      database__connection__password: ${MYSQL_PASSWORD}
      database__connection__database: ghost
      mail__transport: SMTP
      mail__from: noreply@mg.example.com
      mail__options__host: smtp.eu.mailgun.org
      mail__options__port: 465
      mail__options__secure: "true"
      mail__options__auth__user: ${SMTP_USER}
      mail__options__auth__pass: ${SMTP_PASS}
    volumes:
      - ./content:/var/lib/ghost/content

  mysql:
    image: mysql:8.0
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ghost
      MYSQL_USER: ghost
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - ./mysql:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1"]
      interval: 10s
      timeout: 5s
      retries: 10

The most important lines:

  • url is your blog's public address, including https://. Ghost uses it to create all links, image URLs, and links in emails. If the address here is wrong, links and the admin area won't work properly.
  • database__* connects Ghost to the MySQL container. Double underscores represent levels in the Ghost configuration, so database__connection__host corresponds to database.connection.host.
  • mail__* configures SMTP email delivery. If you have a Mailgun account in the US region, use smtp.mailgun.org. mail__from is the sender address.
  • ports binds Ghost only to 127.0.0.1. It can only be accessed from outside through the reverse proxy.
  • ./content contains images, themes, and files; ./mysql contains the database.

Start Ghost:

Code
docker compose up -d
docker compose logs -f ghost

When Ghost starts for the first time, it creates the database tables. This takes one or two minutes. Ghost is ready once no new “Creating table” lines appear in the log. Press Ctrl+C to stop viewing the logs.

Ghost 6 also offers its own more comprehensive Docker template with Caddy, ActivityPub, and web analytics. See TryGhost/ghost-docker. The lightweight setup above is enough for a blog with a newsletter.

First visit

First, set up the reverse proxy in the next section. Then open https://blog.example.com/ghost/ and create the owner account right away, as described above in “First visit: Create the owner account right away.” The same warning applies here: until the account is created, anyone who knows the address can take over the blog.

Access over HTTPS through a reverse proxy

To access Ghost from the outside, put a reverse proxy with a valid certificate in front of it. For the basics, see Set Up a Reverse Proxy with nginx and Create an SSL Certificate (Let's Encrypt). Here's a server block for nginx:

Code
server {
    listen 80;
    server_name blog.example.com;

    client_max_body_size 50m;

    location / {
        proxy_pass http://127.0.0.1:2368;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Then get the certificate with certbot --nginx -d blog.example.com. Certbot adds HTTPS and redirects HTTP by updating the block. X-Forwarded-Proto is important: it tells Ghost that the request came in over HTTPS. If this line is missing, Ghost will keep redirecting when url is set to an https:// address. client_max_body_size sets the maximum size of images and themes you can upload.

Back up your data

For a complete backup, you need the database and the content folder. Create a database dump while Ghost is running:

Code
cd /opt/ghost
docker compose exec -T mysql sh -c 'mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" --single-transaction ghost' > ghost-db-$(date +%F).sql
tar czf ghost-content-$(date +%F).tar.gz content docker-compose.yml .env

The backup contains the passwords from .env and your members' data. Keep it somewhere secure and not just on the VPS itself. To restore it, start a new directory with the same files, extract content, and import the dump with docker compose exec -T mysql sh -c 'mysql -u root -p"$MYSQL_ROOT_PASSWORD" ghost' < ghost-db-DATE.sql.

Update Ghost

The ghost:6 image includes all Ghost 6 versions. Back up the database and content first, and read the release notes. Then update with these commands:

Code
cd /opt/ghost
docker compose pull
docker compose up -d

When it starts, Ghost automatically updates the database. Upgrading to a new major version (for example, Ghost 7) is a bigger step: change the image only after reading the new version's notes and creating a fresh backup. You can find the installed version in the admin area under “Settings” > “About Ghost.”

Set up your blog and newsletter

The following steps are the same for the One-Click App and the manual installation. You'll find all the settings under “Settings” in the bottom-left corner of the admin area.

Basic settings and your first post

Under “General settings,” set your blog's name and description under “Title & description,” the time zone for scheduled posts under “Timezone,” and the language under “Publication language,” for example en. Create a new post by clicking the plus next to “Posts.” Click “Publish” to choose whether the post appears only on the website, goes out only as a newsletter, or does both.

Invite additional authors under “Staff.” Email delivery must be working, since invitations are sent by email.

Customize the theme and design

Under “Site” > “Design & branding,” you can customize the current theme's colors, logo, fonts, and homepage layout. Under “Theme,” choose another theme from the official selection or upload your own as a ZIP file. You can find themes in places such as the Ghost Marketplace. “Navigation” is where you set up menu items.

Uploaded themes are stored in the content volume and remain there through updates. If you customize a theme, edit a copy and give it a new name. Otherwise, an update to the original theme will overwrite your changes.

Members and newsletters with Mailgun

Ghost handles two types of email:

  • Individual emails, such as sign-in codes, invitations, and member sign-in links, are sent through the SMTP service you set up above.
  • Newsletters to many recipients are sent exclusively through the Mailgun API. SMTP alone isn't enough.

To set up newsletters, open “Settings” > “Newsletters” and click “Edit” next to “Mailgun.” Enter your Mailgun account's region (US or EU), your Mailgun domain, and a private API key from Mailgun. As long as you see “Mailgun is not set up,” you can publish posts, but you can't send them as newsletters.

Under “Membership” > “Access,” choose who can sign up as a member and what content they can see. Customize the signup form for readers under “Signup portal.” Connect paid memberships to your own Stripe account under “Tiers.” Find your member list under “Members,” where you can also import and export it as a CSV file.

Tip: Set up your sender domain properly

To keep newsletters out of spam, add the SPF and DKIM DNS records that Mailgun provides for your Mailgun domain. It's best to use a dedicated subdomain such as mg.example.com as your Mailgun domain.

Back up your blog

In addition to backing up your server, you can export your content as a JSON file under “Settings” > “Advanced” > “Import/Export.” The export includes posts, pages, tags, and settings, but not images or themes. For a complete migration, you'll also need the contents of the content volume or the content folder. Export members separately under “Members.”

Limitations

  • Limited without email delivery: Signing in from new devices, invitations, “Forgot password,” and member sign-in all require working email delivery.
  • Newsletters are sent only through Mailgun: Ghost doesn't support other providers for mass email.
  • Few plugins: Add functionality that Ghost doesn't include through integrations, webhooks, or “Code injection,” rather than plugins like those available for WordPress.
  • Not a website builder or online shop: WordPress is a better choice for business websites with lots of features or an online shop.
  • Additional Ghost 6 features: “Network” (sharing to the Fediverse) and web analytics require separate services that aren't included in the One-Click App or the lightweight Docker setup.

Conclusion

You've set up Ghost on your VPS, created the owner account, configured email delivery, and learned how to customize the design and set up members and newsletters. You now have a fast blog with its own newsletter, with your content and member list stored on your server.

Prefer to skip the Docker setup? Take the easy route with the One-Click App, as described above in “The easy way: Ghost as a One-Click App.”

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the faster option: Ghost starts with its own MySQL database, database credentials are generated automatically, and your blog is available over HTTPS once you add a domain. Enter your email settings under App environment in the app settings, and install updates under App update. Manual installation with Docker Compose is a good choice if you're not using One-Click Apps on your server or want to control the configuration, storage locations, and updates yourself. In either case, create the owner account right after installation.
Ghost emails a verification code whenever you sign in from a new device or browser. If email delivery isn't set up correctly, sign-in stops with this message. For the One-Click App, enter your SMTP credentials under App environment and don't forget MAIL_OPTIONS_HOST—for example, smtp.mailgun.org or smtp.eu.mailgun.org. To try Ghost without SMTP, you can disable the code with the custom environment variable security__staffDeviceVerification=false, but this makes your account less secure.
Any SMTP provider will work for individual emails such as sign-in codes, invitations, and member sign-in links. The One-Click App is preconfigured for Mailgun, but you can enter another provider's host, port, and credentials. Ghost only sends newsletters to many recipients through the Mailgun API. So, if you want to send posts as newsletters, you'll need a Mailgun account, which you can configure under Settings > Newsletters > Mailgun.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.