×
Community Blog Create Your Blogging Website Using Ghost on Ubuntu 16.04

Create Your Blogging Website Using Ghost on Ubuntu 16.04

In this guide, we will install and configure Ghost on your Ubuntu 16.04 Alibaba Cloud ECS using Node.js.

By Sajid Qureshi, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Ghost is a free and open source blogging platform, designed to simplify the process of online publishing for individual bloggers as well as online publications. It is written in JavaScript and uses Node.js as its runtime environment. Ghost uses Markdown syntax in the editor, so you can see how your blog will look like on a live site while you are writing the blog. Ghost is perfect platform for bloggers as it is very clean and lightweight.

In this guide, we will install and configure Ghost on your ubuntu 16.04 Alibaba Cloud Elastic Compute Service (ECS) using Node.js.

Prerequisites

  1. You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get a free account in your Alibaba Cloud account. If you don't know about how to set up your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor.
  2. A non root user with sudo access.

Update the System

We recommend you to upgrade all the available packages before installing any new package. To do so, execute the following command.

sudo apt-get update

Install Nginx

Nginx is a web server that we are going to use for installing Ghost. First of all, you will need to install the Nginx server, execute the following command and it will do the job for you.

sudo apt-get install nginx

Next, you will need to start and enable nginx services to automatically start at boot time. Execute the following commands and they will do the job for you.

sudo systemctl start nginx.service && sudo systemctl enable nginx.service

You can test this Nginx installation through your web browser by visiting server domain name or IP address of your server. You should see a default test page of nginx.

Install MariaDB Database

MariaDB database server will be used to store your ghost data. You will need to install MariaDB server using the following command.

sudo apt-get install mariadb-server mariadb-client

Next, you will need to start and enable MariaDB service to always start up when the server boots. To do so, execute the following command.

sudo systemctl start mysql.service && sudo systemctl enable mysql.service

We recommend you to make sure this MariaDB installation is fully secured and to do so, execute the following command.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

-   Enter current password for root (enter for none): Just press the Enter
-   Set root password? [Y/n]: Y
-   New password: Enter password
-   Re-enter new password:  Repeat password
-   Remove anonymous users? [Y/n]:  Y
-   Disallow root login remotely? [Y/n]:  Y
-   Remove test database and access to it? [Y/n]: Y
-   Reload privilege tables now? [Y/n]: Y

Now you will have to create the database required to store the Ghost data. Login to MySQL shell using the following command and providing the required password when prompted.

mysql -u root -p

Now execute the following query to create a new database.

CREATE DATABASE ghost_data;

The above query will create a database named ghost_data. For the database, you can use any name you prefer in the place of ghost_data. Make sure that you use semicolon at the end of each query as a MySQL query always ends with a semicolon. Once the database is created you can create a new user and grant the required permissions to the user for the database.

CREATE USER 'ghost_user'@'localhost' IDENTIFIED BY 'StrongPassword';

The above query will create a user with username ghost_user. You can use any preferred username instead of ghost_user. Replace StrongPassword with a strong password.

Now provide the appropriate privileges to your database user over the database you have created. Run the following query to do so.

GRANT ALL PRIVILEGES ON ghost_data.* TO 'ghost_user'@'localhost';

Now run the following query to immediately apply the changes to the database privileges.

FLUSH PRIVILEGES;

Now you can exit from MySQL prompt using the following command.

exit

Install Node.js

As you know Ghost is based on node.js so, you will need to download and install node.js from its repository. Execute the following command to download node.js.

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

Once you have downloaded the node.js package, install it using the following command.

sudo apt-get install nodejs

Install Ghost

You have installed all the required dependencies to install Ghost. Now, you will need to create a new user to install Ghost. Execute the following command to create a user with a strong password.

sudo adduser ghuser

You can replace the ghuser with any other username of your choice.

Execute the following command to allow the user to run single commands with superuser privileges by using the sudo (superuser do) command.

sudo usermod -aG sudo ghuser

Now, login as the new user using the following command.

su - ghuser

Next, you will need to create a new Ghost root directory. Run the following command to do so.

sudo mkdir -p /var/www/html/ghost/

Next, you will need to change the ownership rules for your ghost user. To do so, execute the following commands.

