Category Archives: Web-server

Installing Redmine on cPanel

Installing Redmine on cPanel will be bit harder, because it needs some modifications on server configuration. And custom modifications will be lost on regeneration of configuration files by cPanel. According instruction at http://www.redmine.org/projects/redmine/wiki/HowTo_install_Redmine_on_CentOS_5 you will need change Apache configuration manually. It’s not okay on cPanel. Also it will be conflicts with the Ruby, Rack, RoR versions which comes with cPanel.

Let’s deal with it.

First of all be sure that you have root access to your server, and Ruby on Rails is uninstalled.

Get the rubygems (1.4.2 version):

wget http://production.cf.rubygems.org/rubygems/rubygems-1.4.2.tgz
tar zxvf rubygems-1.4.2.tgz
cd rubygems-1.4.2
ruby setup.rb

Then install passenger:

gem install passenger

Download and extract redmine:

wget http://rubyforge.org/frs/download.php/75518/redmine-1.2.2.tar.gz  # GET LATEST VERSION ON RUBYFORGE
tar zxvf redmine-1.2.2.tar.gz

Install bundler:

gem install bundler

Go to redmine directory and create Gemfile and install bundle:

vi /<redmine_dir>/Gemfile
source "http://rubygems.org" 
gem "rake", "0.8.3" 
gem "rack", "1.1.0" 
gem "i18n", "0.4.2" 
gem "rubytree", "0.5.2", :require => "tree" 
gem "RedCloth", "~>4.2.3", :require => "redcloth" # for CodeRay
gem "mysql" 
gem "coderay", "~>0.9.7" 
bundle install

Create database and user for it, go to redmine directory:

cd config
mv database.yml.example database.yml

Edit database.yml file and write database credentials in production section.

Now edit the config/environment.rb file.

ENV['RAILS_ENV'] ||= 'production'

Type in the shell:

RAILS_ENV=production bundle exec rake generate_session_store
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake redmine:load_default_data

Make sure there were no any error messages.

Go to public/ directory:

cd public/
mv dispatch.cgi.example dispatch.cgi
mv dispatch.fcgi.example dispatch.fcgi
mv dispatch.rb.example dispatch.rb
mv htaccess.fcgi.example .htaccess

Half of the work is done.

Now we must make it available to cPanel. So cPanel uses different version of rack and RoR there will be conflicts.

Install rubyonrails for cPanel.

/scripts/installruby

It will install RoR, RubyGems, Rack etc. which not compatible with redmine. Otherwise you’ll not be able to start ruby application from cPanel. So, create application named redmine and show the path(e.x. /home/redmine/ruby_apps/redmine – but it’s not real redmine directory with you just configured, it’s better show the non-existing directory). Once application is created. You can start it.

Start by clicking Run button on cPanel.

Test it http://yoursite.com:12001. If everything is okay, so we can continue for tricks.

Now stop it.

Go to directory which you created with RoR application on cPanel. Remove all files, copy everything from configured redmine directory. Then go to rubygems directory where you downloaded 1.4.2 version.

ruby setup.rb

Go to redmine directory

gem install passenger
bundle install

Change permissions for redmine directory.

cd ..
chown -R apache:apache redmine_dir
chmod -R 755 redmine_dir

Now go to cPanel, Ruby on Rails section. Run the application. Now it’s ready on http://yoursite.com:12001. You can make it available on port 80 with htaccess.

Enjoy!

lighttpd frontend + apache backend

light_logo_170pxI think you have seen such urls like static.blablabla.com on your favorite web sites. What is it?

Apache HTTPD uses more memory and CPU resources when it has more connections and this make the web site load slower. The light web servers like lighttp, nginx etc. is used to solve this problem.

I will show you how to use lighttpd as proxy to apache and seperate static content from dynamic. Let’s begin.

First of all change the apache port.

#Listen 80
Listen 81

I recommend to block the direct access to 81 port using firewall.

Actually Apache will listen to 81th port and lighttpd will listen to 80th port and lighttpd will transfer requests to apache. The connections will be held by lighttpd and apache will held only connections between lighttpd and itself.

Now restart apache:
Linux:

/etc/init.d/apache2 restart

Windows:

net stop apache2
net start apache2

Now time to install lighttpd. Follow the instructions at http://www.lighttpd.net/

Edit the configuration file lighttpd.conf in its directory.
Add the following lines:

#Redirect the hosts which will be used for dynamic content to apache
$HTTP["host"] == "blabla.com" {
  proxy.server = ("" => ( (
        "host" => "127.0.0.1",
        "port" => 81 ) )
  )
}
 
# make virtual host for static content.
$HTTP["host"] == "static.blabla.com" {
  var.server_name = "static.blabla.com"
  server.name = server_name
  server.document-root = "/srv/www/vhosts/static"
}

Make sure the following modules are enabled in lighttpd:

server.modules = (
  "mod_access",
  "mod_alias",
  "mod_redirect",
  "mod_rewrite",
  "mod_proxy",
  "mod_accesslog"
)

Save the file. Restart the lighttpd typing /etc/init.d/lighttpd restart. Enjoy.