Installing Project Fedena, Nginx, MySQL, Mongrel on CentOS 6

Edit 1: Added HowTo section at the end to get ImageMagick and Rmagick gem to work with CentOS thus allowing users to upload pictures to Fedena.

Edit 2: Added HowTo to get Postfix email server running on localhost so users can get Password Reset emails.

Yesterday I finally got Project Fedena running on CentOS 6.0 for my friend’s international school in Tunis, Tunisia.  Project Fedena is an ever popular open source school management system developed with Ruby on Rails developed by Foradian Technologies in India.  It is one of the very few open source school information systems that actually work.

Most of the installations and help guides for Project Fedena usually assume that you are running an Ubuntu Server.  Since I have a bias for CentOS, a Red Hat Enterprise based server distro, I decided to install Fedena on this environment.  Below is my guide to help install Fedena on CentOS 6.0.  This guide assumes you have a working knowledge of running a Linux server.  You should also be comfortable of the Linux command line and know how to at least use the nano text editor.

The steps of this guide will be as follows:

  1. Install MySQL
  2. Install Ruby on Rails
  3. Install Nginx-Passenger
  4. Install Fedena
  5. Configure Postfix
  6. Install Mongrel
  7. Install ImageMagick

It is assumed that you already have CentOS 6 installed, the author of this article used the 32-bit version of CentOS 6.0.  I installed Fedena on my Linux virtual private server hosted with Linode.

1. Install MySQL

I decided to install MySQL first.  I did this so that I would be able to install the MySQL gem in the next step.

1.  Install MySQL with yum:

$yum install mysql-server

2. Start MySQL and ensure that the service starts at the next boot sequence:

$/etc/rc.d/init.d/mysqld start
$chkconfig mysqld on

3. Secure your MySQL instance:

$mysql_secure_installation

4. Log into MySQL:

$mysql -u root -p

5. Create a database fedena and username fedenauser and make sure you grant fedenauser to fedena. (You can replace the database and username):

CREATE DATABASE fedena;
CREATE USER ‘fedenauser’ IDENTIFIED BY ‘YOURPASSWORD’;
GRANT ALL PRIVILEGES ON fedena.* TO ‘fedenauser’;
exit

6. Restart MySQL:

$service mysqld restart

Congratulations! You have installed MySQL and created your fedena database.

2. Install Ruby on Rails

You are going to install Ruby on Rails.  Fedena needs Rails version 2.3.5 to run.

1. Install the Ruby on Rails packages:

$yum -y install rubygems ruby-devel mysql-devel gcc make

2. Install Rails version 2.3.5:

$gem install rails -v=2.3.5 –include-dependencies

3. Install the MySQL gems:

$gem install mysql

You know have a Rails environment installed.  Refer to: http://www.server-world.info/en/note?os=CentOS_6&p=rails if you have problems in this step.

3. Install Nginx – Passenger

You now will install Passenger and Nginx.

1.  Install Passenger:

$ gem install passenger

2. After you install passenger, you can now install Nginx:

$/usr/bin/passenger-install-nginx-module

During the installation, it will ask you where to place nginx.  I decided to put it at /etc/nginx/ though some will use /opt/nginx/.

3. Create a dedicated user to run the nginx process (if you place nginx in /opt/nginx, be sure to change accordingly):

$useradd -M -r –shell /bin/sh –home-dir /etc/nginx nginx

4. You will now need to create the init script for nginx.  Create /etc/rc.d/init.d/nginx with the following script (if you place nginx in /opt/nginx, be sure to change accordingly):

#!/bin/sh
#
# nginx – this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/conf/nginx.conf
# pidfile: /etc/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/etc/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    start
}

reload() {
    configtest || return $?
    echo -n $”Reloading $prog: ”
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
    $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
    esac

5. Make the script executable and set nginx to boot:

$chmod +x /etc/rc.d/init.d/nginx
$chkconfig –add nginx
$chkconfig nginx on

6. Configure nginx Virtual Hosting:

$mkdir -p /srv/www/example.com/public_html
$mkdir -p /srv/www/example.com/logs
$mkdir /etc/nginx/sites-available/
$ln -s /etc/nginx/sites-enabled/

Below is on nginx.conf stored in /etc/conf/nginx.conf:

user    nginx nginx;
worker_processes  4;
worker_rlimit_nofile 30000;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
worker_connections  1024;
}

