Why people use XAMPP and Vagrant

If you are new to the world of web development and don’t know much about Linux, your best choice for setting up a development server is with XAMPP. On the other hand, a great deal of more experienced developers use Vagrant (and Puppet or other configuration managers). Both of these solutions have one thing in common – they are easy to use and this is what you want if your only interest is writing code.

My choice is a bit different. I like tinkering with Linux, so I use virtual machine with Debian. I install and set up everything from scratch. Not only do I find this fun, but I get better understanding of everything involved in running a web server.

My approach naturally involves more work. In any given week I spend more time pounding commands, editing config files and reading manuals/scratching my head than users of “pre-cooked” solutions. Most of the time this is not too bad, but last week I decided to increase the size of one of the virtual disks and that took me a bit more time than I had expected.

So, here is the hard and slow way of increasing the size of virtual hard drive under VMware:

VMware and other virtualization systems have the ability to create dynamic virtual hard drives, which start off small and grow as you fill them with files. This is good option for saving space on your real hard drive, but these things fragment like crazy, so I always pre-allocate virtual drive space. Because HDD space is precious commodity for me, I created relative small virtual drives for my server, which worked well for almost a year, but I needed to expand them. VMware has an option to “grow” the virtual disks, which I tried once and ended up corrupting my files. This feature only grows the disk itself. You have to resize partition manually and this is not always safe.

I chose the safer route. I created a larger virtual disk and planned to copy the files from the old, small one to it. I decided to use Parted Magic for this because of the nice collection of tools it has, which in retrospect wasn’t a good idea. I formatted the new hard drive, mounted it in RW (read/write) mode and copied all my files. I had to edit /etc/fstab in Parted Magic to be able to do this.

Then I shut down the VM, removed the old small disk from the list and placed the new one in the same SCSI slot. I fired up Debian, but it wouldn’t start. After a minute or two of reading the docs/scratching my head, I found the problem. I had forgotten that in /etc/fstab, mount points are set by UUID (which is unique to each partition) and not by the device mount point (such as /dev/sdb5 for instance). I went back to PM and fixed this problem, again I had to first edit the fstab on PM so that the partition would be mounted in write mode.

This time I was able to start my Debian server, but some things were still wrong. My mysql server was down. After some checking I determined that the problem was in permissions. After I had copied the files with Parted Magic, everything in /home and /var was owned by root. Fortunately this is easily fixed (sudo) chown -R command gives the ownership of selected directory and all of its content to the given user. For your www you also have to change the group ownership, assigning it to the group “www-data” and also make sure that group has read access everywhere (chmod 755 or chmod g+r) and write access (775 / g+w) where it is necessary. /var/lib/mysql and /var/run/mysqld (or wherever you keep your mysql files) has to be accessible to the “mysql” user. The cron jobs won’t run until you have write permissions to /var/spool/cron.

Isn’t this fun?! You don’t get to do all this with other, user friendly solutions, especially with XAMPP/WAMP/MAMP and you just can’t appreciate the beauty of Linux until you go through this kind of experience.

Read More