• Get In Touch
May 17, 2017

How to Install Publify on Ubuntu 14.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Publify is a free full featured web publishing software built on Ruby on Rails framework. Publify comes with lots of features including classic multi user blogging engine, custom themes, twitter connection, advanced SEO capabilities, support for multiple languages, text filters and much more.

In this tutorial, we will see how to install Publify on Ubuntu 14.04 server with Nginx.

Requirements

  • A server running Ubuntu 14.04.
  • A not-root user with sudo privileges configure on your server.

Update the System

Before installing any packages, it is recommended to update your system with the latest stable version. You can do this with the following command:

sudo apt-get update -y
sudo apt-get upgrade -y

Once your system is up to date, you can proceed to install Apache web server.

Install Required Packages

Before starting, you will need to install Nginx and other required packages on your system. By default Nginx latest version is not available in Ubuntu default repository, so you will need to add the Nginx repo first.

First, install required packages with the following command:

sudo apt-get install software-properties-common imagemagick build-essential git openssl nano

Then, add the Nginx repository wiith the following command:

sudo add-apt-repository ppa:nginx/stable

Next, update the system with the following command:

sudo apt-get update -y

Finally, install Nginx with the following command:

sudo apt-get install nginx -y

Next, start the Nginx servcie and enable it to start on boot with the following command:

sudo /etc/init.d/nginx start
sudo update-rc.d nginx defaults

Install and Configure MariaDB

By default, latest version of MariaDb is not available in Ubuntu, so you will need to add MariaDb repository first.

You can do this with the following command:

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db

sudo add-apt-repository 'deb [arch=amd64,i386] http://mirrors.accretive-networks.net/mariadb/repo/10.1/ubuntu trusty main'

Next, update the system with the following command:

sudo apt-get update -y

Next, install MariaDb server with the following command:

sudo apt-get install mariadb-server libmariadbclient-dev

Default MariaDB instalaltion is not secured, so you will need to secure it.

You can do this by running mysql_secure_installation script:

sudo mysql_secure_installation

Answer all the questions as shown below:

Set root password? [Y/n] n
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

Once MariaDB is secured, log in to the MariaDB shell and create a database for Publify:

mysql -u root -p

Enter your root password when prompted, then create a database for Publify. It is recommended to set a secure password:

MariaDB [(none)]> CREATE DATABASE publifydb CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)

Next, create a username and password for Publify with the following command:

MariaDB [(none)]>CREATE USER 'publify'@'localhost' IDENTIFIED BY 'password';
Query OK, 1 row affected (0.00 sec)

Next, grant privileges to the Publify database with the following command:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON publifydb.* TO 'publify'@'localhost' IDENTIFIED BY 'password';
Query OK, 1 row affected (0.00 sec)

Next, you will need to run the FLUSH PRIVILEGES command so that the privileges table will be reloaded by MySQL and we can use new credential:

mysql>FLUSH PRIVILEGES;
Query OK, 1 row affected (0.00 sec)

Next, exit from the MariaDB console with the following command:

Install Ruby

You can install the latest version of the Ruby with the following curl command:

curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -sSL https://get.rvm.io | bash -s stable --ruby
rvm install ruby-2.1.5

Once Ruby is installed, start it using RVM with the following command:

source ~/.rvm/scripts/rvm

You can verify the version of the Ruby with the following command:

ruby --version

Onc eyou have done, you can proceed to install Publify.

Install Publify

You can download the latest version of the Publify from Git repository using git clone command:

git clone https://github.com/publify/publify.git

Next, rename the sample database.yml file with the following command:

cp ~/publify/config/database.yml.mysql ~/publify/config/database.yml

Next, open database.yml file and make some changes inside it:

sudo nano ~/publify/config/database.yml

Change the following lines:

production:
login: &login
  adapter: mysql2
  host: localhost
  username: publify
  password: password

Next, you will need to create a new puma config file:

nano ~/publify/config/puma.rb

Add the following lines:

#!/usr/bin/env puma

application_path = '/home/hitesh/publify'
directory application_path
environment 'production'
daemonize true
pidfile "#{application_path}/tmp/pids/puma.pid"
state_path "#{application_path}/tmp/pids/puma.state"
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
bind "unix://#{application_path}/tmp/sockets/publify.sock"

Save and close the file when you are finished.

Next, create a directory for pid, log and socket:

mkdir -p ~/publify/tmp/{pids,log,sockets}

Next, install gems with the following command:

cd ~/publify

echo "gem 'puma'" >> Gemfile

echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
RAILS_ENV=production bundle install --without development test postgresql sqlite

Next, prepare the database and compile the assets wit the following command:

RAILS_ENV=production rake db:setup
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake db:seed
RAILS_ENV=production rake assets:precompile

Once you have done, create an upstart script with the following command:

sudo nano /etc/init/publify.conf

Add the following lines:

description "Puma Publify Service"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

setuid hitesh
setgid hitesh

respawn
respawn limit 3 30

script
exec /bin/bash << EOT
source /home/hitesh/.rvm/scripts/rvm
cd /home/hitesh/publify
exec puma -C config/puma.rb
EOT
end script

Save and close the file when you are finished then start your Publify service with the following command:

sudo service publify start

Configure Nginx

Next, you will need to create a virtual host file for Publify.
You can do this with the following command:

sudo nano /etc/nginx/sites-available/publify.conf

Add the following lines:

upstream publify {
  server unix:/home/hitesh/publify/tmp/sockets/publify.sock;
}

server {
  server_name yourdomain.com;
  root /home/hitesh/publify;

  location / {
    try_files $uri @ruby;
  }

  location @ruby {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  Host $http_host;
    proxy_redirect off;
    proxy_read_timeout 300;
    proxy_pass http://publify;
  }
}

Save and close the file when you are finished, the activate the server block by creating a symbolic link:

sudo ln -s /etc/nginx/sites-available/publify.conf /etc/nginx/sites-enabled/

Finally, restart Nginx service with the following command:

sudo service nginx restart

Access Publify

Once everything is configured, open your web browser and type the URL http://yourdomain.com and complete required steps to finish the Publify installation.

Thats it.

Congratulatiopns! you have successfully installed Publify on your Ubuntu 14.04 server.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]