##Vagrant and Environment setup
Under VirtualBox platform packages, install the package for your OS
-
download the latest version of vagrant at http://downloads.vagrantup.com/ and install it.
-
After installation, run the following command in your terminal to make sure it installed properly.
vagrant --version
-
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.
-
Create a new Rails app ( I created a test app)
$ rails new setup_vagrant $ cd setup_vagrant
-
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"
-
Boot up the VM
$ vagrant up
you should now have a VM running Ubuntu (NOTE: vagrant runs the VM w/out a UI)
-
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
-
First ensure all installed software is up to date
$ sudo apt-get update`
-
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
-
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)
-
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
-
Install bundler
$ sudo gem install bundle
###Get your Rails app running
-
cd into your rails app
$ cd /vagrant
-
Go into your Gemfile and un-comment out the gem
therubyracer -
Run bundle
$ sudo bundle install
-
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
-
Exit out of the vagrant shell
$ exit $ vagrant reload
-
run your rails app
$ rails server
-
Then in your browser go to localhost:3000, and your app should be running! BOOM!
###Installing Postgresql (the way that worked for me)
-
Install postgres
$ sudo apt-get install postgresql postgresql-contrib libpq-dev $ sudo -u postgres createuser --superuser $USER
-
Change the postgres user password
$ sudo -u postgres psql postgres $ \password postgres
-
type the password of your choosing
-
type control D to exit out of that shell
-
Fix locale settings( this will open the nano text editor)
$ sudo nano /etc/bash.bashrc
-
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
-
Save it
press the fn key + F3
-
Close and exit nano
press the fn key + F2
-
Set the locale settings
$ sudo locale-gen en_US.UTF-8 $ sudo dpkg-reconfigure locales
-
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
-
Include the pg gem in your Gemfile and run:
$ sudo bundle
-
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
-
Install Apache
$ sudo apt-get install apache2 -y $ sudo apt-get install libapache2-mod-proxy-html libxml2-dev -y
-
Add modules to allow Apache to proxy requests to the Unicorn Server
$ sudo a2enmod proxy
$ a2enmod proxy_balancer
$ a2enmod proxy_http
$ a2enmod rewrite
-
Restart Apache server
$ sudo /etc/init.dapache2 restart
-
Make sure you include the pg gem in your gem file and run:
$ sudo bundle
-
Open up the nano text-editor to create to virtual host:
$ sudo nano /etc/apache2/sites-available/domain.com
-
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
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
ErrorLog /home/demo/public_html/railsapp/log/error.log CustomLog /home/demo/public_html/railsapp/log/access.log combined
-
Save it
press the fn key + F3
-
Close and exit nano text editor
press the fn key + F2
-
Enable the ghost:
$ sudo a2ensite domain.com
-
Restart the Apache server
$ sudo /etc/init.dapache2 reload
-
Update your Vagrantfile
config.vm.network :forwarded_port, guest: 8080, host: 8080
-
Exit out of the vagrant shell and reload
$ exit
$ vagrant reload
-
Log back in
$ vagrant ssh $ cd /vagrant
-
Run the unicorn server
$ unicorn
-
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