Creating a blog is an exciting venture, and Ghost is a powerful platform that focuses on simplicity, speed, and flexibility. You can either build a blog directly on their site, where they will charge a small monthly fee, or install it on a self-hosted instance, which is free!

In the following sections, I will guide you the process step by step and discuss the issues I encountered while setting up Ghost on Debian:

For the official installation guide, please visit: https://ghost.org/docs/install/ubuntu/

1. Configuration of Apache

You can either copy a existing apache configuration of another site and modify it o create a new empty file directly. I will use vim for this purpose.

vim /etc/apache2/sites-available/ghost.conf

Update the file with the new domain and add some Proxy configurations.

<VirtualHost *:80>
        ServerName dev.2volt.cc
        DocumentRoot /var/www/html/ghost

        ProxyPreserveHost On

        RewriteEngine On
        Redirect permanent / https://dev.2volt.cc/
        ErrorLog ${APACHE_LOG_DIR}/dev_error.log
        CustomLog ${APACHE_LOG_DIR}/dev_access.log combined
</VirtualHost>

<VirtualHost *:443>
        ServerName dev.2volt.cc
        DocumentRoot /var/www/html/ghost

        ProxyPreserveHost On
        ProxyPass / http://localhost:2368/
        ProxyPassReverse / http://localhost:2368/

        ErrorLog ${APACHE_LOG_DIR}/ghost_error.log
        CustomLog ${APACHE_LOG_DIR}/ghost_access.log combined
</VirtualHost>

After updating the configuration, add the site to Apache:

a2ensite ghost
systemctl restart apache2

To set up SSL, use the following command; it will update the Apache configuration file for you:

sudo certbot --apache --domains dev.2volt.cc

2. Configure database

If you are using MariaDB, follow these steps:

sudo mysql -u root -p
MariaDB [(none)]> CREATE USER 'xx'@localhost IDENTIFIED BY 'ur_password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit

3. Install Ghost

Set the owner of the directory to the user running apache2, which is typically www-data:

cd  /var/www/html/
sudo mkdir -p ghost
sudo chown www-data:www-data ghost
sudo chmod 775 ghost
cd ghost
ghost install

The Ghost installation process will prompt you for information about the site:

  • Blog URL: https://dev.2volt.cc/
  • MySQL hostname: 127.0.0.1
  • MySQL username/password: xx, ur_password
  • Database: ghost

Skip the Set up NGINX, SSL parts. Also, remember to set up the firewall:

 sudo ufw allow 2368

Now you should be able open https://dev.2volt.cc/ and see the site.

4. Issues I met

If you failed to see the site, like what I have experienced, you could troubleshooting as follow:

If the site automatically direct to localhost:2368, check the port in the configuration file:

cat config.production.json

The port is expected to be 2368, but it could be 2369. This discrepancy may arise from multiple installations.

If you see 500 or failed to connect, check the log of it:

cat /var/log/apache2/ghost_error.log

In some cases, it is due to failed to connected to the database. Because Node 18 will use IPv6 over IPv4, and you will see following error if you set the host of database to localhost.

  • Connect ECONNREFUSED ::1:3306

A simple fix is specifying it to 127.0.0.1.


Blog Comments powered by Disqus.