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.