sudo chown -R ghuser:ghuser /var/www/html/ghost
sudo chmod -R 755 /var/www/html/ghost

If in case you don't have npm already installed then you can install it using the following command.

sudo apt-get install npm

Now, change your current directory to ghost root directory and install Ghost. Execute the following commands and they will do the job for you.

cd /var/www/html/ghost
sudo npm i -g ghost-cli

Now, Install ghost using the following command.

ghost install

The above command will begin the Ghost installation. you will be asked to information about your site URL, database username, and other information.

You should see something similar to this.

ghuser@ubuntu1604:/var/www/html/ghost$ ghost install
? Checking system Node.js version
? Checking logged in user
? Checking current folder permissions
System checks failed with message: 'Linux version is not Ubuntu 16'
Some features of Ghost-CLI may not work without additional configuration.
For local installs, we recommend using `ghost install local` instead.
? Continue anyway? Yes
? Checking operating system compatibility [skipped]
? Checking for a MySQL installation
? Checking memory availability
? Checking for latest Ghost version
? Setting up install directory
? Downloading and installing Ghost v1.22.2
? Finishing install process
? Enter your blog URL: http://example.com:2368
? Enter your MySQL hostname: localhost
? Enter your MySQL username: ghostuser
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghost
? Configuring Ghost
? Setting up instance
Running sudo command: useradd --system --user-group ghost
Running sudo command: chown -R ghost:ghost /var/www/html/ghost/content
? Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? No
MySQL user is not "root", skipping additional user setup
? Setting up "ghost" mysql user [skipped]
? Do you wish to set up Nginx? No
? Setting up Nginx [skipped]
Task ssl depends on the 'nginx' stage, which was skipped.
? Setting up SSL [skipped]
? Do you wish to set up Systemd? Yes
? Creating systemd service file at /var/www/html/ghost/system/files/ghost_example-com.service
Running sudo command: ln -sf /var/www/html/ghost/system/files/ghost_example-com.service /lib/systemd/system/ghost_example-com.service
Running sudo command: systemctl daemon-reload
? Setting up Systemd
Running sudo command: /var/www/html/ghost/current/node_modules/.bin/knex-migrator-migrate --init --mgpath /var/www/html/ghost/current
? Running database migrations
? Do you want to start Ghost? Yes
Running sudo command: systemctl is-active ghost_example-com
? Ensuring user is not logged in as ghost user
? Checking if logged in user is directory owner
? Checking current folder permissions
Running sudo command: systemctl is-active ghost_example-com
? Validating config
? Checking folder permissions
? Checking file permissions
? Checking content folder ownership
? Checking memory availability
Running sudo command: systemctl start ghost_example-com
? Starting Ghost
Running sudo command: systemctl is-enabled ghost_example-com
Running sudo command: systemctl enable ghost_example-com --quiet
? Starting Ghost
You can access your blog at http://example.com:2368/

The ghost installation is finished now. You can access your site through a web browser.

Web Interface

By default Ghost runs on port 2368 so, you will need to type the port number after the URL to access. Open up your favorite web browser and visit http://example.com:2368. You should see a Ghost welcome page.

1

Setup Nginx As Proxy

As you know by default Ghost runs on port 2368 so you must always type the port number after the YourDomain name to access the Ghost. It makes it a little complicated. You can configure Nginx as a proxy server for Ghost to avoid this URL with the port number.

Create a ghost config file using any text editor like below.

sudo nano /etc/nginx/sites-available/ghost

Add the following content to the file.

server {
    listen 80;
    listen [::]:80;
    server_name YourDomainName;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:2368;
    }
}

Save the file and exit from the text editor.

Next, execute the following command to enable the site.

sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/

Finally, restart your nginx services using the following command.

sudo systemctl restart nginx

Now, you can access your ghost blogs by visiting http://YourDomain.com.

Conclusion

In this article, you have learned how to install and configure Ghost blogging platform on your Alibaba Cloud Elastic Compute Service (ECS) Ubuntu 16.04 server. We hope now you have enough knowledge to publish your blogs on Ghost.

0 0 0
Share on

Alibaba Clouder

2,599 posts | 764 followers

You may also like

Comments

Alibaba Clouder

2,599 posts | 764 followers

Related Products