Vhost per tutti con i template per Apache

by Giovanni on April 26th, 2009

Tutti i server di Mikamai usano Ubuntu Linux come distribuzione. Una delle cose migliori è il layout delle directory di Apache, in particolare il modo in cui si abilitano e disabilitano i Virtual Host.

Nonostante la loro semplicità, la creazione dei nuovi vhost è un lavoro tedioso, che abbiamo risolto (alfine!) con uno script ruby molto semplice (è richiesta la gemma optiflag):

#!/usr/bin/env ruby
 
require 'rubygems'
require 'optiflag'
 
module MyOptions extend OptiFlagSet
  flag "d" do
    description "The domain name the vhost should serve"
    long_form "domain"
  end
 
  optional_flag "a" do
    description "Email of the admin. If not specified defaults to info@domain"
    long_form "admin"
  end
 
  optional_switch_flag "w" do
    description "Adds www to non www redirection"
    long_form "www_redirect"
  end
 
  and_process!
end
 
flags = MyOptions.flags
 
admin = flags.a ? flags.a : "info@#{flags.d}"
domain = flags.d
quoted_domain = flags.d.gsub(/\./, "\\.")
 
TEMPLATE=<<-EOT
<VirtualHost *:80>
        ServerName #{domain}
        ServerAdmin #{admin} 
 
        DocumentRoot /var/apps/#{domain}
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/apps/#{domain}>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All 
                Order allow,deny
                allow from all
        </Directory>
 
        ErrorLog /var/log/apache2/#{domain}.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/#{domain}.log combined
 
</VirtualHost>
EOT
 
REDIRECTION=<<-EOT
<VirtualHost *:80>
  ServerName www.#{domain}
  ServerAdmin #{admin} 
 
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^www\\.#{quoted_domain}
  RewriteRule (.*) http://#{domain}/$1 [R=301,L]
</VirtualHost>
EOT
 
puts TEMPLATE
puts REDIRECTION if flags.w?

Lo usiamo in questo modo:

$ vhgen -d domain.com -w > /etc/apache2/sites-available/my_vhost
$ a2ensite my_vhost
No Comments »

Sweeter, Nicer Drupal with Capistrano

by Ivan Vaghi on July 18th, 2008

We didn’t make a fuss about it (although we wish we had the time to do it :-) but we have recently released Montalbano.tv

We are working hard to fatten our portfolio, and it has been great to put a new notch on the belt in our portfolio, side by side with WikiSAP.it.

Both Montalbano and WikiSap are Drupal-based system, as they have a strong editorial component and make wide use of the CMS capabilities of Drupal.

Drupal is very very nice to get started, but as clients start asking you for more complex features – yes they always do! – you have to develop custom modules, do strange magic with the rendering hooks and coordinate more and more people working on the same Drupal instance. Not an easy task on Drupal, if you ask me.

What makes me proud about the people here at MIKAMAI is that we are never happy to just get the work done, but we are always try to extract every nugget of knowledge to hone the process and get the job done better and faster. Giovanni, our Technical Director, is now working on our own Drupal distribution, where we try to address many of the problems that you meet when doing team development on Drupal.

One big point is the externalisation of logic from the DB to files, do that we can put everything nice and safe on Git. The other issue is the deployment. Drupal doesn’t really help with it.. fortunately we are all Ruby on Rails developers and Capistrano always lends an helping hand. Here are Giovanni’s thoughts and experience on using Capistrano to deploy Drupal applications in our projects. Enjoy the post.

1 Comment »