How to Install and Use Ghost for Blogging on Linux
How to Install and Use Ghost for Blogging on Linux
Introduction
Ghost is a popular open-source blogging platform known for its simplicity, performance, and elegant design. Unlike WordPress, Ghost focuses primarily on blogging, making it ideal for writers and publishers who want a clean, distraction-free environment. In this guide, I’ll show you how to install and use Ghost on Linux, ensuring your site is up and running in no time. Follow this step-by-step guide to set up your Ghost blog and make it SEO-friendly.
Prerequisites
Before you begin, ensure you have the following:
- A Linux Server (Ubuntu 20.04/22.04 recommended)
- SSH Access to your server
- Node.js installed (v18 or newer)
- MySQL database (MariaDB can also be used)
- Nginx as a web server
- A domain name (optional but recommended)
- Root or sudo user privileges
Step 1: Update Your Server
The first thing to do is to update your Linux server. Open a terminal window and log in to your server via SSH. Then, run the following command:
sudo apt update && sudo apt upgrade -y
This ensures all packages are up-to-date.
Step 2: Install Node.js
Ghost requires Node.js to function. Install Node.js by executing:
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash –
sudo apt install -y nodejs
Verify the installation:
node -v
npm -v
Make sure you have Node.js version 18 or newer.
Step 3: Install MySQL
Ghost uses MySQL as its database. Install it with:
sudo apt install mysql-server
Secure your MySQL installation:
sudo mysql_secure_installation
Follow the prompts to set a root password and secure your installation. Next, log in to the MySQL shell:
sudo mysql -u root -p
Create a new database for Ghost:
CREATE DATABASE ghostdb;
CREATE USER ‘ghostuser’@’localhost’ IDENTIFIED BY ‘your-strong-password’;
GRANT ALL PRIVILEGES ON ghostdb.* TO ‘ghostuser’@’localhost’;
FLUSH PRIVILEGES;
EXIT;
Replace your-strong-password with a secure password.
Step 4: Install Nginx
Nginx will serve as a reverse proxy to manage HTTP requests. Install it by running:
sudo apt install nginx
After installation, start Nginx and enable it to start on boot:
sudo systemctl start nginx
sudo systemctl enable nginx
Step 5: Install Ghost-CLI
The Ghost-CLI tool simplifies the installation process. Install it globally:
sudo npm install -g ghost-cli
Step 6: Set Up Your Ghost Directory
Create a new directory where you want to install Ghost. For example:
sudo mkdir -p /var/www/ghost
sudo chown $USER:$USER /var/www/ghost
cd /var/www/ghost
Step 7: Install Ghost
Now, use the Ghost-CLI to install Ghost:
ghost install
During the installation, the CLI will prompt you for various details such as your blog URL, MySQL database information, and whether you want to set up SSL. Make sure to follow the prompts carefully.
Step 8: Configure Nginx for Ghost
The Ghost-CLI will automatically configure Nginx for you. However, if you need to make manual adjustments, you can do so by editing the Nginx configuration file:
sudo nano /etc/nginx/sites-available/yourdomain.com
Here’s a sample configuration:
server {
listen 80;
server_name yourdomain.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;
}
}
Replace yourdomain.com with your actual domain name. Save and close the file. Enable the configuration:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Step 9: Secure Your Site with SSL
Ghost-CLI can automatically set up SSL using Let’s Encrypt. If you didn’t choose this during the installation, you can run:
ghost setup ssl
Step 10: Access the Ghost Admin Panel
Once the installation is complete, you can access your Ghost blog by navigating to http://yourdomain.com/ghost. This URL will take you to the admin login page, where you can set up your account and start managing your content.
Customizing Your Ghost Blog
- Themes: Ghost has various themes that you can use to customize the look of your blog. You can install new themes from the admin panel or by manually uploading theme files.
- Plugins and Integrations: Ghost supports integrations with various tools like Google Analytics, Mailchimp, and Zapier. These integrations help you expand the functionality of your blog.
Updating Ghost
Keeping your Ghost blog up-to-date is essential for security and new features. To update Ghost, navigate to your Ghost directory and run:
ghost update