These instructions assume the existence of a dedicated non-root user account for deployment and the possession of a signed SSL certificate.
The production environment has been tested using the following software/versions.
-
Ubuntu Server 12.04.3 LTS i386
-
RVM 1.23.10
-
Ruby 2.0.0
-
Rails 4.0.0.rc2
-
MySQL 5.5.32
-
Phusion Passenger 4.0.20
-
NGINX 1.4.2
Ruby Version Manager (RVM) allows multiple versions of the Ruby interpreter to be installed and executed concurrently on a single server. To install RVM and Ruby execute:
sudo apt-get install curl \curl -L https://get.rvm.io | bash -s stable source ~/.rvm/scripts/rvm rvm requirements rvm install ruby-2.0.0 rvm ruby-2.0.0 --default rvm default
MySQL server is used for the production database. To install and configure MySQL server execute:
sudo apt-get install libmysqlclient-dev mysql-server (when prompted, enter a strong password for the MySQL root user) mysql -u root -p (enter the MySQL root password at the prompt) grant ALL ON things_to_apples.* TO 'things_to_apples'@'localhost' IDENTIFIED BY 'SecureDatabasePassword'; exit
The application requires the NodeJS Javascript runtime. To install NodeJS execute:
sudo apt-get install nodejs
The application is stored in a Git repository. To install Git & clone the repository execute:
sudo apt-get install git cd InstallationDirectory (select a secure installation directory) git clone https:// github.com/jzamanski/things-to-apples.git (without the space after 'https://')
The application’s Ruby dependencies are managed by Bundler. To install the application dependencies execute:
cd things-to-apples bundle install --without development test (repeat if any OpenSSL errors occur)
The MySQL database password and the secret key used by the application are not stored in source control and must be supplied in the file ‘.env’. The MySQL password is the same password provided above in the ‘grant’ MySQL command. The secret key is generated using rake. To set the database password and the secret key execute:
echo "MYSQL_PW: SecureDatabasePassword" >> .env printf "SECRET_KEY: %b\\n" $(rake secret) >> .env
The MySQL database must be initialized beore the application is started. To load the database schema execute:
rake db:setup RAILS_ENV=production
Assets must be precompiled to static assets. To precompile static assets execute:
rake assets:precompile RAILS_ENV=production
The NGINX reverse proxy server is used in production. To install and configure NGINX (and it’s dependencies) execute:
sudo apt-get install libcurl4-gnutls-dev rvmsudo passenger-install-nginx-module (select default options)
NGINX must be configured to serve the application. To configure NGINX execute:
sudo nano /opt/nginx/conf/nginx.conf
-
add the following two server blocks within the http block
server { listen 80; server_name ''; return 301 https://zam.pcanywhere.net:443$request_uri; } server { listen 443; server_name ''; root /home/jeff/things-to-apples/public; passenger_enabled on; ssl on; ssl_certificate /absolute/path/to/server.crt; ssl_certificate_key /absolute/path/to/server.key; }
NGINX must be started to server the application. To install start/stop scripts and start NGINX execute:
sudo wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh sudo mv init-deb.sh /etc/init.d/nginx sudo chmod +x /etc/init.d/nginx sudo service nginx start (it can be stopped or reload the configuration by passing 'stop' or 'reload' instead of 'start')
A daemon is required to automatically timeout requests when users do not respond. To start the daemon execute:
RAILS_ENV=production bin/delayed_job start (it can be stopped by passing 'stop' instead of 'start')