Introduction:
Ghost is a blogging platform which run on nodejs. I have tested this in a Ubuntu-12.04 64bit- 128mb/128mb openvz vps. Ghost requires Node.js 0.10.x (latest stable). Recommended Node.js 0.10.30 & npm 1.4.21.
Objective:
We will install nodejs, npm, lighttpd, mariadb for ghost blog. Lighttpd is for reverse proxy for ghost blog and it is really light enough to run smoothly on small vps boxes. Mariadb for saving posts as it is better than Mysql in some cases and also optimized for good performance. A benchmark of Mysql vs Mariadb. We will also install sendmail for ghost blog to act as a fully functional blog.
Installation Procedure:
1st Step: Nodejs – Npm
Let us install nodejs and npm as ghost blog build to run on this. We need repository to install latest versions.
First install curl and nano to download and edit files and also unzip to extract files.
1 |
apt-get install curl nano unzip |
Then let’s use curl to get repository. This command will add repository and will let us to download/install latest nodejs.
1 |
curl -sL https://deb.nodesource.com/setup | sudo bash - |
After running above command we can now install nodejs.
1 |
apt-get install nodejs |
Check the versions.
1 2 |
npm -v node -v |
2nd Step: Lighttpd and Mariadb
Install the repo manager to use “add-apt-repository” command.
1 |
sudo apt-get install python-software-properties |
Import the GnuPG signing key
1 |
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db |
Add repository.
1 |
sudo add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu precise main' |
Update Source and install:
1 2 3 |
apt-get update apt-get install mariadb-server apt-get install lighttpd |
Now create a database.( It will ask you for root database password.)
1 2 3 |
mysql -u root -p create database ghost; exit; |
3rd Step: Ghost
Let we will install ghost in a domain “domain.com”, so we will create folder.
1 |
mkdir -p /var/www/domain_com |
Now enter into that folder.
1 |
cd /var/www/domain_com |
Now we will download the zip file by which we will install ghost. (Latest) in this folder.
1 |
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip |
Now let’s extract the zip file into a directory.
1 |
unzip -uo ghost.zip -d ghost |
Above unzip command will extract ghost blog to a folder “ghost”, enter ghost directory.
1 |
cd ghost |
Now have to run below code as we will run our blog in production mode. This command will get the dependencies.
1 |
npm install --production |
We have to configure config file by our choice. Let’s replicate the sample config file to config.js-
1 |
cp config.example.js config.js |
Now edit that config file by our need.
1 |
nano config.js |
Find // ### Production. This is the start of Production based configuration. Also find // Developers only need to edit below here and above this line end of Production based configuration. You can just delete all from that and paste below codes which is good enough with sendmail and database.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
// ### Production // When running Ghost in the wild, use the production environment // Configure your URL and mail settings here production: { url: 'http://my-ghost-blog.com', mail: { transport: 'SMTP', options: { service: 'Sendmail', } }, database: { client: 'mysql', connection: { host: '127.0.0.1', user: 'root', password: 'password', database: 'database', charset: 'utf8' } }, server: { // Host to be passed to node's `net.Server#listen()` host: '127.0.0.1', // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT` port: '2368' } }, |
Change that domain with yours and change database section like above with the latest created database and add the server/vps ip in 127.0.0.1 and save it. In database connection do not use localhost, use 127.0.0.1 instead.
Now let’s test the ghost and nodejs server.
1 |
npm start --production |
the oputput should be something like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
…………………….. > node index Migrations: Database initialisation required for version 003 Migrations: Creating tables... Migrations: Creating table: posts Migrations: Creating table: users Migrations: Creating table: roles Migrations: Creating table: roles_users Migrations: Creating table: permissions Migrations: Creating table: permissions_users Migrations: Creating table: permissions_roles Migrations: Creating table: permissions_apps Migrations: Creating table: settings Migrations: Creating table: tags Migrations: Creating table: posts_tags Migrations: Creating table: apps Migrations: Creating table: app_settings Migrations: Creating table: app_fields Migrations: Creating table: clients Migrations: Creating table: accesstokens Migrations: Creating table: refreshtokens Migrations: Populating fixtures Migrations: Populating permissions Migrations: Creating owner Migrations: Populating default settings Migrations: Complete Ghost is running... Your blog is now available on http://domain.com |
So it is running but we will not be able to browse by that domain yet. We have to use http://domain.com:2368 as ghost or nodejs run by ports and we installed ghost in 2368 port.
4th Step: Start Script
Create a blank file as ghost.conf in /etc/init/ folder.
1 |
touch /etc/init/ghost.conf |
Edit that file by nano and put below code.
1 |
nano /etc/init/ghost.conf |
1 2 3 4 5 6 7 |
# ghost start on startup script cd /var/www/domain_com/ghost npm start --production end script |
Change the location And save that file. Now you can start and stop the service by simply running below command.
1 |
service ghost start |
1 |
service ghost status |
1 |
service ghost restart |
1 |
service ghost stop |
This will also act as an auto start configuration file when reboot the server.
5th Step: Lighttpd and Virtualhost
Edit /etc/lighttpd/lighttpd.conf and pur below codes in the bottom of that config file. But remember to change the ip and domain name and directory name.
1 2 3 4 5 6 7 8 |
$HTTP["host"] =~ "(^|\.)domain.com$" { server.document-root = "/var/www/domain_com/" cache.enable = "enable" proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => 2368 ) ) ) } |
Save the file and run below command-
1 |
lighttpd-enable-mod proxy |
Then restart lighttpd server. Above command for enabling proxy feature of lighttpd server.
1 |
service lighttpd restart |
Now you can access your blog by the domain name only.
Final Step:
Make sure you restarted the service accurately.
1 2 |
service ghost restart service lighttpd restart |
Now you will be able to register and use your very fast blogging platform. 🙂
Conclusion: We have installed successfully our beloved ghost blog with sendmail function and mariadb+lighttpd. This box is 128mb openvz and it’s running smoothly.
I have also tested the server by Apache Benchmark. It just doesn’t bother. 🙂
You can tweak mysql/mariadb and lighttpd to give it a fast reaction capability. A good optimised lighttpd+mysql will give you a breeze with ghost blog and your small vps. You can find some interesting post in this site about how to tweak mysql for better traffic handling.
Happy Blogging !
22 comments for “Install Ghost Blog With Lighttpd and Mariadb”