http {
passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11;
passenger_ruby /usr/bin/ruby;
client_body_timeout 60;
client_body_buffer_size 8k;
client_header_timeout 60;
client_header_buffer_size 1k;
client_max_body_size 10m;
large_client_header_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

include /etc/nginx/sites-enabled/*;

include      mime.types;
default_type  application/octet-stream;

#log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
#                  ‘$status $body_bytes_sent “$http_referer” ‘
#                  ‘”$http_user_agent” “$http_x_forwarded_for”‘;

#access_log  logs/access.log  main;

    sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
listen       80;
server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
root   html;
index  index.html index.htm;
}

        #error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
#    deny  all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;

 #    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

# HTTPS server
#
#server {
#    listen       443;
#    server_name  localhost;

#    ssl                  on;
#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_timeout  5m;

#    ssl_protocols  SSLv2 SSLv3 TLSv1;
#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers   on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

Below is my  nginx server configuration for fedena.  Notice that the root is set to the fedena rails app’s public folder:

  server {
listen 80;
server_name example.com;
root /srv/www/example..com/public_html/fedena/public/;
access_log /srv/www/example..com/access.log;
error_log /srv/www/example..com/logs/error.log;
passenger_enabled on;
}

7. Start nginx:

$service nginx start

Congratulations!  You now have nginx running with passenger.  If you have problems, refer to: http://library.linode.com/lemp-guides/centos-6#sph_compile-nginx-from-source

4. Install Fedena

1. You will now change into your Fedena directory and then grab the latest Fedena source code from github.  For some, it may be easier to use links to retrieve Fedena:

$cd /srv/www/example.com/public_html/
$yum install links
$links http://projectfedena.org/download/fedena-github

 2. Extract fedena:

$unzip projectfedena*

3. It may be helpful to rename this file to fedena:

$mv projectfedena* fedena

4. Move into the fedena directory:

$cd fedena

5. Now you will configure your fedena database:

$nano config/database.yml

Edit the production details with the following:

database: fedena
username: fedenauser
password: YOURPASSWORD (from MySQL – above)

CONTROL-X to save and exit.

6. Install the rest of the gems:

$gem install declarative_authorization -v 0.5.1
$gem install searchlogic -v 2.4.27
$gem install i18n -v 0.4.2

7. Set up the Fedena database.  For the first command, you may see the comment that the database is already created.  That is okay.

$rake db:create

$rake db:migrate

8. Change the permissions to the script:

$chmod +x script/*

9. Run the server:

$script/server

If you followed this guide correctly, you should be able to see Fedena at the following URL: http://example.com:8080.  Username: admin, Password: admin123.

Control-X to quit.  If you need help and want PDF support, please refer to: http://projectfedena.org/install

5. Install Postfix

You will need to have a email server running on localhost to have Fedena send emails to users such as Password Resets.  The easiest solution is to use Postfix.

First install postfix and start the server:

$yum install postfix
$chkconfig –level 345 postfix on
$/etc/init.d/postfix start

Be sure to reconfigure your firewall to block incoming traffic to postfix which is on port 25.

You should still be in your fedena folder, if not, cd back into this folder.  From the main fedena directory, cd into the config directory:

$cd config

We are going to configure postfix at two locations, environment.rb and at environments/production.rb.  Normally you would just configure just one of them but at this moment, lets do both.  I will speak to a Rails guy next week to see where the proper location is but online people either configure on or the other.

In environments.rb, use your text editor and add the following [at the end] making sure you replace the example.com with your  domain:

$nano environment.rb

# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp

# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
:address => ‘localhost’,
:domain => ‘example.com’,
:port => 25,
:enable_starttls_auto => true
}

You can also add this to environments.production.rb.

 Now you have Postfix configured with Rails and Fedena.

6. Install Mongrel

Now to run Fedena in the background without using the above script, you just need to install mongrel:

$gem install mongrel

To start mongrel of port 80, issue the following command:

$mongrel_rails start -p 80 -e production -d

You now will be able to view your Fedena install at http://example.com.

To stop mongrel, issue the following command:

$mongrel_rails stop

If you anticipate many users, you can install and use thin to run 3 mongrel instances.  See http://articles.slicehost.com/2009/4/17/centos-nginx-rails-and-thin for more information.

7. Install Imagemagick and Rmagick gem

For some people, they cannot upload pictures to Fedena resulting in a 500 page error.  The following will fix this problem.

1. First, if you have ImageMagick already installed, you may be running an older version.  You will need to remove it.

$yum remove ImageMagick

$yum install wget tcl-devel libpng-devel libjpeg-devel ghostscript-devel bzip2-devel freetype-devel libtiff-devel

2. Download and install the following ImageMagick RPMs and :

$yum install ImageMagick
$yum install ImageMagick-devel
$gem install rmagick

Restart mongrel and you should be able to upload the pictures now.

Conclusion

You should have a fully running Project Fedena school management system now running on CentOS 6.  Be sure to use mysqldump and crontab to regularly back up your Fedena database.

If I made any errors to the above guide or if you have questions, please feel free to contact me.

Project Fedena School ERP

  • vous le vous

    That is awesome.

  • It is a great open source project.

  • maundinc

    Hello Kevin,

    Thank for sharing, I have been following fedena for a year now and is a very nice piece of programming, i have been trying to improve the performance of fedena by installing nginx with passenger.

    I follow your process, to

    # service nginx start

    but i receive error,

    Starting nginx: nginx: [emerg] unknown directive “server” in /opt/nginx/conf/nginx.conf:131
    [FAILED]

    i follow this steps Refer to: http://www.server-world.info/en/note?os=CentOS_6&p=rails.

    after i receive error

    passenger_root error in nginx.conf i recheck and my path is correct

    passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11;

    I need help to solve this error

    Please help

    Thank you

    Prince

    below is my nginx.conf content

    user nginx nginx;
    worker_processes 4;
    worker_rlimit_nofile 30000;

    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    #pid logs/nginx.pid;

    events {
    worker_connections 1024;
    }

    http {
    passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11;
    passenger_ruby /usr/bin/ruby;
    client_body_timeout 60;
    client_body_buffer_size 8k;
    client_header_timeout 60;
    client_header_buffer_size 1k;
    client_max_body_size 10m;
    large_client_header_buffers 4 16k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;

    include /opt/nginx/sites-enabled/*;

    include mime.types;
    default_type application/octet-stream;

    #log_format main .$remote_addr . $remote_user [$time_local] .$request. .
    # .$status $body_bytes_sent .$http_referer. .
    # ..$http_user_agent. .$http_x_forwarded_for..;

    #access_log logs/access.log main;

    sendfile on;
    #tcp_nopush on;

    #keepalive_timeout 0;
    keepalive_timeout 65;

    #gzip on;

    server {
    listen 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root html;
    index index.html index.htm;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ .php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ .php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache.s document root
    # concurs with nginx.s one
    #
    #location ~ /.ht {
    # deny all;
    #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    # listen 8000;
    # listen somename:8080;

    # server_name somename alias another.alias;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    # HTTPS server
    #
    #server {
    # listen 443;
    # server_name localhost;

    # ssl on;
    # ssl_certificate cert.pem;
    # ssl_certificate_key cert.key;

    # ssl_session_timeout 5m;

    # ssl_protocols SSLv2 SSLv3 TLSv1;
    # ssl_ciphers HIGH:!aNULL:!MD5;
    # ssl_prefer_server_ciphers on;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    }

    server {
    listen 80;
    server_name example.com;
    root /srv/www/example..com/public_html/fedena/public/;
    access_log /srv/www/example..com/access.log;
    error_log /srv/www/example..com/logs/error.log;
    passenger_enabled on;
    }

  • suresh

    hello sir
    i have installed fedena on shared server.but when i generate pdf report
    i receive 500 error page.pls give the solution for my problem

  • Kamel Sellaoui

    Hi Sir

    I would be pleased to invite you to setup fedena in our school in tunisia too.

    please contact me on : kamel.sellaoui@apbs.tn

%d bloggers like this: