Difference between revisions of "Temp"
| Line 54: | Line 54: | ||
====Install Rails secrets==== | ====Install Rails secrets==== | ||
Rails also needs a unique secret key with which to encrypt its sessions. Starting from Rails 4, this secret key is stored in config/secrets.yml. But first, we need to generate a secret key. Run: | Rails also needs a unique secret key with which to encrypt its sessions. Starting from Rails 4, this secret key is stored in config/secrets.yml. But first, we need to generate a secret key. Run: | ||
| + | cd ~/DMPonline_v4 | ||
bundle exec rake secret | bundle exec rake secret | ||
This command will output a secret key. Copy that value to your clipboard. Next, open config/secrets.yml: | This command will output a secret key. Copy that value to your clipboard. Next, open config/secrets.yml: | ||
| + | cd ~/DMPonline_v4 | ||
nano config/secrets.yml | nano config/secrets.yml | ||
If the file already exists, look for this: | If the file already exists, look for this: | ||
Revision as of 11:11, 4 July 2016
Contents
- 1 Introduction
- 2 Installation
- 2.1 Step 1 - Install Ubuntu server
- 2.2 Step 2 - Install web app framework on the server
- 2.3 Step 3 - Get the DMP code
- 2.4 Step 7 - Compile assets and test the web app
- 2.5 Step 4 - Configure database connections
- 2.6 Step 5 - GEM dependency configuration
- 2.7 Step 7 - Prepare the MySQL databases
- 2.8 Step 8 - Deploy the web app using "passenger"
- 2.9 Step 8 - Prepare the Apache web server
- 2.10 Step 9 - Start the web app
- 3 References
Introduction
This wiki page details the installation and use of the DCC RDMP software (RDMP = Research Data Management Plan) on an Ubuntu 14.04 LTS server with the "RubyonRails" web development framework installed.
Installation
Step 1 - Install Ubuntu server
Install an Ubuntu 14.04 LTS server as per:
http://ubuntu.sun.ac.za/wiki/index.php/Enterprise_Server_Management
Use "tasksel" and install the "LAMP server" and the "OpenSSH server". See screenshot below.
- When asked for a password for the MySQL server, type in a VERY SECRET password and do not forget it!
- When asked for the user account details, use "dmponline" as the installed user name.!
See: http://tecadmin.net/install-lamp-quickly-using-tasksel-on-ubuntu-and-linuxmint/ for reference.
Step 2 - Install web app framework on the server
Install the prerequisites
Login to the server and then type the following;
sudo apt-get install git mysql-server mysql-client libmysqlclient-dev git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev libgdbm-dev libncurses5-dev automake libtool bison libffi-dev gnupg2 libgmp-dev
Install RubyonRails
Install Ruby as a normal user as follows;
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \curl -L https://get.rvm.io | bash -s stable --ruby echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
Logout and login again, then check the installed Ruby version;
ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
Install required "gems";
gem install bundler
Install the "rails" framework;
gem install rails --version=3.2.22
Check version;
rails -v
Rails 3.2.22
Install Nodejs
Type the following;
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs
Check version;
nodejs -v
v4.4.6
Step 3 - Get the DMP code
Type the following;
git clone https://github.com/DigitalCurationCentre/DMPonline_v4.git
Step 7 - Compile assets and test the web app
Install Rails secrets
Rails also needs a unique secret key with which to encrypt its sessions. Starting from Rails 4, this secret key is stored in config/secrets.yml. But first, we need to generate a secret key. Run:
cd ~/DMPonline_v4 bundle exec rake secret
This command will output a secret key. Copy that value to your clipboard. Next, open config/secrets.yml:
cd ~/DMPonline_v4 nano config/secrets.yml
If the file already exists, look for this:
secret_key_base: <%=ENV["SECRET_KEY_BASE"]%>
Then replace it with the following. If the file didn't already exist, simply insert the following.
secret_key_base: the value that you copied from 'rake secret'
- Sample File
development: admin_name: Dev Admin admin_email: XXXXXXX admin_password: XXXXXX secret_key_base: XXXXX test: admin_name: Test User admin_email: XXXXXX admin_password: XXXXXXX secret_key_base: XXXXXX production: admin_name: Prod User admin_email: XXXXXXX admin_password: XXXXXXX secret_key_base: XXXXXX
Step 4 - Configure database connections
Configure database access by typing the following;
cd ~/DMPonline_v4 nano config/database.yml
Copy and paste the following;
# MySQL. Versions 4.1 and 5.0 are recommended. # # Install the MYSQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # http://dev.mysql.com/doc/refman/5.0/en/old-client.html development: adapter: mysql encoding: utf8 reconnect: false database: dmponline_development pool: 5 username: root password: %PASSWORD% socket: /var/run/mysqld/mysqld.sock # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: mysql encoding: utf8 reconnect: false database: dmponline_test pool: 5 username: root password: %PASSWORD% socket: /var/run/mysqld/mysqld.sock production: adapter: mysql encoding: utf8 reconnect: false database: dmponline_production pool: 5 username: root password: %PASSWORD% socket: /var/run/mysqld/mysqld.sock
Replace %PASSWORD% with the "root" password for your MySQL database.
Step 5 - GEM dependency configuration
Type the following;
cd ~/DMPonline_v4 nano Gemfile
Delete everything and then copy and paste the following;
source 'https://rubygems.org' # # RAILS # gem 'rails', '3.2.22' gem 'uglifier' gem 'less-rails' gem 'twitter-bootstrap-rails' gem 'sass-rails', '~> 3.2.3' gem 'sass' gem 'therubyracer', '0.11.4', platforms: :ruby gem 'libv8' # To use debugger gem 'ledermann-rails-settings' gem 'jbuilder' #to notify admin of errors gem 'exception_notification' #to allow cloning of objects gem 'amoeba' # Gems used only for assets and not required in production environments by default. group :assets do gem 'coffee-rails', '~> 3.2.1' end group :development do gem "better_errors" gem "binding_of_caller" end # # USERS # # devise for user authentication gem 'devise' gem 'devise_invitable' gem 'omniauth' gem 'omniauth-shibboleth' #rolify for roles gem 'rolify' # Gems for repository integration gem 'email_validator' gem 'validate_url' # # DATABASE/SERVER # gem 'mysql' # Use unicorn as the app server # gem 'unicorn' #cancan for usergroups gem 'cancan' # # VIEWS # gem 'jquery-rails' gem 'tinymce-rails' gem 'friendly_id' gem 'contact_us' gem 'recaptcha' #implementation of forms gem 'activeadmin', '1.0.0.pre1' # # EXPORTING PLANS # gem 'thin' gem 'wicked_pdf' gem 'htmltoword' gem 'feedjira' # WORD DOC EXPORTING gem 'caracal', '~> 1.0' gem 'caracal-rails', '~> 1.0' gem 'passenger'
Step 7 - Prepare the MySQL databases
Type the following;
cd ~/DMPonline_v4 rails dbconsole
This will connect you to the database. If successful then continue, otherwise check the database config above.
Type the following to create the databases;
For "development";
rake db:setup RAILS_ENV="development" rake db:migrate RAILS_ENV="development"
For "test";
rake db:setup RAILS_ENV="test" rake db:migrate RAILS_ENV="test"
For "production";
rake db:setup RAILS_ENV="production" rake db:migrate RAILS_ENV="production"
If there is an error and you need to drop the database to try again, then type one or all of the following;
rake db:reset RAILS_ENV="production" rake db:reset RAILS_ENV="development" rake db:reset RAILS_ENV="test"
PLEASE NOTE:
There is an error with creating an admin user. Type the following to bypass this error;
nano ~/DMPonline_v4/db/migrate/20130708092900_devise_create_admin_users.rb
Comment out the following line;
AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password') if direction == :up
In addition there are CSS errors.
Type the following to fix them;
/home/dmponline/DMPonline_v4/app/assets/stylesheets/admin.css.less
Comment out the second line.
Another CSS error.
Type the following;
nano /home/dmponline/DMPonline_v4/app/assets/stylesheets/bootstrap_and_overrides.css.less
Comment out the second line.
Step 8 - Deploy the web app using "passenger"
Install the dependencies
Type the following;
cd ~/DMPonline_v4 bundle install --deployment --without development test
Compile assets
Run the following command to compile assets for the Rails asset pipeline:
bundle exec rake assets:precompile
Test the installation
Type the following;
rvmsudo rails s -p 80
Follow the on screen instructions.
Install Passenger
Type the following;
passenger-install-apache2-module
At the end of the installation process, you will be asked to copy and paste a configuration snippet (containing LoadModule, PassengerRoot, etc.) into your Apache configuration file.
Type the following;
sudo nano /etc/apache2/sites-enabled/000-default.conf
Add the following;
LoadModule passenger_module /home/dmponline/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.29/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/dmponline/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.29
PassengerDefaultRuby /home/dmponline/.rvm/gems/ruby-2.3.0/wrappers/ruby
</IfModule>
Restart the web server;
sudo service apache2 restart
Step 8 - Prepare the Apache web server
Update the Apache web server config file as follows;
sudo nano /etc/apache2/sites-enabled/000-default.conf
Uncomment the "ServerName" and type the following;
ServerName rdmp.bib.sun.ac.za
Add the following as the "DocumentRoot";
/home/dmponline/DMPonline_v4/public
Add the <Directory> parameters as shown in the example below.
Example Apache web config
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName rdmp.bib.sun.ac.za
ServerAdmin webmaster@localhost
DocumentRoot /home/dmponline/DMPonline_v4/public
LoadModule passenger_module /home/dmponline/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.29/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/dmponline/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.29
PassengerDefaultRuby /home/dmponline/.rvm/gems/ruby-2.3.0/wrappers/ruby
</IfModule>
<Directory /home/dmponline/DMPonline_v4/public>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Step 9 - Start the web app
Restart the Apache web server;
sudo service apache2 restart
Type the following to check the passenger installation;
rvmsudo passenger-config validate-install
If everything looks good then go to:
http://rdmp.bib.sun.ac.za
Type the following to check the memory;
rvmsudo passenger-memory-stats
References
Source Code
Installation
- http://railsapps.github.io/installrubyonrails-ubuntu.html
- https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/apache/oss/rubygems_rvm/install_passenger.html
- https://gorails.com/setup/ubuntu/14.04
- https://en.wikipedia.org/wiki/Capistrano_(software)
