Ghost is a powerful, open-source platform designed for creating and managing professional-grade websites, blogs, and publications. Its focus on simplicity, speed, and elegant design makes it an excellent choice for developers, system administrators, and tech-savvy users who value complete control over their data and infrastructure. In this guide, weβll cover everything you need to deploy, configure, and manage a self-hosted Ghost instance, including installation, reverse proxy setups, logging, backups, updates, and leveraging Ghostβs unique features.
Installing Ghost
π¦ Docker/Docker Compose Setup
Using Docker Compose is one of the easiest and most modular methods to run Ghost. Below is a docker-compose.yml
file tailored for Ghost:
version: '3.8'
services:
ghost:
image: ghost:latest
container_name: ghost
ports:
- "2368:2368" # Ghost listens on port 2368 by default
volumes:
- ./ghost-content:/var/lib/ghost/content # Persist Ghost content
environment:
- url=http://your-domain.com # Replace with your domain
- NODE_ENV=production
restart: always
To deploy Ghost using this configuration, run the following commands:
mkdir ghost && cd ghost
nano docker-compose.yml # Paste the configuration above
docker-compose up -d
This will set up Ghost with persistent storage for content under the ./ghost-content
directory.
π Manual Installation
For direct installation on a Linux server, follow these steps:
sudo apt update && sudo apt upgrade -y
## Install required dependencies
sudo apt install -y nginx mysql-server nodejs npm curl unzip
## Install Ghost CLI globally
sudo npm install -g ghost-cli
## Create a directory for Ghost and set permissions
sudo mkdir -p /var/www/ghost
sudo chown $USER:$USER /var/www/ghost
sudo chmod 775 /var/www/ghost
cd /var/www/ghost
## Install Ghost
ghost install
Follow the prompts during the ghost install
process to configure the app and database.
Configuring Nginx as a Reverse Proxy
π Nginx Configuration
Below is an example Nginx server block to route traffic to Ghost running on port 2368
:
server {
listen 80;
server_name your-domain.com;
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;
}
access_log /var/log/nginx/ghost_access.log;
error_log /var/log/nginx/ghost_error.log;
}
Save this configuration to /etc/nginx/sites-available/ghost
and enable it:
sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled
sudo nginx -t # Test the configuration
sudo systemctl reload nginx
π SSL/TLS Setup
Secure your Ghost site with a free Let's Encrypt SSL certificate:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com
This command automatically configures SSL for your Nginx block and sets up certificate renewals.
π οΈ Testing and Reloading Nginx
After any changes, test and reload Nginx to avoid configuration issues:
sudo nginx -t
sudo systemctl reload nginx
Logging and Debugging Ghost
ποΈ Enabling Debug Logs
To enable debug-level logging in Ghost, edit the config.production.json
file located in the Ghost installation directory:
{
"logging": {
"level": "debug",
"transports": ["file", "stdout"]
}
}
Restart Ghost to apply changes:
ghost restart
π Viewing Logs
If running in Docker, view logs using:
docker logs ghost
For manual installations, logs are typically stored in /var/www/ghost/content/logs/
. Use tail
to view them:
tail -f /var/www/ghost/content/logs/*.log
π οΈ Troubleshooting Common Issues
For common startup issues, inspect permissions with:
ls -lh /var/www/ghost
And resolve port conflicts by identifying processes using port 2368
:
sudo netstat -tuln | grep 2368
π€ Exporting Logs
Send logs to an ELK stack using filebeat
or similar tools. Install filebeat
and configure it to forward logs from the Ghost log directory.
Backup and Restore
ποΈ File-Based Backups
To back up Ghostβs files and content:
tar -czvf ghost-backup.tar.gz /var/www/ghost
π Database Backups
For MySQL-based setups, export the database:
mysqldump -u root -p ghost_production > ghost_db_backup.sql
To restore:
mysql -u root -p ghost_production < ghost_db_backup.sql
π Automated Backup Scripts
Automate file and database backups with a cron job:
echo "0 2 * * * tar -czvf /backup/ghost-$(date +\%F).tar.gz /var/www/ghost && mysqldump -u root -pYourPassword ghost_production > /backup/ghost_db_$(date +\%F).sql" | crontab -
Updating and Upgrading Ghost
β¬οΈ Updating Docker Images
Update the Ghost container with:
docker-compose pull ghost
docker-compose down
docker-compose up -d
π οΈ Manual Updates
For manual installations, upgrade Ghost using:
ghost update
π Checking for Updates
Check for updates with:
ghost ls
Leveraging Ghostβs Unique Features
π§ Enabling APIs
Ghostβs Content API can be enabled and used for programmatic access to content. Generate an API key from the Admin interface, then query the API with curl
:
curl -X GET https://your-domain.com/ghost/api/v3/content/posts/ \
-H "Authorization: Ghost-API-Key YOUR_API_KEY"
π Advanced Configurations
Customize the theme by editing files in the content/themes/
directory and reloading Ghost:
ghost restart
Integrate with third-party tools like Zapier or custom webhooks using the Admin UI.
Wrapping Up
Self-hosting Ghost gives you unparalleled control over your content management system, from installation and optimization to customization and advanced features. By following this guide, youβve learned how to deploy, secure, and manage Ghost effectively. Take advantage of Ghostβs flexibility, and start building your next great publication today.