Install apache web server and passenger on Ubuntu 11.04(Natty)

I just Installed apache and passenger on Ubuntu 11.04 to run and deploy my ruby on rails applications Passenger is a gem and can work with apache as well as nginx…

The reason for choosing apache is that its an industry standard.

Also one thing I did with apache was created virtual hosts and ran my apps on local machine with domains like http://www.application1.com

In this post I will list the steps I followed in order to setup apache web server and passenger.

Here is my stack:

  •  Ubuntu 11.04
  •  ruby 1.9.2 via rvm
  •  rubygems 1.8.10

I will be using rails 3.1.10(lastest this morning).!!

So lets start !!

  • Install rvm

To install rvm just type the following in the terminal(ctrl+alt+t)

 user$ bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )

You can find more information about rvm on Here

  • Install ruby via rvm

Once rvm is installed you can install the latest or desired version of ruby by typing the following in terminal

rvm install 1.9.2

This will install ruby 1.9.2 on your system.

More information on how to make it your default ruby is available on here

  • Install rails.

just need to do

gem install rails

  • Install passenger

just do

gem install passenger

  • Install apache web server.

To install apache web server type:

sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
  • Install passenger apache module.

Once this is done, we must install passenger , an apache module thats hepls us to rub rails apps on apache.

sudo passenger-install-apache2-module
  • Configure.

Finally everything is done.

When you run the passenger apache module, there would be some instructions that installer will give you.

The last thing it will tell is to paste some text in apache configuration file

The configuration file is located at /etc/apache2/apache2.conf

Now once this is done, we are ready to deploy.

This has a lot of information about deploying.

In my next post, I will show how to start rails apps on local machine with apache.

Hope it helps.!

Creating virtual hosts in apache in local machine

In this post I show how to create virtual hosts on apache and run multiple rails apps on your local machine with names like

rails_app1.com

rails_app2.com

In the previous post I had shown how to deploy rails apps on local machine with apache web server

My software stack:

  • Ubuntu 11.04
  • ruby 1.9.2 p290.
  • Rails 3.1.10
  • rubygems 1.8.10

Lets start!

First we have to enable virtual aliases on the Apache S

sudo a2enmod vhost_alias

Now I assume that the rails app is at the location:

/home/username/Desktop/rails_apps/my_rails_app

 

We first create a virtual configuration file:

Tyep the following in terminal:

sudo gedit /etc/apache2/sites-available/mydomain

Copy the following settings to your file:

 

<VirtualHost *:80>
ServerAdmin webmaster@domain.com
ServerName my_rails_app.com
ServerAlias http://www.my_rails_app.com

DocumentRoot /home/username/Desktop/rails_apps/my_rails_app/public
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory //home/username/Desktop/rails_apps/my_rails_app/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<Directory “/usr/lib/cgi-bin”>

AllowOverride None

Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

Order allow,deny

Allow from all

</Directory>

 

ErrorLog ${APACHE_LOG_DIR}/error.log

 

# Possible values include: debug, info, notice, warn, error, crit,

# alert, emerg.

LogLevel warn

 

CustomLog ${APACHE_LOG_DIR}/access.log combined

 

Alias /doc/ “/usr/share/doc/”

<Directory “/usr/share/doc/”>

Options Indexes MultiViews FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

Allow from 127.0.0.0/255.0.0.0 ::1/128

</Directory>

</VirtualHost>

Important to note here is to change ServerName as per your convinince and Directory to your public of rails app.

Once this is done,

type the following to open the hosts file:

 sudo gedit /etc/hosts

 

In this file, copy the following code:

 

127.0.0.1 domain-name.com
www.domain-name.com

 

replace domain name with your desired name.

This is what you will use in browser to access the page

Activate your domain and reload the Apache Server to enable settings
Enable the site

a2ensite domain-name

 

Reload Apache2

/etc/init.d/apache2 reload

 

Finally test your app by typing www.domain-name.com and see the magic !!!

 

 

Deploying rails app with apache locally

In this post I am going to show how to make apache the server for all ruby on rails application on local machine.

In the previous post I had shown how to install apache web server ad configure it.

My software stack:

  • Ubuntu 11.04
  • ruby 1.9.2 p290.
  • Rails 3.1.10
  • rubygems 1.8.10

Lets start!

I assume that you have a rails app in the following path:

/home/username/Desktop/rails_apps/my_rails_app

It is important to note that apache serves all local request via www directory in /var.

/var/www

So the first step is to create a symbolic link:

ln -s /home/username/Desktop/rails_apps/my_rails_app/public /var/www/my_rails_app

Note that sym link should be to your appls publc folder.

Now edit the following file(you can coly paste the code)

sudo gedit /etc/apache2/sites-available/default

In this file, append the follwing line:

RailsBaseURI /my_rails_app
RailsEnv development #(if you want to run on development mode default is production)

Restart apache using

sudo /etc/init.d/apache2 restart

 Now on you browser when you type 127.0.1.1/my_rails_app
 the app should fire up !

Hurray you have done it !

————————————–warning for ruby 1.9.2p290————————————————

When I fired up my app, I got an error

Can’t convert nil to hash,

This is phsyc problem and to solve this, add the following to boot.rb

(this issue existed when I did used it )

require ‘yaml’

YAML::ENGINE.yamler = ‘syck’

Install apache web server and passenger on Ubuntu 11.04(Natty)

I just Installed apache and passenger on Ubuntu 11.04 to run and deploy my ruby on rails applications Passenger is a gem and can work with apache as well as nginx…

The reason for choosing apache is that its an industry standard.

Also one thing I did with apache was created virtual hosts and ran my apps on local machine with domains like http://www.application1.com

In this post I will list the steps I followed in order to setup apache web server and passenger.

Here is my stack:

  •  Ubuntu 11.04
  •  ruby 1.9.2 via rvm
  •  rubygems 1.8.10

I will be using rails 3.1.10(lastest this morning).!!

So lets start !!

  • Install rvm

To install rvm just type the following in the terminal(ctrl+alt+t)

 user$ bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )

You can find more information about rvm on Here

  • Install ruby via rvm

Once rvm is installed you can install the latest or desired version of ruby by typing the following in terminal

rvm install 1.9.2

This will install ruby 1.9.2 on your system.

More information on how to make it your default ruby is available on here

  • Install rails.

just need to do

gem install rails

  • Install passenger

just do

gem install passenger

  • Install apache web server.

To install apache web server type:

sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
  • Install passenger apache module.

Once this is done, we must install passenger , an apache module thats hepls us to rub rails apps on apache.

sudo passenger-install-apache2-module
  • Configure.

Finally everything is done.

When you run the passenger apache module, there would be some instructions that installer will give you.

The last thing it will tell is to paste some text in apache configuration file

The configuration file is located at /etc/apache2/apache2.conf

Now once this is done, we are ready to deploy.

This has a lot of information about deploying.

In my next post, I will show how to start rails apps on local machine with apache.

Hope it helps.!