Rails production server
From LocalizationWiki
[edit]
How to setup rails production server
A. Setting up ruby on rails framework
1. aptitude install ruby1.8 2. aptitude install ruby1.8-dev build-essential 3. aptitude install ri 4. aptitude install rdoc 5. aptitude install rubygems 6. aptitude install rake 7. gem install rails --include-dependencies 8. gem install mongrel 9. gem install mongrel_cluster --include-dependencies
B. Installing imagemagick library
//Installed libmagick++9-dev to install rmagick in ubuntu 1. sudo aptitude install librmagick-ruby librmagick9-dev 2. gem install rmagick
Checking out ndlb code from svn
[edit]
=====================
cd /var/webapps/rails svn co https://ndlb.svn.sourceforge.net/svnroot/ndlb/portal/ror/tags/stable ndlb
C. Setting up and configuring mysql database server
1. aptitude install mysql-server-5.0
2. aptitude install libmysqlclient15-dev
3. gem install mysql
4. configuring mysql (i.e. editing /etc/mysql/my.cnf)
a. Under the [mysql] directive add the following line:
default-character-set = utf8
b. Under the [mysqld] directive add the following lines:
default-character-set = utf8
default-storage-engine = MyISAM
D. Installing and loading necessary modules in Apache web server
1. aptitude install apache2 2. a2enmod rewrite 3. a2enmod ssl 4. a2enmod deflate 5. a2enmod proxy 6. a2enmod proxy_balancer
E. Configuring mongrel/mongrel_cluster and apache to use proxy balancer
1. Say our rails project is in the path /var/webapps/rails/ndlb 2. Create a user 'mongrel' to run the to run the mongrel server for ndlb adduser mongrel 3. Make mongrel the user and group owner for all the files under /var/webapps/rails chown -R mongrel:mongrel /var/webapps/rails 4. Configure the mongrel_cluster mongrel_rails cluster::configure -e production -p 4000 -N 2 -c /var/webappsrails/ndlb -a 127.0.0.1 --user mongrel --group mongrel This creates the configuration file /var/webapps/rails/ndlb/config/mongrel_cluster.yml mkdir /etc/mongrel_cluster cd /etc/mongrel_cluster ln -s /var/webapps/rails/ndlb/config/mongrel_cluster.yml ndlb.yml ln -s /var/lib/gems/1.8/bin/mongrel_cluster_ctl /usr/bin/mongrel_cluster_ctl ln -s /var/lib/gems/1.8/bin/mongrel_rails /usr/bin/mongrel_rails cp /var/lib/gems/1.8/bin/mongrel_cluster_ctl /etc/init.d/mongrel_cluster chown mongrel:mongrel /etc/init.d/mongrel_cluster update-rc.d -f mongrel_cluster defaults->mongrel_cluster starts at startup or we can do /etc/init.d/mongrel_cluster start|stop etc
5. Configuring Apache: create file /etc/apache2/conf.d/ndlb.conf with the following content
Alias /ndlb/ /var/webapps/rails/ndlb/public/
<Directory "/var/webapps/rails/ndlb/public">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Proxy balancer://ndlb-cluster>
BalancerMember http://127.0.0.1:4000/ndlb
BalancerMember http://127.0.0.1:4001/ndlb
</Proxy>
ProxyPass /ndlb/images !
ProxyPass /ndlb/javascripts !
ProxyPass /ndlb/stylesheets !
ProxyPass /ndlb/texts !
ProxyPass /ndlb/movies !
ProxyPass /ndlb/flash !
ProxyPass /ndlb balancer://ndlb-cluster
ProxyPass /ndlb/ balancer://ndlb-cluster
ProxyPassReverse /ndlb/ balancer://ndlb-cluster
Edit the /etc/apache2/mods-enabled/proxy.conf and change the text between <proxy *> </Proxy> to the following.
<Proxy *> AddDefaultCharset off Order allow,deny Allow from all </Proxy>
F. Installing and configuring tomcat
1. Tomcat needs java. So we need to install a jdk/jre first. Many free implementation of java exists like kaffe but tomcat works best with the sun-java. In debian, sun-java is in the non-free section. So we need to add non-free to our sources.list. aptitude install sun-java5-jdk Then install tomcat: aptitude install tomcat5.5 tomcat5.5-admin tomcat5.5-webapps 2. Configure tomcat: cd /var/lib/tomcat5.5/webapps/conf/Catalina vim ndlb-texts.xml Now add the foling in the ndlb-texts.xml file
<Context path="/ndlb-texts" docBase="/var/webapps/ndlb-texts"
reloadable="true" crossContext="true">
</Context>
checking out ndlb-texts
[edit]
============
cd /var/webapps/ svn co https://ndlb.svn.sourceforge.net/svnroot/ndlb/portal/saxon/tags/stable ndlb-texts
3. Configure apache also for tomcat by adding the following just above the proxy_balancer directive in /etc/apache2/conf.d/ndlb.conf
ProxyPass /ndlb/texts http://127.0.0.1:8180/ndlb-texts ProxyPass /ndlb/texts/ http://127.0.0.1:8180/ndlb-texts ProxyPassReverse /ndlb/texts http://127.0.0.1:8180/ndlb-texts
4. /var/webapps/ndlb-texts is the folder in which the files to be served by tomcat is placed
Installing other gems required for NDLB
1. gem install flvtool2 flvtool2 is a tool used to manipulate and correct the flash movies created my mencoder.
2. Installing mencoder. The mencoder package is not in the official Debian repo for some reasons. So we have to install mencoder from debian-multimedia repo. add "deb http://www.debian-multimedia.org etch main" to /etc/apt/sources.list, run aptitude update and then aptitude install mencoder.
3. Installing rmovie rmovie is a Ruby extension that adds methods for accessing media files. It can return video frames as images that can be imported by RMagick. rmovie requires the latest ffmpeg. Since the Debian ffmpeg Package is old, we have to compile it from the latest source. We also need other packages like libavcodec0d, libavformat0d etc. - aptitude install libmagick9 libmagick9-dev - aptitude install libpostproc0d libpostproc-dev libpostproc0d-dev - aptitude install libavcodec0d libavcodec-dev - aptitude install libavformat0d libavformat-dev
Compiling ffmpeg ================ - download the latest ffmpeg source from http://ffmpeg.mplayerhq.hu/ - extract the tar.bz2 file : tar xjf ffmpeg-checkout-snapshot.tar.bz2 - go to the newly created folder : cd ffmpeg-checkout-2007-06-15 (the names of the folder will vary) - configure : ./configure --prefix=/usr/local --libdir=${prefix}/lib --shlibdir=${prefix}/lib --incdir=${prefix}/include/ffmpeg --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --enable-libfaadbin --mandir=${prefix}/share/man --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-pp --enable-libogg --enable-libgsm --enable-libx264 --enable-liba52 --enable-liba52bin --enable-libtheora --extra-cflags=-Wall --enable-swscaler
for the above bunch of configure options to work, we have to install the respective libraries. --enable-libmp3lame, install lame and liblame-dev from debian-multimedia --enable-pthreads, for threading support using pthreads --enable-libogg, install libogg-dev --enable-libtheora, install libtheora-dev --enable-libvorbis, install libvorbis-dev --enable-libx264, install libx264-dev , since libx264 is under GPL we have to also have --enable-gpl --enable-libxvid, install libxvidcore4-dev --enable-libgsm, install libgsm1-dev --enable-libfaad, enable-libfaadbin, install libfaad-dev --enable-libfaac, install libfaac-dev --enable-liba52 --enable-liba52bin, install liba52-0.7.4-dev
- make ffmpeg: make -install ffmpeg: sudo make install This installs the latest ffmpeg on the production server. Now install the rmovie gem : gem install rmovie.
Creating ndlb database
1. Create the production database for ndlb : mysqladmin -u username -p create ndlb_production Change the username to your username.
2. Once the database is created, we have to create the ndlb migrations.
3. In the /var/webapps/rails/ndlb/config/database.yml edit under the "production:" heading as follows.
production:
adapter: mysql
database: ndlb_production
username: username
password: password
host: localhost
socket: /var/run/mysqld/mysqld.sock
encoding: utf8
Change the username and password to your own.
4. Now Edit the /var/webapps/rails/ndlb/config/environment.rb and comment the following lines.
# Code for globalization
#LOCALES = Language.locales_hash
#Globalize::Locale.set_base_language LOCALES['dz']
#ACCEPTED_LOCALES = LOCALES.keys.freeze
#LANGUAGES = Language.languages_array
5. Place the administrative_unit and dictionary CSV files into the /var/webapps/rails/ndlb/db/migrate/units and /var/webapps/rails/ndlb/db/migrate/dicts
6. Do the migrations. rake db:migrate RAILS_ENV=production rake globalize:setup RAILS_ENV=production 7. Now uncomment the lines that we commented on step 4 above.
8. Now start the mongrel server
