Menu

Rails Installation on production server

August 21, 2014 - Rails

Steps to Create and Secure Server

Refer document “Firewall and SSH”

Steps to Configure Application

 

  1. login  using putty or ssh  user@ip
  2. sudo apt-get upgrade
  3. sudo apt-get update
  4. sudo aptitude install language-pack-en-base
  5. sudo aptitude upgrade
  6. sudo aptitude install mysql-server
    1. It will prompt for password and repeat passwordc
  7. Test mysql by coonecting it- mysql -u root -p
    1. It will prompt for password (give password and hit enter)
    2. run show databases; command to list current databases
    3. exit mysql console by typing exit
  8. Secure mysql – sudo /usr/bin/mysql_secure_installation
    1. It will prompt for password
    2. Give answers as Y/N
  9. Install apache using – sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
  10. After installation is complete, Browser should respond to http://50.56.204.146 with “It Works!!” page
  11. If there is error “apache2: Could not reliably determine the server’s fully qualified domain nam” follow http://aslamnajeebdeen.com/blog/how-to-fix-apache-could-not-reliably-determine-the-servers-fully-qualified-domain-name-using-127011-for-servername-error-on-ubuntu
  12. Assign server ‘fully quanlifed name’
    1. sudo nano /etc/apache2/apache2.conf
    2. Add ServerName company.org at last line of file
    3. Restart server using sudo apache2ctl graceful
  13. Install PHP5 using – sudo aptitude install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd

    php5-imagick php5-mcrypt php5-memcache php5-mhash php5-mysql php5-pspell php5-snmp

    php5-sqlite php5-xmlrpc php5-xsl
  14. run sudo /etc/init.d/apache2 reload
  15. Install phpmyadmin – sudo apt-get install phpmyadmin
    1. Choose apache using spacebar
    2. Provide password of root account of mysql
    3. Give “No” to popup
    4. http://www.company.org/phpmyadmin should work
  16. Install curl – sudo apt-get install curl

 

    1. Test curl – curl –version

 

  1. Install Git – sudo apt-get install git-core
    1. Test Git – git –version
  2. Install RVM – bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
  3. edit .bashrc using nano .bashrc and add following line at end of file – if [[ -s “$HOME/.rvm/scripts/rvm” ]] ; then source “$HOME/.rvm/scripts/rvm” ; fi
  4. Might need to remove “ from above in case you are getting error “RVM is not a function, selecting rubies with ‘rvm use …’ will not work.”
  5. sudo reboot
    1. login again and test evm using rvm notes
    2. Use rvm requirements to find out required libraries (see below step)
  6. Install required libraries using apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
  7. install ruby – rvm install 1.9.2
    1. Start using ruby – rvm 1.9.2
    2. Check version – ruby -v
  8. Create gemset rvm gemset create company
  9. Make it default using rvm 1.9.2@company –default
  10. Install application dependendencies
    1. apt-get install libmysqlclient-dev
    2. apt-get install imageMagick
    3. http://blog.structuralartistry.com/post/2327213260/installing-wkhtmltopdf-on-ubuntu-server and https://github.com/mileszs/wicked_pdf/issues/53
      1. apt-get remove wkhtmltopdf
      2. gem uninstall wkhtmltopdf
      3. gem uninstall wkhtmltopdf
      4. Go to usr/local/bin – cd /usr/local/bin
      5. sudo curl -C – -O http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
      6. sudo tar -xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
      7. sudo ln -s /usr/local/bin/wkhtmltopdf-amd64 /usr/bin/wkhtmltopdf
      8. Restart apache – sudo /etc/init.d/apache2 restart
  11. Install gems needed for application
    1. gems install rails (specify the version to install specific rails) and Test rails – rails -v
    2. Install mysql gem – gem install mysql
    3. gem install passenger
    4. passenger-install-apache2-module and Follow the steps of the above command till the process is complete. Keep doing this step until everything is ok. Below are sample commands
      1. sudo apt-get install libcurl4-openssl-dev
      2. sudo apt-get install apache2-prefork-dev
      3. passenger-install-apache2-module
      4. Note down the instruction (mainly path name) for editing Apache configuration file> these are three lines starting with words – LoadModule, PassengerRoot and PassengerRuby
      5. Create the following two directories in /etc/apache2/mods-available – “sudo nano /etc/apache2/mods-available/passenger.load”  and add this line noted in point iv above – LoadModule passenger_module /home/user/.rvm/gems/ruby-1.9.2-p320@user/gems/passenger-3.0.12/ext/apache2/mod_passenger.so
      6. “sudo nano /etc/apache2/mods-available/passenger.conf” and add these lines PassengerRoot /home/user/.rvm/gems/ruby-1.9.2-p320@user/gems/passenger-3.0.12 and PassengerRuby /home/user/.rvm/wrappers/ruby-1.9.2-p320@user/ruby
      7. Enable the modules by creating the following symbolic links in /etc/apache2/mods-enabled – sudo ln -s /etc/apache2/mods-available/passenger.load /etc/apache2/mods-enabled/passenger.load and sudo ln -s /etc/apache2/mods-available/passenger.conf /etc/apache2/mods-enabled/passenger.conf
      8. Restart apache – sudo /etc/init.d/apache2 restart
  12. Setup Git – http://help.github.com/linux-set-up-git
    1. Login to remote cloud server ssh user@some_ip
    2. sudo apt-get install xclip
    3. mkdir ~/.ssh
    4. chmod 700 ~/.ssh
    5. ssh-keygen -t rsa -C “your_email@youremail.com
    6. Keep on accepting defaults and don’t give passphrase
    7. xclip -sel clip < ~/.ssh/id_rsa.pub
    8. On the GitHub site Click “Account Settings” > Click “SSH Keys” > Click “Add SSH key”
    9. Copy this key on Key field and give some title
    10. run ssh-add
    11. Test it from remote server – ssh -T git@github.com
    12. You should get message like – “Hi punchouty! You’ve successfully authenticated, but GitHub does not provide shell access.”
  13. Deploy Application
    1. Login to phpmysqladmin in server
    2. Create database name ‘qa-enoch’ using http://ip_address/phpmysqladmin
    3. Create folder in home directory of user mkdir workspace and cd workspace
    4. Get code – git clone git@github.com:punchouty/enoch.git
    5. Rename enoch to support multiple “enoch” projects on same hosts-  mv enoch enoch-qa
    6. Edit enoch-qa/config/database.yml and change database setting for production
    7. Go to base directory (/home/user/worspace/user) and run bundle install
    8. rake assets:clean
    9. rake assets:precompile
    10. rake db:migrate RAILS_ENV=”production”
    11. rake db:seed RAILS_ENV=”production”
    12. sudo /etc/init.d/apache2 restart
  14. Setup Apache Local
  15. Setup Apache Remote – http://www.rackspace.com/knowledge_center/index.php/Ubuntu_-_Apache_Virtual_Hosts
    1. cd ~
    2. mkdir public_html
    3. mkdir -p public_html/company.org/{public,private,log,cgi-bin,backup}
    4. Create index.html in public_html/company.org/public
    5. sudo nano /etc/apache2/sites-available/company.org and add lines written at end of this page
    6. sudo a2dissite default – remove default site
    7. service apache2 reload – reload apache
    8. rake assets:clean
    9. rake assets:precompile
    10. rake db:drop RAILS_ENV=”production”
    11. rake db:create RAILS_ENV=”production”
    12. rake db:migrate RAILS_ENV=”production”
    13. rake db:seed RAILS_ENV=”production”
    14. sudo /etc/init.d/apache2 restart

 

<VirtualHost *:80>

# Admin email, Server Name (domain name) and any aliases
ServerAdmin abc@gmail.com
ServerName  company.org
ServerAliascompany.org

# Index file and Document Root (where the public files are located)
DirectoryIndex index.html
DocumentRoot /home/user/workspace/rails_app/public

# Custom log file locations
LogLevel warn
ErrorLog  /home/user/public_html/company.org/log/error.log
CustomLog /home/user/public_html/company.org/log/access.log combined

#To solve php problem add the following lines
<Location /phpmyadmin>

PassengerEnabled off

</Location>

</VirtualHost>

In case of any errors remember to explore the apache log which is found at the below location.

sudo cat /var/log/apache2/error.log

This will help in resolving the errros.

 

Leave a Reply