This blog is powered by Ghost, a much cleaner, simpler solution when compare to other like WordPress. Here is a quick guide on how to setup NGINX, MySQL and Ghost on Ubuntu:
NGINX
Installing NGINX is relatively simple, just type the following command:
$ sudo apt install nginx
After it is done, the web server should be running on port 80. Then you will need to update your DNS and configure NGINX. I simple NGINX configuration should look something like this:
server {
listen 80;
listen [::]:80;
server_name ocean.hk www.ocean.hk;
root /var/www/ocean.hk/html;
index index.html index.htm;
}
But wait, you probably also want to enable HTTPS on your website. With Let's Encrypt, you can apply, install and auto renew your SSL certificate by using very simple command.
First you will need to install Certbot by adding the certbot PPA to your apt repository:
$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository universe
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
Then run the following command:
$ sudo apt-get install certbot python-certbot-nginx
After this is done, you can then run the certbot command to install the certificate on your domain:
$ sudo certbot --nginx
Certbot should automatically detect your domain configuration, setup the certificate and update your NGINX configuration to support HTTPS. It should also setup a schedule job to renew the certificate when needed. You can view the schedule job by typing the following command:
$ sudo systemctl list-timers
You should be able to see the certbot.timer in the list.
MySQL
Ghost officially support MySQL 5.x. You can get MySQL 8 working with Ghost but will need to change the authentication plugin. This is not really a Ghost issue, but an issue with NodeJS MySQL driver.
Check to make sure you have the correct MySQL version available through your package manager, and then install with the following command:
$ sudo apt install mysql-server
After this is done, you can then run the secure installation script to complete the installation:
$ sudo mysql_secure_installation
Depends on your configuration/installation, you may find that you are unable to login to MySQL as root UNLESS you use sudo or login as root in this session already. This is because MySQL may be using auth_socket plugin for root user. You can fix this by typing the following command:
$ sudo mysql -u root
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
After that, you should be able to login as MySQL root from normal user
NodeJS
Before you can install Ghost, you will need to install NodeJS first. You can use the following command to install NodeJS 10.x:
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
$ sudo apt-get install -y nodejs
Ghost
Finally, we can install Ghost by execute the following command:
$ sudo npm install ghost-cli@latest -g
Before you execute the ghost command, please create a directory where you will host your ghost installation first. I will suggest a place like: /var/www/<domain>/ghost. Please also make sure you do not run the ghost command as root. After you created the directory, execute the following command in that directory:
$ ghost install
You will need to answer few questions. Few points to note:
- If you input MySQL root username/password, it will automatically create ghost Database and a new user to access the database. It will not use the MySQL root user to access the DB.
- I will recommend you answer "no" on both NGINX and SSL setup as you already complete those setup in previous steps.
- I will recommend you use systemd to keep ghost up and running. Alternatively you can also use other process manager like pm2, but that will require manual setup
After ghost CLI complete the installation, you can then setup NGINX. Open your domain configuration and add the following:
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
client_max_body_size 50m;
Restart/Reload NGINX and you are done. You can now go to https://<domain>/ghost and follow the instruction to setup ghost configuration.