Shared hosting appears to not be as popular as it once was. There are plenty legitimate reasons for this such as my primary concern being of the security of my data on a server that has other “customers” on it as well. This means that if someone’s poorly installed and (un)maintained WordPress site is exploited, my data may be exposed to the attacker depending on the exploit in question. That said, there are still plenty of other reasons why shared hosting is either the optimal choice, or the only choice for some users – and that is why I am discussing how to install the popular open-source, Node.js Ghost blogging platform in a shared hosting environment, specifically with HestiaCP.
Disclaimer: This guide assumes that you have already created a domain in HestiaCP and either used the automated Let’s Encrypt SSL certificate installation or manually inserted a valid SSL certificate.
Log into the terminal of your server and install
nvm, or node version manager. This is an excellent tool that helps with quick installs of various node versions, and the swapping between of versions on the fly. At the time of this guide, the latest version of nvm is 0.39.1, but you will want to keep an eye out on the release page to make sure you’re downloading the most recent version.
With that in mind, run the following commands to download and install nvm, reset your terminal, and install the latest LTS Node 16.x version and latest node package manager:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash $ exec $BASH $ nvm install 16 $ nvm install-latest-npm
Installing Ghost via ghost-cli
ghost-cli proved problematic in the past for instances where you wanted to run Ghost on a shared hosting server. However as they made changes to the tool itself, it’s become an extremely easy and elegant solution to installing Ghost, and keeping your Ghost blog up to date. Run the following command to install ghost-cli globally:
$ npm install [email protected] -g
Now that you have the ghost-cli tool, you will want to navigate to the
public_html directory of your domain to install Ghost. Once there, simply run the following commands to perform a “local” Ghost install and stop the service:
$ ghost install local $ ghost stop
If you attempt to visit your site at this time, you will be greeted with a 503 Service Unavailable message. This is expected until we configure Apache and actually have the Ghost service running.
In order to run Ghost, or really any other similar Node.js web application, the best method is to use a reverse proxy. Since this guide is specific for HestiaCP, I’ll name the directories and files where you can configure Apache – however keep in mind that you can set up a reverse proxy for any sort of Apache environment in case you’re running some other web control panel software.
The location of the Apache config files for your domain in HestiaCP will be:
Once in this directory, you will want to create a file named
apache2.conf_ghost, and paste in the following contents. Keep in mind that
127.0.01 should be swapped out for the IP address that you’re wanting to use. The port
2368 is the default Ghost port, so unless you’re wanting to change this, you can leave this the same.
Timeout 2400 ProxyTimeout 2400 ProxyBadHeader Ignore ProxyPass / http://127.0.0.1:2368/ ProxyPassReverse / http://127.0.0.1:2368/
Restart Apache either via the command line or the HestiaCP web interface.
Configure and Run Ghost
Make sure that you are back in the
public_html directory of your domain, or wherever your Ghost install is at. You will then run the following command to configure Ghost instead of having to manually edit the configuration file. Once again, keeping in mind to replace values such as the domain name, port, and IP address:
$ ghost config --url https://domain.name --port 2368 --ip 127.0.0.1
Once configured, you simply need to run
ghost start to start your Ghost blog. Navigate to your domain and confirm that you’re greeted with a Ghost install!
Keeping your Ghost install up to date is as easy as stopping your Ghost service, running a single update command, and starting your Ghost service back up:
$ ghost stop $ ghost update --no-setup-linux-user $ ghost start