Install Publify on Ubuntu 14.04

install-publify-on-an-ubuntu-14-04In this tutorial, we will explain how to install Publify on an Ubuntu 14.04 VPS with MariaDB, Puma and Nginx. Publify is a simple but full featured open source web publishing software. Publify is built on Ruby on Rails framework and it is the oldest Rails open source project alive. This guide should work on other Linux VPS systems as well but was tested and written for Ubuntu 14.04 VPS.

Login to your VPS via SSH

ssh user@vps

Update the system and install necessary packages

[user]# sudo apt-get update && sudo apt-get -y upgrade
[user]# sudo apt-get install software-properties-common imagemagick build-essential git openssl nano

Install MariaDB 10.1

[user]# sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
[user]# sudo add-apt-repository 'deb [arch=amd64,i386] http://mirrors.accretive-networks.net/mariadb/repo/10.1/ubuntu trusty main'
[user]# sudo apt-get update
[user]# sudo apt-get install mariadb-server libmariadbclient-dev

When the installation is complete, run the following command to secure your installation:

[user]# sudo mysql_secure_installation

Next, we need to create a database for our Publify installation:

[user]# mysql -uroot -p 
MariaDB [(none)]> CREATE DATABASE publify CHARACTER SET utf8; 
MariaDB [(none)]> GRANT ALL PRIVILEGES ON publify.* TO 'publify'@'localhost' IDENTIFIED BY 'publify_passwd'; 
MariaDB [(none)]> FLUSH PRIVILEGES; 
MariaDB [(none)]> \q

Publify user

Create a new system user for Publify.

[user]# sudo adduser --home /opt/publify --shell /bin/bash --gecos 'Publify publishing software' publify
[user]# sudo install -d -m 755 -o publify -g publify /opt/publify
[user]# sudo usermod -a -G sudo publify
[user]# sudo su - publify

Install Ruby using RVM

The following commands are run as publify user.

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

To start using RVM run the following command:

[publify]# source ~/.rvm/scripts/rvm

To verify everything is done correctly, use the command ruby --version.
The output should be similar to the following:

[publify]# ruby --version
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]

Install Publify

Clone the latest release of Publify from github using the following command:

[publify]# cd && git clone https://github.com/publify/publify.git
[publify]# git checkout v8.2.0

Copy database.yml.mysql as database.yml

[publify]# cp ~/publify/config/database.yml.mysql ~/publify/config/database.yml

Open the database.yml file and update username/password

[publify]# vim ~/publify/config/database.yml
production:
login: &login
  adapter: mysql2
  host: localhost
  username: publify
  password: publify_passwd

Create a new Puma configuration file.

[publify]# nano ~/publify/config/puma.rb
#!/usr/bin/env puma

application_path = '/opt/publify/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"
[publify]# mkdir -p ~/publify/tmp/{pids,log,sockets}

Install Gems

[publify]# cd ~/publify
[publify]# echo "gem 'puma'" >> Gemfile
[publify]# echo "gem: --no-ri --no-rdoc" >> ~/.gemrc 
[publify]# RAILS_ENV=production bundle install --without development test postgresql sqlite

Prepare the database and compile the assets

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
[publify]# RAILS_ENV=production rake db:setup
[publify]# RAILS_ENV=production rake db:migrate
[publify]# RAILS_ENV=production rake db:seed
[publify]# RAILS_ENV=production rake assets:precompile

Create an Upstart script

[publify]# sudo nano /etc/init/publify.conf
description "Puma Publify Service"
 
start on filesystem or runlevel [2345]
stop on runlevel [!2345]
 
setuid publify
setgid publify
 
respawn
respawn limit 3 30

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

You can now start your Publify service with :

[publify]# sudo service publify start

Install and Configure Nginx

The latest version of Nginx 1.8 is not available via the default Ubuntu repositories, so we will add the “nginx/stable” PPA, update the system and install the nginx package.

[user]$ sudo add-apt-repository ppa:nginx/stable
[user]$ sudo apt-get update
[user]$ sudo apt-get install nginx

Create a new Nginx server block with the following content

[publify]# sudo nano /etc/nginx/sites-available/publify.domain.com
upstream publify {
  server unix:/opt/publify/publify/tmp/sockets/publify.sock;
}

server {
  server_name publify.domain.com;
  root /opt/publify/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;
  }
}

Activate the server block by creating a symbolic link and restart Nginx:

[user]# sudo ln -s /etc/nginx/sites-available/publify.domain.com /etc/nginx/sites-enabled/publify.domain.com
[user]# sudo service nginx restart

That’s it. You have successfully installed Publify on your Ubuntu VPS. For more information about Publify, please refer to the Publify website.


Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Comment