Custom permalinks in Ghost

Standard

Ghost by default only lets you have dated permalink <code class="highlighter-rouge">:year/:month/:day/:slug or title <code class="highlighter-rouge">:title based with is set by default.

You can change this by editing the Sqlite Database and updating the the permalink column, this will let you have custom url for your posts, this will only affect urls of your posts and not pages.

Backup the Database before making any changes to it.

You need stop Ghost, than access the Database using Sqlite CLI.

“`
sqlite3 content/data/ghost.db
“`

In development mode the Database will be `ghost-dev.db`.

```
sqlite3 content/data/ghost-dev.db
```

Use the query below.

```
UPDATE settings SET value = ‘/journal/:slug/` WHERE key = 'permalinks'
```

Now your permalink will be `http://example.com/journal/welcome-to-ghost/`, you can set journal to anything you like.

After this step you can start Ghost.

If you visit the settings panel in your Ghost admin, you will see. that the dated permalink has been tick(turned on), this is because Ghost believes that you are using dated permalinks.

If you want to revert back, you can tick the dated permalink under settings panel in Ghost admin, this will set the url back to the default <code class="highlighter-rouge">:slug, you can re tick the dated permalink and enable the actual dated permalink.

Happy Blogging.

Have a question? leave a comment below.

Ghost on Ubuntu

Standard

Ghost is a free open source blogging platform built with Node.js. It started as a Kickstarter project and turned into a great blogging platform that is still under active development.

It can be self hosted or you can choose a hosted built at Ghost.org.

It uses Sqlite by default as it’s Database, you use MySQL to.

Its easy to setup and maintain Ghost compared to other blogging platforms and CMS, self hosting gives you the freedom to choose your own server.

If you don’t already have a server or planning to host it on a Ubuntu VPS, I would personally recommend Digital Ocean, Ghost.org is also hosted on it.

Getting started

Installing dependencies required for running Ghost into production.

Installing Node.js

Adding the Node.js repository to get the latest stable version of Node.js (requires: cURL).

“`
curl -sL https://deb.nodesource.com/setup | sudo bash –
“`

Installing Node.js

“`
sudo apt-get install nodejs # NPM comes with it.
“`

Adding [NGINX](http://nginx.org) stable repository to get latest version of NGINX.

“`
sudo apt add-repository ppa:nginx/stable
“`

Installing NGINX.

“`
sudo apt-get update && sudo apt-get install nginx-full
“`

Installing Sqlite.

“`
sudo apt-get install sqlite3
“`

Installing Supervisor, for handling Ghost at startup and crash or restart.

“`
sudo apt-get install supervisor
“`

Downloading [Ghost stable](https://ghost.org/zip/ghost-latest.zip) zip.

“`
wget https://ghost.org/zip/ghost-latest.zip
“`

cURL users can get it to.

“`
curl -# -L -O http://ghost.org/zip/ghost-latest.zip
“`

Unzipping Ghost zip file that we downloaded.

“`
unzip ghost-latest.zip -d Ghost
“`

Turn `Ghost` directory into current directory.

```
cd Ghost/
```

Installing production dependencies for Ghost using NPM.

```
npm install --production
```

Test run to see, to see if everything is running fine:

```
npm start --production
```

If you don’t get any errors, you are good to go ahead.

Adding Ghost service configuration to Supervisor, by creating a new <code class="highlighter-rouge">ghost.conf file.

```
sudo nano /etc/supervisor/conf.d/ghost.conf
```

Add the lines below, edited it to match you system settings, you can it under a separate user for Ghost, **don’t run it under the root user**.

```
[program:ghost]
command = npm start --production
directory = /path/to/ghost # Change to the place you have stored Ghost
user = ghost # Change the username Ghost will be running under
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/ghost.log
stderr_logfile = /var/log/supervisor/ghost_err.log
environment = NODE_ENV="production"
```

Save file CTRL + X + Y and hit ENTER.

Ghost stores all it’s configuration in a <code class="highlighter-rouge">config.js file, which need to be created by coping the <code class="highlighter-rouge">config.example.js file to <code class="highlighter-rouge">config.js.

```
cp config.example.js config.js
```

Edit the file to your preference, don’t forget to edit the `url:` string to your domain.

Starting Ghost as a Supervisor service.

```
sudo supervisorctl start ghost
```

Now Ghost will be running on port 2368.

Reverse proxying it using NGINX to run it on port 80.

Edit the <code class="highlighter-rouge">default nginx configuration.

```
sudo nano /etc/nginx/sites-enabled/default
```

Add the following to the `default` file.

```
server {
listen 80;
server_name yourdomain.com; # Change this to your domain

    location / {
    proxy_pass       http://127.0.0.1:2368;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
    }

}

</div>Restart NGINX.

<div class="highlighter-rouge">```
sudo service nginx restart  

Visit your domain, you will now be greeted by Ghost setup page, fill the required information, now you have Ghost setup.

Happy Blogging.

Thanks for reading, have a question? leave a comment below.

Static site generators

Standard

Static sites are the fast, secure and easy to create and manage, it is also the fastest in load up time.

It’s the best way to serve content, if all you want to serve is static.

Its can handle higher traffic because it does not require any pre-processing.

Its also one of the oldest ways of creating websites, before pre-processors existed, people wrote website, pages and web content manually, but you really don’t have to, these days there are static site generator, which let you use pre-processors to build static content in a much easier and hassle free way, it also makes managing content easier and some of the static site generators can completely be a replacement to a CMS.

A lot of bloggers go with a static site generator, mainly because hosting a static site is cheaper and sometimes free, there are hosting options like GitHub Pages, Netlifty and many others.

The best place you can use a static site generator when you need to serve content that is not updated regularly or dynamic, it good for a blog, if you prefer writing in files instead of using a front-end interface that uses a Database to store content.

Usage of client sided scripting languages like JavaScript can make you static site serve dynamic content, you can getting commenting services like Disqus to have comment in a static site.

The most popular static site generator is Jekyll, it’s written in Ruby, but if you want more flexibility you can use Metalsmith. I have used both and recommend Jekyll for beginners, due to well-written documentation, community support, and user-friendly design.

Static sites are secure because they don’t have to communicate Database, so hacking and SQL Injection kinds of attack don’t work on them.

Have a question? Leave a comment below.