Monthly Archives: August 2012

Designing mini virtual machine for web development

Motivation
I spent a lot of time on setting web-server for developing webpages in past. Every time I bought a new computer or simple reinstall the operating system I had to set the environment again and again. Solving same or slightly different issues and wasting the time. I also tried a developing inside VM and under a native Unix system. In first case I was confused by the performance. In the second one I don't like the synchronization. I often hibernate my Windows and writing on the partition with hibernated one is not a good idea.

So I decided to design a minimal unix machine with installed services for my development. That should be easily backup-able. No more wasting time with setting a new web development environment.

Realization
At first I had done a check-list with functions that I want to use. Apache web server, php, mysql  database server, ftp deamon, version control system. I also do not want any graphic user interface. Choice of the operating system was very fast and clear I had a good experience with CentOS and there is minimal install ISO image to download.

Installing the CentOS  under VM is really simple but there are several issues with installing and running services listed above.

Network
For the installation of the services is necessary functional network with access to the Internet. I recommend to write own shell script for setting up interface. For example my script for my mobile connectivity with bridged networking:

#!/bin/bash
ifconfig eth0 192.168.1.200 netmask 255.255.255.0
ifconfig eth0 up
route add default gw 192.168.1.1 eth0
echo nameserver 192.168.1.1 >/etc/resolv.conf

After setting up connection it is time for service installation well I started with Midnight Commander which is my favourite tool on unix systems that has little bit friendlier text editor than vi. 🙂 Installing packages on CentOS is really simple the packager's name is yum. So only thing you have to do is enter these commands into a command line.

yum install mc
yum install httpd
yum install mysql-server
yum install php*
yum install subversion
yum install vsftpd

Issues
There are not hard to beat but it can take some time to solve it. The first one is with vsftp deamon. I have trouble with permissions to list/read/write to the directory after loging into ftp server the reason is SELinux. There are two options a) disable it b) set two "se" variables. I tried the second one and it works. After setting these variables ftp started working properly. The commands are:

setsebool ftp_home_dir=1
setsebool allow_ftpd_full_access=1

Firewall is a good thing but if you think about this minimal web server available only from our native machine (host-only network) it is nonsense. So instead of configuring exceptions for services I turned it off by entering this command.

/etc/init.d/iptables stop

Subversion, well this is not really a issue but you have to set up repository which is easy and there is a one problem of accessing to it. One way is access it by HTTPS protocol and the another one is by the SSH.  I choose SSH because it is easier to set up but I have one annoying issue with Tortoise SVN client's input box that wants to know your password with each svn command. I figure out that it can be solved by public key authentication. Well you need to generate a key pair on CentOS and then transfer it to the host machine (viva ftp).  Then load with a Puttygen a save it into putty key format. Then download and run Pageant with that key enter the pass phrase and enjoy the freedom without annoying dialog :).

Start script
It is a good idea to write own start up script which prepare our mini virtual server to run because restart of VM will cause that some settings should lost. For inspiration there is my start up script.

ifconfig eth0 192.168.56.2 netmask 255.255.255.0
ifconfig eth0 up
/etc/init.d/httpd start
/etc/init.d/vsftpd start
/etc/init.d/mysqld start
/etc/init.d/iptables stop
setsebool ftp_home_dir=1
setsebool allow_ftpd_full_access=1

I didn't describe everything in details in purpose. I think that some missing information can be found on Google. If you are interested look on these pages where you can found more.

http://tortoisesvn.net/ssh_howto.html
https://security.appspot.com/vsftpd/vsftpd_conf.html
http://wiht.link/subversion-resources
http://www.cyberciti.biz/tips/ssh-public-key-based-authentication-how-to.html