To deploy a Ghost blog using the command line interface (CLI), follow these steps:
Make sure Docker and Docker Compose are installed on your machine. If not, follow the installation instructions from the Docker website and Docker Compose installation page.
Create a directory for your Ghost blog project:
mkdir ghost-blog
cd ghost-blog
Create a docker-compose.yml
file in the project directory with the following content:
version: "3.3"
services:
ghost:
image: ghost:latest
restart: always
ports:
- "2368:2368"
volumes:
- ./content:/var/lib/ghost/content
environment:
url: http://localhost:2368
db:
image: mariadb:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: your_mysql_root_password
MYSQL_USER: ghost
MYSQL_PASSWORD: ghostdbpass
MYSQL_DATABASE: ghostdb
volumes:
- ./mysql:/var/lib/mysql
Navigate to the project directory and run Docker Compose to start the Ghost blog and database containers:
docker-compose up -d
This command will download the necessary Docker images, create the containers, and start them. Your Ghost blog will be accessible at http://localhost:2368
.
Open a web browser and go to http://localhost:2368/ghost
. You will be prompted to set up your Ghost admin account and configure your blog.
To secure your blog with SSL, you can use Let's Encrypt and Nginx. Here's how to set it up:
-
Install Certbot:
sudo apt-get update sudo apt-get install certbot python3-certbot-nginx
-
Obtain an SSL Certificate:
sudo certbot certonly --standalone -d yourdomain.com
-
Create Nginx Configuration: Create a new Nginx configuration file for your Ghost blog:
sudo nano /etc/nginx/sites-available/ghost
Add the following content to the file, replacing
yourdomain.com
with your actual domain:server { listen 80; server_name yourdomain.com; location / { proxy_pass http://localhost: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; } location /.well-known/acme-challenge/ { root /var/www/html; } } server { listen 443 ssl; server_name yourdomain.com; ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; include /etc/letsencrypt/options-ssl-nginx.conf; ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; location / { proxy_pass http://localhost: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; } }
-
Enable the Nginx Configuration:
sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ sudo systemctl restart nginx
To automate the deployment, you can use GitHub Actions by creating a workflow file at .github/workflows/deploy.yml
:
name: Deploy Ghost Blog
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v2
with:
push: true
tags: your-dockerhub-username/ghost-blog:latest
- name: Deploy to Server
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
ssh -o StrictHostKeyChecking=no user@your-server-ip << 'EOF'
cd /path/to/your/project
git pull origin main
docker-compose down
docker-compose up -d
EOF
Replace the placeholders with your actual values and ensure your Docker Hub credentials and SSH private key are stored as GitHub secrets.