Amazium bvba, your online partner
Setting up an Development VM (ubuntu server 10.04)
  • Share post with Twitter
  • Share post with StumbleUpon
  • Share post with Delicious
  • Share post with Digg
  • Share post with Technorati
  • Share post with Blinklist
2010-06-03 16:48

Setting up an Development VM (ubuntu server 10.04)

vmware

Quite some time ago I wrote an article on how to setup a Debian development VM. In this article I will show you how to set up one with Ubuntu Server 10.04.

In this article I explain how to set up the vmware image in VMWare Fusion for Mac OS X. You can probably use it in VMWare WorkStation as well, but since I have never used that I won't be able to answer questions on the subject.

Step 1: Getting the VM running

I like to start from a pre-installed Ubuntu Server VMware image. It is easy to work with and you don't have to keep CD/DVDs lying around. Start by downloading the VMWare image at ThoughtPolice.co.uk. I installed Ubuntu Server 10.04 this time (if you want Debian, see Debian Etch Development VM). After downloading, unzip it.

You can either keep it with the same name or rename it. If you want to rename it, you need to open following files in a text editor:

ubuntu-server-10.04-i386.vmdk
ubuntu-server-10.04-i386.vmx

Inside, do a search and replace on "ubuntu-server-10.04-i386" and replace it by "the_vm_name_you_choose". After that is done, change all the filenames so the "ubuntu-server-10.04-i386" parts are renamed to "the_vm_name_you_choose". Example:

ubuntu-server-10.04-i386.vmx becomes the_vm_name_you_choose.vmx
ubuntu-server-10.04-i386-s001.vmdk becomes the_vm_name_you_choose-s001.vmdk
etc...

Don't forget the directory name.

Then move the directory inside the "Virtual Machines" folder in "My Documents" (on Mac). I'm not sure where the virtual machines are located on Windows, so if anyone knows let me know and I'll add it.

Next step is adding the VM to VMWare Fusion. In the Menu go to File > Open and go to the vmx file in the directory you copied. When VMWare fusion asks you if you copied or moved the file, just say "copied it".

The basic installation happens now, be patient for a minute until it ends. When the user prompt appears, use notroot as username and thoughtpolice as password.

Step 2: Basic configuration and set up

Keyboard Map

The first thing you need to do is change the keyboard map. I'm on AZERTY (why the hell did they invent that!), so I'm having a problem typing. ;) Launch the command below and run trough the screens. Take what is most appropriate for you:

notroot@ubuntu:~$ sudo dpkg-reconfigure console-setup

Username & passwords

Next you can change the user & password to something more appropriate. First let's change the root password. Once it is changed log out so you're back at the login prompt in your VM

notroot@ubuntu:~$ sudo su -
[sudo] password for notroot:
root@ubuntu:~$ passwd
Enter new UNIX password:
Retype new UNIX password:
passed: password updated successfully
root@ubuntu:~$ exit
notroot@ubuntu:~$ exit

Now you log in as root. Let's rename the notroot user & group to something more to your liking:

root@ubuntu:~$ usermod -l new_user_name notroot
root@ubuntu:~$ groupmod -n new_user_name notroot
root@ubuntu:~$ usermod -d /home/new_user_name -m new_user_name
root@ubuntu:~$ usermod -c "New User Name" new_user_name

VMWare Tools

The next thing you need to do is to upgrade the system (I just do 'y' on all questions ;)) and reboot afterwards.

new_user_name@ubuntu:~$ sudo apt-get update
new_user_name@ubuntu:~$ sudo apt-get upgrade
new_user_name@ubuntu:~$ sudo apt-get dist-upgrade
new_user_name@ubuntu:~$ sudo reboot

After the reboot, install the VMWare tools. In VMWare Fusion (make sure you have the latest version!), go to the menu "Virtual Machine" and choose "Install VM Tools". This should mount your VMWare tools CDRom. If it doesn't (it didn't for me), you can mount it using:

new_user_name@dev:~$ sudo mkdir /media/cdrom
new_user_name@dev:~$ sudo mount /dev/cdrom /media/cdrom

Now, let's proceed and actually install the tools. I pressed "enter" on every question to use all defaults.

new_user_name@dev:~$ cd /media/cdrom
new_user_name@dev:~$ tar -C /tmp -zxvf VMwareTools-*.tar.gz
new_user_name@dev:~$ cd /tmp/vmware-tools-distrib
new_user_name@dev:~$ sudo ./vmware-install.pl

Network Stuff

