Skip to content

Instantly share code, notes, and snippets.

@garciadanny
Last active December 18, 2015 09:39
Show Gist options
  • Select an option

  • Save garciadanny/5762445 to your computer and use it in GitHub Desktop.

Select an option

Save garciadanny/5762445 to your computer and use it in GitHub Desktop.

##Vagrant and Environment setup

  1. Go to https://www.virtualbox.org/wiki/Downloads

Under VirtualBox platform packages, install the package for your OS

  1. download the latest version of vagrant at http://downloads.vagrantup.com/ and install it.

  2. After installation, run the following command in your terminal to make sure it installed properly.

    vagrant --version

  3. Go to http://www.vagrantbox.es/

    A) Add a vagrant box. Example: vagrant box add [whatever_title] [url] $ vagrant box add ubuntu_lucid_32 http://files.vagrantup.com/lucid32.box

You can name the title what you'd like, the url is included under the URL column on the vagrant box site.

  1. Create a new Rails app ( I created a test app)

    $ rails new setup_vagrant $ cd setup_vagrant

  2. Create a VM that is specific for running your rails app and it's dependencies

    $ vagrant init {name_you_gave_your_vagrant_box} Example: vagrant init lucid32

This should have created a Vagrantfile in the root directory of your project and there should be an un-commented configuration that set's up your vagrant box.

Example: config.vm.box = "name_you_gave_your_vagrant_box"
  1. Boot up the VM

    $ vagrant up

you should now have a VM running Ubuntu (NOTE: vagrant runs the VM w/out a UI)

  1. Now you can ssh into your VM

    $ vagrant ssh

BOOM!!! You're now running a Ubuntu in a VM.

###Installing RVM, Ruby 2.0, and Rails 3.2.13

  1. First ensure all installed software is up to date

    $ sudo apt-get update`

  2. Now install zlib, git, and sqlite3, and curl

    $ sudo apt-get install build-essentail zlib1g-dev git-core sqlite3 libsqlite3-dev $ sudo apt-get install curl

  3. Install RVM (multi-user install), Ruby 2.0 , and Rails 3.2.13 all in one line!

    $ sudo bash -s stable --rails < <(curl -L https://get.rvm.io)

  4. Start using RVM and add users to the RVM group

    $ source /etc/profile.d/rvm.sh $ rvm user all

  • Test your Ruby/Rails versions:

    $ ruby -v #=> ruby 2.0.0p195 (2013-05-14 revision 40734) [i686-linux] $ rails -v #=> Rails 3.2.13

  1. Install bundler

    $ sudo gem install bundle

###Get your Rails app running

  1. cd into your rails app

    $ cd /vagrant

  2. Go into your Gemfile and un-comment out the gem therubyracer

  3. Run bundle

    $ sudo bundle install

  4. Add forward_port configuration to your Vagrantfile so that when you run your rails app, you can access it in your browser:

    $ config.vm.network :forwarded_port, guest: 3000, host: 3000

  5. Exit out of the vagrant shell

    $ exit $ vagrant reload

  6. run your rails app

    $ rails server

  7. Then in your browser go to localhost:3000, and your app should be running! BOOM!

###Installing Postgresql (the way that worked for me)

  1. Install postgres

    $ sudo apt-get install postgresql postgresql-contrib libpq-dev $ sudo -u postgres createuser --superuser $USER

  2. Change the postgres user password

    $ sudo -u postgres psql postgres $ \password postgres

  3. type the password of your choosing

  4. type control D to exit out of that shell

  5. Fix locale settings( this will open the nano text editor)

    $ sudo nano /etc/bash.bashrc

  6. Add these lines to the bottom of the file (copy and past these):

    export LANGUAGE=en_US.UTF-8 export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8

  7. Save it

    press the fn key + F3

  8. Close and exit nano

    press the fn key + F2

  9. Set the locale settings

    $ sudo locale-gen en_US.UTF-8 $ sudo dpkg-reconfigure locales

  10. Disconnect from your VM then re-connect

    $ ctrl + D

    $ vagrant ssh

    $ sudo pg_createcluster 8.4 main --start

    $ sudo su

    $ sudo -u postgres psql -l

  11. Include the pg gem in your Gemfile and run:

    $ sudo bundle

  12. Now you should be able to do the following successfully:

  • configure your config/database.yml file to run postgres in development and production

  • generate a migration

  • run the migration

BOOM!!!

Resources that helped me install postgres:

https://gist.github.com/jschoolcraft/1963369

https://help.ubuntu.com/community/PostgreSQL

http://xtremekforever.blogspot.com/2011/05/setup-rails-project-with-postgresql-on.html

###Unicorn

  1. Install Apache

    $ sudo apt-get install apache2 -y $ sudo apt-get install libapache2-mod-proxy-html libxml2-dev -y

  2. Add modules to allow Apache to proxy requests to the Unicorn Server

    $ sudo a2enmod proxy

    $ a2enmod proxy_balancer

    $ a2enmod proxy_http

    $ a2enmod rewrite

  3. Restart Apache server

    $ sudo /etc/init.dapache2 restart

  4. Make sure you include the pg gem in your gem file and run:

    $ sudo bundle

  5. Open up the nano text-editor to create to virtual host:

    $ sudo nano /etc/apache2/sites-available/domain.com

  6. Add this to the file:

    <VirtualHost *:80> ServerName domain.com ServerAlias www.domain.com

    DocumentRoot /home/vagrant(ssh)/THE_NAME_OF_YOUR_RAILS_APP_GOES_HERE/

    RewriteEngine On

    <Proxy balancer://unicornservers> BalancerMember http://127.0.0.1:8080

    Redirect all non-static requests to thin

    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]

    ProxyPass / balancer://unicornservers/ ProxyPassReverse / balancer://unicornservers/ ProxyPreserveHost on

    <Proxy *> Order deny,allow Allow from all

    Custom log file locations

    ErrorLog /home/demo/public_html/railsapp/log/error.log CustomLog /home/demo/public_html/railsapp/log/access.log combined

  7. Save it

    press the fn key + F3

  8. Close and exit nano text editor

    press the fn key + F2

  9. Enable the ghost:

    $ sudo a2ensite domain.com

  10. Restart the Apache server

    $ sudo /etc/init.dapache2 reload

  11. Update your Vagrantfile

    config.vm.network :forwarded_port, guest: 8080, host: 8080

  12. Exit out of the vagrant shell and reload

    $ exit

    $ vagrant reload

  13. Log back in

    $ vagrant ssh $ cd /vagrant

  14. Run the unicorn server

    $ unicorn

  15. Go to your browser

    localhost:8080

BOOM!!!

Resources to get Unicorn working:

http://www.varyonic.com/2012/03/apache-unicorn-ssl/#.UbfUK_b71Tshttps://github.com/	

google: teambox/teambox/wiki/Installing-on-Ubuntu-using-Apache-and-Unicorn

http://articles.slicehost.com/2008/5/6/ubuntu-hardy-apache-rails-and-thin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment