Automatic vHost with Apache

In my development machine i wanted to have a specific vHost for each project. Something that would allow me to type URL like:

  • http://wordpress-test1.lan/
  • http://phpmyadmin.lan/
  • http://project1.lan/

I started to set for each one a vHost in Apache but after a while I've found myself with too many vHost files.

So I started to search for a more easy and fast way, and here it is:

Note: you need to install Apache mod_rewrite to make things work.

Preamble:

  1. You have Apache installed, and your DocumentRoot is /var/www/
  2. You have mod_rewrite installed and enabled
  3. You can modify the /etc/hosts file

Let's say we want to install a test/demo version of WordPress and access it from the URL http://wp-test.lan/

  1. We download and untar WordPress in /var/www/wp-test/
  2. We tell our machine to resolve the domain wp-test.lan with the IP 127.0.0.1. To make this we add a line to our hosts file.hpatoio@namazu:~$ sudo su -
    [sudo] password for hpatoio:
    root@namazu:~#echo "127.0.0.1 wp-test.lan" >> /etc/hosts
    root@namazu:~#exit
    hpatoio@namazu:~$
  3. Now we have to change Apache config. Open /etc/apache2/sites-anabled/000-default with your favorite editor and add these lines inside the <VirtualHost *> directive:RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([^.]+)\.lan$
    RewriteRule ^(.+)$ /%1$1
    Basically :

    • The first line turns the mod_rewrite on
    • The second one tells Apache to keep in the host part of the URL (HTTP_HOST) everything that stands before ".lan"
    • Finally the third line insert the string matched before (%1) between the host and the resource part (directory + file + query string) of the requested URL
  4. Restart Apache
  5. hpatoio@namazu:~$sudo /etc/init.d/apache2 restart
    Now if open your browser and you point it to the URL http://wp-test.lan/ you should see the WP installation page. Right ?

Carnival !!

???

???

Critical Mass Lecco

It has to start somewhere,
it has to start sometime !
Which better place than here ?
Which better time than now ?

Critical Mass Lecco 2008

Clusone '07

Giusy, Kathrin and me. Thanks to Adeline (on the other side of the camera

Giusy, Kathrin and me. Thanks to Adeline (on the other side of the camera

Like the last 4 years, few days ago, I was in Clusone for the Estate di S.Martino, I love this village and the feeling you get during the happening. Lovely wine, traditional food and true friends … need more to be happy ?

If the next year you wanna come mark this site: www.bandabidu.org.

Got pictures !

Reading and writing in Amsterdam !

Reading and writing in Amsterdam !

Sotto la panza ...

Under the belly ...

CSV export from MySQL

If you have access on the machine with MySQL and you need to export all tables in a database you can use:

hpatoio@namazu:~$ mysqldump -uroot -p DATABASE_NAME -T '/home/simone/export_csv' --fields-terminated-by "," --fields-enclosed-by '"' --lines-terminated-by "\n"

the script will create a files for each table of the DB and will place it in export_csv.

If you need to export a custom resultset or you need to export data from a remote MySQL server on your machine you can use this command :

hpatoio@namazu:~$ mysql -uroot -h HOSTNAME -p DATABASE_NAME -B -e "select field1,field2 ... fieldX from \`TABLE_NAME\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > my_export.csv

Microsoft Access to MySQL | Online converter

Amazing online tool to convert MDB Microsoft Access file to MySQL SQL scripts !

Check it out -> http://www.mdb2mysql.com/

Good times

Joelle and I

Joelle and I

And also for this year my vacations are finished. Many people I've met on the way … some were already friends, some were new :D .

I could write for hours trying to tell you who I meet and where I was, but, as you probably know I'm not good in telling stories.

So just wanna say thanks to : Jan, Rebekka, Bugo, Vale, Gio, Anca (even if it didn't work), Joelle and all the people at the NEVA meeting, Linnea, Kenneth and all the Tjärnkvist family, Karsten, Liga, the lovely people in Ultervattnet, the backpackers at the Sunflower Hostel, Adam and of course to Swedish Police :D

Due I didn't have a camera with me there are no pictures of the vacations, except for this one …

Finally ! What you see is what you mean

I was looking for a good and clean editor for one of my customers, and I end up to WYMeditor !

That's the way I like, that's the way I meant !

Add days to a date in javascript

shiftDay = 10
var myDate = new Date();
myDate.setDate(myDate.getUTCDate() + shiftDay)
day   = myDate.getUTCDate()
month = myDate.getUTCMonth()*1 + 1
year  = myDate.getUTCFullYear()

This code is quite easy:

  • shiftDay hold the number of days you want to add, if you need to go backwards you can set it to a negative value.
  • myDate is set to the current date
  • At the end we will have the data we need in day, month and year.
  • getUTCMonth return the current month shifted back by one (January is 0, February is 1 and so on) that's why we add 1. We multiply the value returned by getUTCMonth by one to cast it to integer.
Yes !