Deploying GeneXus applications on CentOS with Ruby 1.9 and mysql (part 1)

Firs of all you need a CentOS operating system with mysql, ruby 1.9 and passenger installed

If you don’t have this or you don’t know how to do it, just follow the simple instructions on these 2 posts:

Installing Ruby 1.9 on CentOS

Installing Phusion’s Passenger on CentOS (for Ruby 1.9)

Once you are done with this you are ready to move forward.

First you need to copy the following directories from your GeneXus installation to the CentOS server.

From under “gxruby” copy the “linux” and “generic” directory both under the same subdirectory.

In my case I’ve created a new directory on the server called “gxruby” (original 🙂 ), and put them there.

Now before you run the installation script, in order to work properly under CentOS you have to do the following:

  1. The installation script is based on Debian, so it expects to have certain libraries installed in places where CentOS doesn’t normally used them
    specially the “libmysqlclient”. On CentOS these library is called “libmysqlclient.so.15.0.0” and it’s under “/usr/lib/mysql/”, but in the installation
    script it should be under “/usr/local/lib/” so we’ll have to link it to the new location, we do this with the following command:
    $ ln -s /usr/lib/mysql/libmysqlclient.so.15.0.0 /usr/local/lib/libmysqlclient.so
  2. Under the subdirectory “gxruby/generic/gx_lucene” (this is where you copy from the GeneXus machine), you have to edit the script “build_make.sh”.
    In reality, because this file is corrupted on GeneXus Evo1 U3, it’s better if you delete it an create a new one with the same name with the following contente:

    #!/bin/sh
    tar -xzf clucene-core-0.9.21b.tar.gz
    cd clucene-core-0.9.21b
    sh autogen.sh
    sh configure
    make
    make install
    cd ..
    ruby extconf.rb –with-clucene-include=’clucene-core-0.9.21b/src’ –with-clucene-lib=’clucene-core-0.9.21b/src/.libs’ –with-ldflags=’-lclucene’
    make
    mkdir lib
    mv CLucene_gx.so lib
    gem build build_gem.rb
    gem install  CLucene_gx-0.1.1-x86-linux

NOTE:

In addition, if you are using a 64 bit platform replace the last line of the script for gem install  CLucene_gx-0.1.1-x86_64-linux

Now you are ready to run the installation script that will install all GeneXus gems on your system.

Go to “./gxruby/linux”, and run the “installgems.bash” script.

In order to do that just change the mode of the file to “executable” with $ chmod +x installgems.bash

and then runt $ ./installgems.bash

Now, you are ready to deploy your GeneXus Ruby applications.

If you don’t know how to do it, follow the next post where I’m going to walk you through the deployment process

😉

Installing Phusion’s Passenger on CentOS (for Ruby 1.9)

As a prerequisite you have to have installed Ruby 1.9.x on your CentOS system.

If you don’t know how to do it, follow the instructions on this post:

Installing Ruby 1.9 on CentOS

Once you are ready follow the next steps:

On a terminal type:

gem install passenger

$ passenger-install-apache2-module

This last command is going to walk you through the process of installation,

helping you install whatever is missing on your system and at the end giving the instructions

to “patch” your apache’s configurations file.

passenger-install-appache2-module

On my case, I had to install the following modules:

$ yum install httpd-devel

$ yum install apr-devel

$ yum install apr-util-devel

After installing them re-run the command again

$ passenger-install-apache2-module

And then edit the apache configuration

/etc/httpd/conf/httpd.conf

Ad the following lines to the file:

LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.2
PassengerRuby /usr/local/bin/ruby
And finally configure your VirtualDirectories (on the same file)
<VirtualHost *:80>
ServerName ruby.1oc.com
DocumentRoot “/var/www/virtualhost/ruby.1oc.com/web/public”
<Directory “/var/www/virtualhost/ruby.1oc.com/web/public”>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Now reboot the apache server
$ /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
Now you are ready to go.
Test the site http://ruby.1oc.com/
ruby.1oc.com

Installing Ruby 1.9 on CentOS

$ sudo yum groupinstall 'Development Tools' $ sudo yum install readline-devel $ cd /usr/local/src $ wget ftp://ftp.ruby-lang.org:21//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz $ tar xzvf ruby-1.9.2-p0.tar.gz $ cd ruby-1.9.2-p0 $ ./configure && make $ sudo make install
test the installations with
$ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Now, just in case the source became unavailable I'm including it here:
ruby-1.9.2-p0.tar.gz
NOTE:
If you're going to use Ruby for Genexus, the version 1.9.2 and above are NOT suported as this date, instead use the version 1.9.1
ruby-1.9.1-p429.tar.gz

					

Preparing Genexus to deploy applications on Unix with Java and Mysql

We’ll assume here that you already installed a Unix operating system, or Linux.

I’m using CentOS 5.0 (linux) on this example.

In addition I’m assuming that Apache , php and mysql is already installed, as well as phpMyAdmin since all of them came standard with most Linux.

Although we are not using any of those directlly on our application, we’ll use phpMyAdmin as a visual tool to connect with MySql, but in order to run phpMyAdmin you have to have Apache with php 🙂

Let’s start by downloading Tomcat and Java for Linux

If you are logged in your Lunux through ssh terminal, simply use the following commands:

this is for tomcat

wget http://apache.g5searchmarketing.com/tomcat/tomcat-5/v5.5.27/bin/apache-tomcat-5.5.27.tar.gz

or click here to download the file i used (Tomcat)

this is for java

wget http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jre-6u14-linux-i586-rpm.bin?BundledLineItemUUID=63tIBe.l9l4AAAEhrxM_7Kzm&OrderID=f.5IBe.lA4MAAAEhlhM_7Kzm&ProductID=hhNIBe.pzioAAAEhP1UP5zfr&FileName=/jre-6u14-linux-i586-rpm.bin

or click here to download the file I used (Java)

Or just go to their sites and download them from there.

For Java, we are using the pre-zipped auto-executable rpm file.

This means, that first we’ll give the file the mode to be executed

chmod +x jre-6u14-linux-i586-rpm.bin

./jre-6u14-linux-i586-rpm.bin

and them we execute it to install (you don’t need to rung the rpm command, it’s done automatically). This script install Java in the following directory /usr/java/default/.

Now let’s untar Tomcat. For compatibility reasons, let’s put it under the following directory: /usr/tomcat/default/ , but actually we untar it under /user/tomcat/apache-tomcat-5.5.27/ and later we create the symbolic link “default” to that particular directory.

tar xzf apache-tomcat-5.5.27.tar.gz

ln -s apache-tomcat-5.5.27/ default

Now, let’s configure the operating system with the appropriate global variables

At the end of the /etc/profile (file) we add the following commands:

export JAVA_HOME=/usr/java/default

export CATALINA_HOME=/usr/tomcat/default

Save and restart.
Now, you are ready to go.
Enjoy 🙂

Creating a static copy of a dynamic website

 

At work we have several websites that we develop with Plone, but each year we make a new version and we want to keep an archive of the old version.

Since it takes a lot of memory to keep a Zope instance for these old websites that probably won’t need to be edited ever again, it makes sense to make a static copy of the website. It also eliminates the work needed to update the instance when security patches come out (and eliminates security risks, in cases of old versions that are no more maintained).

There are some tools that can help in this case; I chose to use wget, which is available in most Linux distributions by default.

 

The command line, in short…

 

wget -k -K  -E -r -l 10 -p -N -F --restrict-file-names=windows -nH http://website.com/
…and the options explained
-k : convert links to relative
-K : keep an original versions of files without the conversions made by wget
-E : rename html files to .html (if they don’t already have an htm(l) extension)
-r : recursive… of course we want to make a recursive copy
-l 10 : the maximum level of recursion. if you have a really big website you may need to put a higher number, but 10 levels should be enough.
-p : download all necessary files for each page (css, js, images)
-N : Turn on time-stamping.
-F : When input is read from a file, force it to be treated as an HTML file.
-nH : By default, wget put files in a directory named after the site’s hostname. This will disabled creating of those hostname directories and put everything in the current directory.
–restrict-file-names=windows : may be useful if you want to copy the files to a Windows PC.

Possible problems

	
  • wget download the homagepage, robots.txt then stops! Your robots.txt file probably denies access to your site to search engines. Yes, in recursive mode, wget will respect the robots.txt file, so you will need to remove it before making the copy. Don’t forget to put it back in the static site if that’s what you want.
  • Stylesheets : if you have @import stylesheet imports, wget won’t see them, and won’t download them :( You might want to change them to <link rel=”stylesheet” … /> imports, which wget will see and download.
  • Stylesheet images : wget won’t download background-images referenced in CSS files. For most websites that should not be too long to download those images manually.
  • Be sure that you CSS files and with “.css”! Apache won’t send the correct mime-type if your file extension is not .css, and Firefox will not use the stylesheet. (test.css?color=blue won’t work, change it to test.css?color=blue&ext=.css) The same problem may happen with other files types that need to have a proper mimetype set (video files, for instance)
  • LinguaPlone specific problems
    • To prevent having several duplicated files with the set_language parameter, you could setup one subdomain for each language, and force the set_language= in the Apache redirect rule.
    • I also recommand to change the language link so it points to the main page instead of the current page.
    • You have several possibilities here, but by just doing a wget without changing anything, you may end up with pages where languages are a bit fucked up.
  • <base> tag problem : If you pages contains a base tag (which is true for Plone sites), wget will empty it’s value but leave the base tag there ([base href="" /]). That works in Firefox, but it will confuse IE, which won’t load any images, CSS or links.To fix it, you can remove the base tag completely with this command :
    find | grep html$ | xargs perl -i -p -e 's/<base href="" />//g'
    Downsides
    
    
    
    • Most file names will change (bad for SEO)
    • May take some manual work to have a working static copy
    After taking care of all the possible problems, you should have a working static site! Be sure to check with both IE and Firefox (at least), because some problems happen in only one browser. Then, you can shut down your CMS and server the static content using a standard webserver. Don’t forget to put a nice 404 page pointing to your main page, since your URLs probably changed, and several visitors will get a 404 error if they come from search engines or bookmarks.    
  •