Server Setup - quattro004/scratches GitHub Wiki

Note: this is based on Ubuntu Server 12.10

Install Ubuntu Server

  • When installing Ubuntu select all of the defaults. When asked to enter a user use 'deploy' as this guide will assume that user name during configuration. When presented with the features to use select SSH and Mail Server. At some point I'd like to provide an unattended installation but that's down the road.

Configure Ubuntu Server

  • Login to the server, I typically use ssh from another computer but you can login to the terminal directly if desirable.
  • Ensure all of the packages are up to date: sudo apt-get update
  • Install Rmagick Prerequisites:
    1. sudo apt-get install imagemagick
    2. sudo apt-get install libmagickwand-dev
  • Install RVM \curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled Note: this installs Ruby and Rails as well.
  • Install NodeJS
    1. sudo apt-add-repository ppa:chris-lea/node.js
    2. sudo apt-get -y update
    3. sudo apt-get -y install nodejs
  • Install MySQL sudo apt-get install mysql-server mysql-client libmysqlclient-dev Follow the instructions presented.
    1. Update the my.cnf file to set max_allowed_packet = 1048576000
  • Add the deployment user to the mysql database by entering the following commands:
    1. mysql -u root -p Enter the root password when prompted.
    2. create user 'deploy'@'localhost' identified by 'pass'; Replace 'pass' with your password.
    3. GRANT ALL ON *.* TO 'deploy'@'localhost';
    4. FLUSH PRIVILEGES;
    5. exit
  • Install Phusion Passenger and nginx:
    1. sudo apt-get install software-properties-common
    2. sudo add-apt-repository ppa:brightbox/passenger-nginx
    3. gem install passenger
    4. rvmsudo passenger-install-nginx-module Follow the instructions presented, select the recommended option #1. Leave the default prefix directory [/opt/nginx].
  • Grab an init script from Linode’s website and install it. Necessary when installing from source.
  1. wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
  2. sudo mv init-deb.sh /etc/init.d/nginx
  3. sudo chmod +x /etc/init.d/nginx
  4. sudo /usr/sbin/update-rc.d -f nginx defaults
  • Once that’s done, you can start and stop nginx like so:
  1. sudo /etc/init.d/nginx stop
  2. sudo /etc/init.d/nginx start
  • Configure nginx:
    1. sudo nano /opt/nginx/conf/nginx.conf
    2. Change the commented out line that says '#user nobody;' to 'user deploy staff;'
    3. Uncomment the first error_log entry => error_log logs/error.log; if you wish to log errors, recommended.
    4. Replace the server section with the following:
      • Change server_name to use your IP (if configuring for a LAN) or your website name (website.com for example)
      • server {
              listen              80;
              server_name         recipieces.com;
              root                /home/deploy/scratches/public;
              passenger_enabled   on;
              rails_env           production;
              #access_log         logs/host.access.log  main;
        
      }
    5. Increase the default client_max_body_size 1000M; add that to the http section.
    6. Restart nginx
  • Git the code
    1. git clone git://github.com/quattro004/scratches.git
  • Update the config/database.yml file to include your production database settings, I remove the test and development settings. Also remove the cucumber information at the bottom.
    1. cd scratches
    2. nano config/database.yml
  • Run bundle install from the scratches directory to setup the application.
  • Edit recreate_database.sh for production:
    1. nano recreate_database.sh
      rake db:reset RAILS_ENV=production
      rake db:seed RAILS_ENV=production
    
  • Recreate the database with the shell script included with the application source:
    1. sh recreate_database.sh
  • Precompile application assets:
    1. bundle exec rake assets:precompile
  • Restart your application without restarting nginx at any time merely by creating a file named tmp/restart.txt:
    1. touch tmp/restart.txt
  • Setup complete you should now be able to browse to the application. Enjoy and remember 'ya ain't livin if you ain't eatin good!'.
    • Note: you have to signup to create the first user, I typically login to the server and update that user to be an admin via mysql.
⚠️ **GitHub.com Fallback** ⚠️