After that, I always install ssh so I can login remotely (use "ifconfig" to find out your ip address).

new_user_name@ubuntu:~$ sudo apt-get install ssh openssh-server

If you want, you can now change my hostname. For this you add a line to your /etc/hosts file (on your VM) with your IP (that you got from ipconfig) and preferred hostname. I added following line:

new_user_name@ubuntu:~$ 192.168.209.130 dev.amazium.com dev

Once that is done, modify the hostname (open the file with vi or nano and modify the content to "dev" (no quotes)):

new_user_name@dev:~$ sudo vi /etc/hostname
new_user_name@dev:~$ sudo reboot

Then verify that the hostname is set:

new_user_name@dev:~$ hostname
dev
new_user_name@dev:~$ hostname -f
dev

Don't forget to add the hosts to your local hosts file as well (on mac: sudo nano /etc/hosts).

Nano bug

I have a nasty bug when I use nano in my VM. My backspace key is actually mapped as delete. To mitigate that bug, edit /etc/nanorc and uncomment following line:

# set rebinddelete

If you haven't done so yet, I suggest you now switch to your mac and login on your VM using ssh. This way you can copy/paste the commands below instead of typing them.

Step 3: Installing LAMP

MySQL

Let's install MySQL first.

new_user_name@dev:~$ sudo apt-get install mysql-server mysql-client libmysqlclient16-dev

If you want to access your database from your macbook (i.e. by a mysql client), you need to comment out following line in /etc/mysql/my.cnf:

#bind-address = 127.0.0.1

Then restart MySQL:

new_user_name@dev:~$ sudo service mysql restart

Apache & PHP:

Once the database is running, you can move on to the webserver (with php).

new_user_name@dev:~$ sudo apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 \
ssl-cert

new_user_name@dev:~$ sudo apt-get install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd \
php5-idn php-pear php5-imagick php5-imap php5-json php5-mcrypt php5-memcache \
php5-mhash php5-ming php5-mysql php5-ps php5-pspell php5-recode php5-snmp php5-sqlite \
php5-tidy php5-xmlrpc php5-xsl php5-cli php5-xdebug

Last but not least you can activate the apache modules you need. I typically install ssl, rewrite and include:

new_user_name@dev:~$ sudo a2enmod ssl
Enabling module ssl.
See /usr/share/doc/apache2.2-common/README.Debian.gz on how to configure SSL and create self-signed certificates.
Run '/etc/init.d/apache2 restart' to activate new configuration!
new_user_name@dev:~$ sudo a2enmod rewrite
Enabling module rewrite.
Run '/etc/init.d/apache2 restart' to activate new configuration!
new_user_name@dev:~$ sudo a2enmod include
Enabling module include.
Run '/etc/init.d/apache2 restart' to activate new configuration!
new_user_name@dev:~$ sudo service apache2 restart
 * Restarting web server apache2
 ... waiting    ...done.

If you want your server time to be in sync, you can install ntp.

new_user_name@dev:~$ sudo apt-get install ntp ntpdate

Step 4: The code paths

IN VMWare Fusion settings, I typically add the project workspace to the shared folders. This way I keep my code on my local machine, while it's immediately accessible in the VM. Once you have modified the settings, you should have the path available in /mnt/hgfs. You will notice that you will have issues with the user / groups. This is because the UID/GID from your mac, differ from the UID/GID from your VM.

You can simple fix this by modifying a config file. In debian I found the line below in the file "/etc/fstab", on ubuntu I found it in "/etc/mtab":

.host:/ /mnt/hgfs vmhgfs rw,ttl=1 0 0

You need to add the uid/gid of your www-data user there. You can find out what the id's are by running following command on the command line:

new_user_name@dev:~$ id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data)

You then modify "/etc/mtab" or "/etc/fstab" so the line looks something like this:

.host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=33,gid=33 0 0

Finally you reboot your VM server and you're ready to go!

new_user_name@dev:~$ sudo reboot

What's next?

So, you have your server ready now. But the story doesn't end here, now you will need to configure your vhosts, set up your databases and start coding! But all of that is out of the scope of this article... ;-)

Enjoy!

Jeroen

Comments and Feedback

Stijn Janssen

2010-06-20 21:33
Great article, everything worked just like you explained it!

Ben Ellis

2010-09-17 11:42
Great except that editing the mtab doesn't work. Gets overwritten with default on reboot. Copying the same line into ftab breaks ubuntu. Suggestions?

Add a Comment

Your email is never published or shared. Required fields are marked*