Skip to content

Setup Papyrus in Production

Taras Danylak edited this page Dec 11, 2013 · 12 revisions

Prerequisites

In order to setup papyrus on a production server, first you must install Ruby, Rails and Apache/Passenger. Check out this guide if your system is CentOS or similar (Fedora, RedHat). You can extrapolate how to setup the prerequisites on your chosen distribution from read those instructions as well.

Prerequisites:

  1. Ruby 1.9.3
  2. Apache/Passenger
  3. MySQL (the guide link above)
  4. Rails and MySQL2 gems installed without errors.

Setup the database

Before you begin, you have to setup the database to be used with Papyrus. MySQL is the default and this guide will be for this database.

$ mysql -u root -p 'enter-your-password'
mysql> create database 'papyrus_production';
Query OK, 1 row affected (0.00 sec)

By convention, Papyrus default config expects the database to be called papyrus_production. You, of course, can name it whatever you like. Papyrus also expects the database user to be 'papyrus', with default, not recommended password being the same as the user.

mysql> grant all privileges on papyrus_production.* to papyrus@localhost identified by 'new-password-here';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)
mysql> exit

Cloning Papyrus and Configuration Setup

The choice of where you setup Papyrus is yours, however, when using Apache/Passenger and deploying to a subdirectory (i.e. your-website.com/papyrus/), the Papyrus directory must be hidden from Apache and the public directory inside Papyrus must be sym-linked inside the DocumentRoot folder.

For the purpose of this guide, the following shall be assumed:

DocumentRoot /var/www/html
PapyrusRoot /var/www/papyrus

First you should clone the latest version of Papyrus from GitHub.

$ cd /var/www
$ git clone https://github.com/yorkulcs/papyrus.git

Once you've cloned the repository, you can begin the setup process. Go into that directory to begin the setup process.

$ cd papyrus/
$ bundle install --deployment --quiet --without development test

If bundle install is successful, you can continue with the setup process by running the rake task.

$ rake app:setup

=====================================================
  Setting up default configuration files 
=====================================================

Creating: database.yml
cp /var/www/papyrus/config/database.yml.default /var/www/papyrus/config/database.yml
Creating: papyrus_app_config.rb
cp /var/www/papyrus/config/papyrus_app_config.rb.default /var/www/papyrus/config/papyrus_app_config.rb

=====================================================
  Follow the following steps to complete the installation.
======================================================

1) Create Your Database & User (If not done already)
2) Modify config/database.yml to match your database settings
3) Run: rake db:migrate
4) Modify config/papyrus_app_config.rb 
5) Run: rake app:setup_admin_user
6) To test installation, Run: rails s
7) Visit http://locahost:3000/login

======================================================

Now that you can performed the basic setup, you have a few more things left to do before setting up apache. First, you will see a set of instructions to follow after running rake app:setup.

Since you have created the database user already, go to step two and modify the database.yml file with your chosen database name, username and password. Note: do this under the production setting.

$ vi config/database.yml

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: papyrus_production
  pool: 5
  username: mysqluser <- change this
  password: mysqlpassword <- change this
  socket: /var/lib/mysql/mysql.sock

After you've modified this file, run the migrations in production mode.

$ RAILS_ENV=production rake db:migrate
==  CreateItems: migrating ====================================================
-- create_table(:items)
....

If you see a bunch of migrating statements, you're setup is going very well. Continue to the next step.

Step 4 is about modifying your papyrus_app_config.rb file, to change the name of your installation, email address for notifications and bibliographic record search settings. You don't have to do this right now, but before you go live, you should make sure everything is setup as you require it.

$ vi config/papyrus_app_config.rb
.. make your changes ..

Now the last step before setting up Apache configuration is creating the default admin user. Run the following command and follow the onscreen instructions.

$ RAILS_ENV=production rake app:setup_admin_user

=====================================================
  Setting up admin user
=====================================================

Admin Full Name?
Your Full Name
Admin Email?
papyrus-admin@your-website.com
Admin Username?
administrator

=====================================================
  Finished setting up admin user.
=====================================================

Answer the questions and the rake task will create a default admin user for you. The username should be the one you will use to login either via AuthBasic, or CAS, or whatever authentication module you use. See configuration options for more help.

Now that the user is setup you can move on to configuring Apache Passenger.

Setup Apache/Passenger to Use Papyrus.

This section assumes you have setup Passenger already, so it will have the configuration options to setup Papyrus in a subdirectory of your domain.

Assumption: Apache configuration is stored in /etc/httpd/conf.d and DocumentRoot is /var/www/html

Create a configuration file for your Papyrus instance inside the Apache configuration directory.

$ touch /etc/httpd/conf.d/webapp-papyrus.conf
$ vi /etc/httpd/conf.d/webapp-papyrus.conf

Paste the following configuration setup for Papyrus.

Alias /papyrus /var/www/papyrus/public

RailsBaseURI /papyrus
<Directory /var/www/papyrus>
	Order allow,deny
	Allow from all
	AllowOverride All
</Directory>

 # Basic Auth Example config
 <Location /papyrus/login>

 	AuthType basic
        AuthName "Papyrus"
        AuthBasicProvider dbm
        AuthDBMType SDBM
        AuthDBMUserFile /etc/papyrus_passwd        
        Require valid-user
 </Location>

This configuration file tells Apache that Papyrus is located in the /var/www/papyrus directory. It also says it should expose Papyrus's public directory to the world and allow Passenger to access Papyrus app directory.

The Basic Auth config example is protecting the login section of Papyrus which is responsible for authenticating users. If you will use this method, you will have to generate the passwords file and make sure that authentication.cas_header_name is equal to REMOTE_USER

You can run the following command to create the username and password for Basic Auth. This approach is not recommended. You should be using something like CAS or LDAP for authentication and user management.

$ htdbm -TSDBM -c /etc/papyrus_passwd administrator [ CENTOS ]

$ dbmmanage /etc/papyrus_passwd adduser administrator [ OTHER ]

Sym Link Papyrus to Document Root

After you've setup the configuration, you have to sym link Papyrus's public directory to the DocumentRoot. This will allow Apache to serve static css and javascript files, rather then letting Rails do it. Passenger requires this sym link for apps deployed as subdirectories

$ ln -s /var/www/papyrus/public /var/www/html/papyrus

Test the configuration by running apachectl command:

$ apachectl -t
Syntax Ok
$ apachectl restart

Final Step

Before you go to checkout your new Papyrus installation, you have precomile the assets. This step is done last because it depends on the location of Papyrus you have set in the Apache config. In this guides it's /papyrus, but you may have it different.

$ cd /var/www/papyrus
$ bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets RAILS_RELATIVE_URL_ROOT=\"/papyrus\" assets:precompile

This will precomile assets, compressing javascript and css and copying them to the public directory of Papyrus app. These files will be served directly by Apache so it will reduce load times significantly.

Grand Finale

Go to http:://your-website.com/papyrus and you should get an HTTP Basic Auth Popup, fill in your username and password and click ok.

Clone this wiki locally