Self-Hosting A Free Website with Raspberry Pi 5 – Setting Up Ghost
Imagine turning a pocket-sized computer into a powerful, professional blogging platform. With Raspberry Pi 5 and Ghost, you can! This guide will walk you through setting up a self-hosted Ghost blog on a Raspberry Pi 5, complete with HTTPS secured through Cloudflare. Whether you're a seasoned developer or a hobbyist, this step-by-step tutorial is designed to get your website up and running smoothly.
Disclaimer: Hosting a website from home can expose your network to security risks. Always ensure you have robust security measures in place, and consult with your ISP to confirm that hosting is permitted under your service agreement.
How to Navigate This Series
This guide walks you through the process of setting up a self-hosted Ghost website on a Raspberry Pi 5. With Ghost, you’ll be able to create a fast, professional site optimized for publishing and content management. Once Ghost is installed, you can further configure your setup by following our Cloudflare guide for added security and performance.
- Complete the Core Setup: This guide provides step-by-step instructions for installing and configuring Ghost on your Raspberry Pi 5.
- Finalize with Cloudflare: Once Ghost is installed, return to our Cloudflare Setup Guide to secure and enhance your site’s performance and optimization.
Related Articles
- Self-Hosting A Free Website with Raspberry Pi 5 – Setting Up WordPress
- Self-Hosting A Free Website with Raspberry Pi 5 – Setting Up Drupal
- Self-Hosting A Free Website – Cloudflare Setup Guide
Getting Started
Ghost is a modern publishing platform built on Node.js, renowned for its simplicity and performance. By self-hosting Ghost on a Raspberry Pi 5, you can enjoy a powerful blogging platform without the recurring costs of traditional hosting services. Plus, with Cloudflare's free SSL certificates, your website will be secure and professional.
In this guide, we'll cover everything from setting up your Raspberry Pi to configuring Ghost, Let's dive in!
Hardware Requirements
The speed of your Raspberry Pi affects how quickly your website can perform tasks, such as saving data to external storage. In this tutorial, we are using a Raspberry Pi 5 with 8GB of RAM, but a Raspberry Pi 4 is also capable of hosting a Ghost blog:
- Raspberry Pi 5 Kit with a power supply, MicroSD card, Power Supply, Case and Heat sinks
- External storage (optional) for larger Ghost Blog sites, Requires HAT and Drive.
- Network: Reliable internet connection
- Domain Name: A registered domain name pointed to your server's IP address
- Cloudflare Account: A free account to manage DNS and SSL
Setting Up Your Linux Server Environment
Once you have the necessary hardware, the next step is to set up your Linux server environment. Using Ubuntu Server on your SSD or NVMe drive provides a robust and efficient platform that's well-suited for hosting your Ghost blog. While microSD cards are fine for testing purposes, SSDs or NVMe drives offer significantly better performance and reliability for production use. Here's how to get your Linux environment up and running:
Install Your Linux Distribution
Choosing the right Linux distribution is key to ensuring smooth performance on your Raspberry Pi. Ubuntu Server is an excellent choice due to its minimal footprint and compatibility with most web hosting requirements.
- Download the OS: Start by downloading the Ubuntu Server image from the official Ubuntu website. Choose the 64-bit version for optimal performance and compatibility with modern applications. You can also use Raspberry Pi OS Lite (64-bit) successfully.
- Prepare Your Storage Device:
- For Testing (MicroSD Card): If you're in the testing phase, a microSD card will suffice. Ensure it's a high-quality, high-speed card to minimize performance bottlenecks.
- For Production (SSD or NVMe Drive): For a stable and fast production environment, use an SSD or NVMe drive connected via USB 3.0. This setup significantly enhances read/write speeds and improves overall reliability.
- Flash the OS Image: Use a tool like Raspberry Pi Imager or balenaEtcher to flash the Ubuntu Server image onto your chosen storage device.
- Open Raspberry Pi Imager on your computer.
- Select "Choose OS" and pick Ubuntu Server 22.04 LTS (64-bit) from the list.
- Select "Choose Storage" and choose your target storage device—this could be an SSD, NVMe drive, or microSD card.
- Click "Write" to initiate the flashing process. A prompt will appear asking if you'd like to customize your installation.
- Choose "Yes" to access customization options:Set Hostname: Assign a unique name to your Raspberry Pi for easy identification on your network.Enable SSH: Activate SSH for remote access by selecting this option and setting a secure password or providing an SSH key.Configure Wi-Fi: Enter your Wi-Fi network's SSID and password to enable wireless connectivity.Set Locale: Adjust language, time zone, and keyboard layout to match your preferences.
- After configuring these settings, proceed with the flashing process.
After successfully flashing the OS image onto your chosen storage device, it's time to boot up your Raspberry Pi. Insert your SSD, NVMe drive, or microSD card into the Raspberry Pi, connect it to a power source, and allow it to start. The system will initialize and set up the basic environment, which may take a few minutes on the first run.
Once your Raspberry Pi has booted up, the next step is to update your system to ensure it has the latest features and security patches. If you’ve preconfigured SSH during the flashing process, you can simply SSH into your Raspberry Pi from another device on the same network using a command like this:
ssh username@your-pi-hostname.local
(Replace username
with your Pi's username, and your-pi-hostname.local
with the hostname you set earlier. If the hostname isn't working, you can use the Pi's IP address instead.)
If SSH wasn’t preconfigured, you’ll need to connect a keyboard and monitor to your Raspberry Pi to make some initial changes. Once logged in, follow these steps:
- Update your system to ensure it’s secure and stable by running:
sudo apt update && sudo apt upgrade -y
This command refreshes the package list and applies available updates.
- Enable SSH for remote access (if it isn’t already enabled) by running:
sudo systemctl enable ssh
sudo systemctl start ssh
Now, with SSH enabled, you can manage your Raspberry Pi remotely from any device on the same network. This provides flexibility and convenience for future configurations.
At this stage, your Linux server environment is set up and ready. Next, you’ll proceed to configure your web server and install Ghost, bringing you closer to launching your self-hosted website.
Web Server Installation ✅
With your Linux environment ready, the next step is to set up a web server. For this guide, we’ll be using Apache HTTP Server. Alternatively, you can use NGINX, which is a popular choice for hosting due to its lightweight design, speed, and compatibility with modern web standards.
- Apache: Known for its versatility and ease of use, Apache HTTP Server is a great choice for beginners. It handles dynamic content efficiently, supporting pages that rely on scripting languages like PHP.
- Nginx: Optimized for speed and memory efficiency, Nginx excels at serving high-traffic sites and static content. It manages multiple simultaneous connections with ease, though it does have a steeper learning curve for new users.
Setting up Apache on your Raspberry Pi is a straightforward process by follow the step-by-step commands below to install and configure Apache:
- Update Your System
Before installing Apache, make sure your system is up-to-date:
sudo apt update && sudo apt upgrade -y
- Install Apache HTTP Server
Install Apache using the package manager:
sudo apt install apache2 -y
- Verify Apache Installation
After installation, verify that Apache is running by checking its status:
sudo systemctl status apache2
You should see a message indicating that Apache is active and running.
- Test Apache
To confirm Apache is working:- Open your browser and go to your Raspberry Pi's IP address (e.g.,
http://192.168.x.x
). - You should see the default Apache welcome page. (To find your Pi’s IP address you can use this command:
hostname -I
- Open your browser and go to your Raspberry Pi's IP address (e.g.,
- Enable Apache to Start on Boot
Ensure Apache starts automatically when the Raspberry Pi reboots:
sudo systemctl enable apache2
- Adjust Firewall Settings (if applicable)
If you haveufw
(Uncomplicated Firewall) enabled, allow HTTP traffic:
sudo ufw allow 'Apache'
- Restart Apache (to Apply Changes)
After making any configuration changes, restart Apache:
sudo systemctl restart apache2
Database Installation
A reliable database is essential for storing and managing your website’s data, especially when using a platform like Ghost that relies on databases for content, user information, and configuration settings. For this setup, MariaDB is a popular open-source option that serves as a high-performance, drop-in replacement for MySQL. Known for its simplicity and compatibility, MariaDB is an excellent choice for self-hosting, efficiently handling dynamic content and ensuring smooth, dependable operation.
Installing MariaDB
Follow these steps to install and configure MariaDB on your Linux server.
- Update Your System: As always, it’s a good practice to start by updating your package list to ensure you’re downloading the latest version of MariaDB. Open a terminal and enter:
sudo apt update && sudo apt upgrade -y
- Install MariaDB: Use the following command to install MariaDB on your system. This command will download MariaDB along with all necessary dependencies:
sudo apt install mariadb-server -y
- Start and Enable MariaDB: After installation, start the MariaDB service and set it to run automatically on startup with these commands:
sudo systemctl start mariadb
sudo systemctl enable mariadb
This ensures that your database server is up and running whenever your server is active.
- Secure the Installation: For security, it’s important to configure MariaDB by running the following security script:
sudo mysql_secure_installation
This will prompt you to set a root password and make some security adjustments, such as removing anonymous users, disallowing remote root login, and deleting the test database. For each prompt, it’s generally recommended to select the secure option (Y
) to strengthen the database’s security.
- Verify Installation: To confirm MariaDB is running, use the following command to check the service status:
sudo systemctl status mariadb
You should see an active status, indicating that MariaDB is up and running.
You can also log into the MariaDB shell to confirm the correct configuration:
sudo mysql -u root -p
Enter the root password you set during the secure installation step. If you successfully enter the MariaDB shell, the installation is complete.
Ghost Installation Guide
To get Ghost up and running smoothly on your server, you'll need to install a few essentials, including Node.js, MySQL, and Ghost's command-line interface (CLI). Here’s how:
Install Node.js
Ghost runs on Node.js, so you'll need to install the latest Long Term Support (LTS) version. We’ll use NodeSource, a popular repository for Node.js, to make the installation process seamless. Follow these steps:
- Update Your System and Install Prerequisites:
This will update your package index and install essential packages for managing the software we will be installing.
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
- Add the NodeSource Repository Key:
For secure installations, it’s important to add the repository’s GPG key. This step ensures that the packages you install are authentic.
Note: Input the second command (curl...) as a single command.
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
- Set Up the Repository for Node.js:
Now, create a repository entry. Here, you’ll choose a supported Node.js version by setting theNODE_MAJOR
variable. For instance, to use Node.js 20:
Note: Input the second command (echo...) as a single command.
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
- Install Node.js:
Finally, update your package list again and install Node.js:
sudo apt-get update
sudo apt-get install nodejs -y
MySQL (MariaDB) Setup
Create a Database for Your Website: Ghost requires a dedicated database for storing content and configurations. First log into the database with this command:
sudo mysql -u root -p
While logged into the MariaDB shell, create a database and user specifically for Ghost by entering the following commands:
CREATE DATABASE your_database_name;
CREATE USER 'your_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_user'@'localhost';
FLUSH PRIVILEGES;
Replace your_database_name
, your_user
, and your_password
with your own values. This setup grants the user access to the database, which your website platform will use to store and retrieve data.
Exit the MariaDB shell by typing:
EXIT;
With MariaDB installed and configured, you now have a fully operational database ready to support your website.
Install Ghost-CLI
Ghost’s CLI tool simplifies tasks like setup, configuration, and updates. Use npm
(Node's package manager) to install it globally on your system:
sudo npm install -g ghost-cli@latest
You may get a message to update your NPM, like I did; if so, just follow the instructions on the screen. Make sure to add sudo
to the front of the command.
Create a Directory for Ghost
Choose a directory to install Ghost. Typically, this is in the /var/www
folder. Create the directory where Ghost will be installed:
sudo mkdir -p /var/www/ghost
Make sure the directory /var/www/ghost
is writable for the root user. You can verify this by running the following command to guarantee write access:
sudo chown $USER:$USER /var/www/ghost
Switch to the Ghost installation directory:
cd /var/www/ghost
Install Ghost
With the Ghost-CLI installed and your directory set up, you can install Ghost by running:
ghost install
During the installation process, a series of questions about the information you've setup for your instance will come up. Like before, replace your_database_name
, your_user
, and your_password
with your own values.
- The domain you’ll use for Ghost (e.g.,
https://yourdomain.com
). - Your MySQL hostname: (e.g.,
127.0.0.1
). - Your MySQL username: (e.g.,
your_user
). - Your MySQL password: (e.g.,
your_password
). - MySQL Database Name: (e.g.,
your_database_name
).
Select yes to setting up Systemd and yes to starting Ghost, and the CLI will handle the rest of the setup process, including configuration, starting Ghost, and enabling it as a system service.
After installation, we need to configure Ghost to work with Apache. In order to do that, you’ll need to set up a virtual host in Apache to point to this directory and enable Ghost to serve your site.
Setting Up an Apache Virtual Host for Ghost
To configure Apache to serve your Ghost site, you'll need to create a virtual host file:
- Open a new configuration file for your site:
sudo nano /etc/apache2/sites-available/ghost.conf
- Add the following content:
<VirtualHost *:80>
DocumentRoot /var/www/ghost/system/nginx-root
<Directory /var/www/ghost/system/nginx-root>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:2368/
ProxyPassReverse / http://127.0.0.1:2368/
ErrorLog ${APACHE_LOG_DIR}/ghost_error.log
CustomLog ${APACHE_LOG_DIR}/ghost_access.log combined
</VirtualHost>
You should be able to copy and paste this into the nano editor with CTRL-SHIFT-V
Once you have made the changes, you can press CTRL-X
then Y
and finally ENTER
to save the changes.
This configuration assumes Ghost is running on its default port, 2368
.
- Enable the new site and the required Apache modules:
sudo a2ensite ghost.conf
sudo a2enmod proxy proxy_http
- Restart Apache to apply the changes:
sudo systemctl restart apache2
Test your setup by navigating to http://your-blog-ip:2368/ghost/
. If you’ve configured everything correctly, you should see your Ghost admin site.
As mentioned earlier in this guide, this is the point where you transition to our Cloudflare setup article to configure your domain.
Maintenance: Keeping Your Site Running Smoothly
Regular maintenance is essential for ensuring your self-hosted site remains secure, responsive, and up-to-date. By setting up automated backups, regularly updating software, and understanding common issues, you can keep your website running smoothly with minimal downtime.
Updating
Keeping both your system and application software updated is crucial for security and functionality.
- System Updates:
- Regularly update your server’s operating system to ensure security patches and new features are applied. On most Linux distributions, use:
- Use cloud storage services like Google Drive, Amazon S3, or Dropbox for remote backups. This adds an extra layer of protection in case of hardware failures on your main server.
Pro Tip: Set up automated backups with a cron job to ensure your data is safe. Usemysqldump
for database backups andrsync
for file backups. For example, schedule backups usingcrontab -e
and add this line:0 2 * * * mysqldump -u root -p drupal_db > /path/to/backup.sql
.
sudo apt update && sudo apt upgrade -y
- Consider setting up unattended upgrades to automate security updates:
sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades
- Application Updates:
- CMSs like WordPress, Drupal, or Ghost frequently release updates with security patches and new features. Set notifications to remind you when updates are available, and regularly check the platform’s dashboard or use plugins to automate updates.
- For other applications, review each update’s release notes, especially if you’ve customized your setup, to ensure compatibility with existing plugins and configurations.
Tip: Over time, backup files, cache, and logs can consume significant disk space. Use tools like ncdu to visualize disk usage and periodically delete unnecessary files
Use monitoring tools like UptimeRobot or Pingdom to receive alerts if your site goes offline. These tools monitor server response times and can send notifications via email or SMS if they detect downtime.
By scheduling regular backups, staying on top of updates, and proactively addressing common issues, you’ll maintain a secure, efficient website that continues to deliver a reliable experience to visitors.
Beyond the Setup
By following this guide, you've set up a secure and efficient self-hosted Ghost blog on your Linux server. Regular maintenance and updates will keep your site running smoothly, allowing you to focus on creating and sharing your content. Remember to monitor your server's performance and security regularly, and make backups to safeguard your data.
Your self-hosted blog is more than a website—it's a testament to your DIY spirit. Keep learning, experimenting, and building!
Resources and Further Learning
Building and maintaining a self-hosted website is a continuous learning journey, and accessing the right resources can make the process much smoother. From online forums and educational platforms to comprehensive documentation, here are some valuable resources to help you troubleshoot, expand your skills, and stay up-to-date with the latest best practices.
Forums
Online forums are essential for troubleshooting issues, sharing ideas, and connecting with other developers and enthusiasts. Here are some of the best forums for support and guidance:
- Stack Overflow: An extensive community of developers ready to help with coding and development questions. Whether you’re stuck on server configuration, coding errors, or platform-specific issues, Stack Overflow’s vast archive of questions and answers is invaluable.
- Raspberry Pi Forums: For those using a Raspberry Pi as their server, the official Raspberry Pi Forums offer dedicated support for Pi-specific challenges. Topics include hardware compatibility, networking setup, and project ideas, making it a go-to resource for Pi users.
- Cloudflare Community: The Cloudflare Community is a hub for users looking to optimize DNS settings, enable CDN, and troubleshoot performance issues. Here, you’ll find advice from both Cloudflare experts and experienced users, covering everything from basic SSL configurations to advanced performance settings.
Educational Resources
Learning platforms offer structured courses and hands-on labs to build foundational skills in Linux, networking, and web development. Consider these resources for guided learning:
- Udemy & Coursera: Both Udemy and Coursera feature a variety of courses tailored to different skill levels. Topics range from Linux administration and server management to full-stack web development and networking essentials. Look for courses with high ratings and hands-on labs for practical experience.
- YouTube Channels:
- Binary Tech {LABS}: A source for straightforward tutorials on DIY tech projects, home automation, and Raspberry Pi setups. Binary Tech {LABS} breaks down complex topics into easy-to-follow steps, making tech accessible for everyone from hobbyists to experienced users.
- NetworkChuck: Known for his engaging, step-by-step tutorials on networking, server setup, and cyber security. NetworkChuck’s videos simplify complex topics like DNS configuration, server administration, and Docker, making them accessible for beginners and advanced users alike.
- Traversy Media: A popular channel covering web development and backend technologies. From HTML basics to setting up Nginx and Apache, Traversy Media provides clear, practical guidance on various web technologies.
Documentation
Official documentation is a key resource for understanding the inner workings of each platform and ensuring your setup aligns with best practices. Bookmark these resources for in-depth information, configuration options, and troubleshooting steps:
- Ghost Docs: Ghost’s documentation is concise and highly organized, covering everything from installation to theme customization. It’s ideal for users looking to optimize the platform’s performance and explore the latest publishing features.
By leveraging these community forums, educational platforms, and official documentation resources, you can deepen your understanding, solve technical challenges more effectively, and keep improving your self-hosted website setup.
Thanks for Your Support!
I truly appreciate you taking the time to read my article. If you found it helpful, please consider sharing it with your friends or fellow makers. Your support helps me continue creating content like this.
- Leave a Comment: Got questions or project ideas? Drop them below—I'd love to hear from you!
- Subscribe: For more tutorials, guides, and tips, subscribe to my YouTube channel and stay updated on all things tech!
- Shop & Support: If you're ready to get started, check out the recommended products in my articles using my affiliate links. It helps keep the lights on without costing you anything extra!
Thanks again for being part of this community, and happy building!