Set up Jruby with apache and passenger in EC2
How to set up jruby with apache and passenger in amazone ec2.
Step 1: First install jruby using please check the current version in the link. And make sure you are installing the bin version of it
wget 'http://jruby.org.s3.amazonaws.com/downloads/1.7.4/jruby-bin-1.7.4.tar.gz'
Step 2: extract the tar file using
tar zxvf jruby-bin-1.7.4.tar.gz
Step 3:
We need to set come environment variable so that it will be accessible from every other place.
export JRUBY_HOME=/home/home_directory_name/jruby-1.7.4
export PATH=$JRUBY_HOME/bin:$PATH
And Open the .bashrc file and put the path in their
sudo nano ~/.bashrc
PATH=$PATH:/home/ubuntu/jruby-1.7.4/bin
Step 4:
Now to check if jruby is properly installed or not put
jruby-v
If your system does not have java installed then it will show an error like
/home/ubuntu/jruby-1.7.4/bin/jruby: line 395: exec: java: not found
Don't worry we will install java to fix this.
sudo apt-get install openjdk-7-jdk
apt-cache search jdk
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
export PATH=$PATH:/usr/lib/jvm/java-7-openjdk/bin
check the path before using export commands
now just put jruby-v it will show something like.
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK Client VM 1.7.0_25-b30 [linux-i386]
That means it's working now.
Step 5: install the jruby-openssl
jruby -S gem install jruby-openssl
jruby-openssl is necessary due jruby doesn’t support the default Ruby’s openssl. The parameter -S tells JRuby to use the scripts which are in JRuby’s bin directory, then in a second case to use the which ones in the system PATH.
Step 5: now install rails
jruby -S gem install rails
Thats it.. now we have set up jruby.
Now we need to install the apache, mysql and passenger
Step 6: First we will install apache2 using the following command.
sudo apt-get install apache2
Step 7: We need to install mysql now.
sudo apt-get update
sudo apt-get install mysql-server mysql-client
Step 8: Now we will install passenger gem using
gem install passenger.
Step 9: Now we need to install apache-passenger module
sudo apt-get install apache2-prefork-dev
sudo apt-get install libcurl4-openssl-dev
sudo passenger-install-apache2-module
Step 10:
Now after installing passenger-install-apache2-module we need to follow the instructions shown in the console like
In your apache confiiguration file put the lines like.
LoadModule passenger_module /home/ubuntu/jruby-1.7.4/lib/ruby/gems/shared/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
PassengerRoot /home/ubuntu/jruby-1.7.4/lib/ruby/gems/shared/gems/passenger-4.0.19
PassengerDefaultRuby /home/ubuntu/jruby-1.7.4/bin/jruby
and inside the sites-available and sites-enable put the
<VirtualHost *:80>
ServerName www.yourhost.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /somewhere/public
<Directory /somewhere/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
Suppose you have a Rails application in /somewhere. Add a virtual host to your Apache configuration file and set its DocumentRoot to /somewhere/public:
That's it just need to restart apache2 using sudo /etc/init.d/apache2 restart and we are done. :)
Step 1: First install jruby using please check the current version in the link. And make sure you are installing the bin version of it
wget 'http://jruby.org.s3.amazonaws.com/downloads/1.7.4/jruby-bin-1.7.4.tar.gz'
Step 2: extract the tar file using
tar zxvf jruby-bin-1.7.4.tar.gz
Step 3:
We need to set come environment variable so that it will be accessible from every other place.
export JRUBY_HOME=/home/home_directory_name/jruby-1.7.4
export PATH=$JRUBY_HOME/bin:$PATH
And Open the .bashrc file and put the path in their
sudo nano ~/.bashrc
PATH=$PATH:/home/ubuntu/jruby-1.7.4/bin
Now to check if jruby is properly installed or not put
jruby-v
If your system does not have java installed then it will show an error like
/home/ubuntu/jruby-1.7.4/bin/jruby: line 395: exec: java: not found
Don't worry we will install java to fix this.
sudo apt-get install openjdk-7-jdk
apt-cache search jdk
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
export PATH=$PATH:/usr/lib/jvm/java-7-openjdk/bin
check the path before using export commands
now just put jruby-v it will show something like.
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK Client VM 1.7.0_25-b30 [linux-i386]
That means it's working now.
Step 5: install the jruby-openssl
jruby -S gem install jruby-openssl
jruby-openssl is necessary due jruby doesn’t support the default Ruby’s openssl. The parameter -S tells JRuby to use the scripts which are in JRuby’s bin directory, then in a second case to use the which ones in the system PATH.
Step 5: now install rails
jruby -S gem install rails
Thats it.. now we have set up jruby.
Now we need to install the apache, mysql and passenger
Step 6: First we will install apache2 using the following command.
sudo apt-get install apache2
Step 7: We need to install mysql now.
sudo apt-get update
sudo apt-get install mysql-server mysql-client
Step 8: Now we will install passenger gem using
gem install passenger.
Step 9: Now we need to install apache-passenger module
sudo apt-get install apache2-prefork-dev
sudo apt-get install libcurl4-openssl-dev
sudo passenger-install-apache2-module
Step 10:
Now after installing passenger-install-apache2-module we need to follow the instructions shown in the console like
In your apache confiiguration file put the lines like.
LoadModule passenger_module /home/ubuntu/jruby-1.7.4/lib/ruby/gems/shared/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
PassengerRoot /home/ubuntu/jruby-1.7.4/lib/ruby/gems/shared/gems/passenger-4.0.19
PassengerDefaultRuby /home/ubuntu/jruby-1.7.4/bin/jruby
and inside the sites-available and sites-enable put the
<VirtualHost *:80>
ServerName www.yourhost.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /somewhere/public
<Directory /somewhere/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
Suppose you have a Rails application in /somewhere. Add a virtual host to your Apache configuration file and set its DocumentRoot to /somewhere/public:
That's it just need to restart apache2 using sudo /etc/init.d/apache2 restart and we are done. :)
Great work save my time.. :)
ReplyDeleteThanks Jhon
DeleteExcellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. Ruby on Rails Online Training
ReplyDelete