SEO friendly URLs with apache mod_rewrite

I assume that the reader is familiar with the "SEO friendly URLs" concept. If not you can start reading these:

At the cost of beating my own drum, I will consider a real case: http://wildzone.it. It is an image gallery where the contents are organized in a structure like this:


So the smartest way to write the URLs would be: http://wildzone.it/en/italy-4/seaside-of-sardinia-19/orosei-117f.html (external URL). The internal URL, actually managed by the cms and more concise, is: http://wildzone.it?l=en&cat=4&gal=19&id=117. As you can see, the external URL is SEO and user friendly. It embeds the id number of the language/category/gallery/photo. In addition, reading the URL gives the user an understanding of the site's topic and organization.

Running two php/mysql/mariadb versions on the same apache web server

In a web server  very old applications must coexist with new ones. Usually old applications are no more mantained and still require old versions of php and mysql, while recent apps claim to use the latest features of your apache, php and database servers. In addition you may want to switch from MySQL to mariaDB, which is going to quickly supersede its progenitor program.

That said, how to build a web server which mounts on the same apache a variety of php/mysql/mariadb configurations? Let's consider a simple case and suppose to have an apache 2.4.x already installed and two database server, let's say mysql-5.5 and mariadb-5.5, listening on two different IPs. We would like to have two separate php versions available, let's say 5.3.x and 5.4.x, living together and connecting to mysql and mariadb respectively. Of course this procedure can be modified as you like for any number of configurations you like.

I will show how to achieve this configuring php in the usual mod_php manner and and by means of mod_cgid, an apache module which starts php requests as a CGI program, delivering very similar performance as mod_php. I will show how to select the proper php.ini file as well.