Simon Holywell

Posts tagged xampp

A Good Windows Development Environment and Ubuntu Virtualbox

Sun VirtualBox Logo

Sun VirtualBox Logo

Often Linux just does it better!  Often I find myself developing a Windows machine without access to a Linux development server, but I still need to access to some of the Linux binaries and features such as cron jobs, the at command and binaries such as imagemagick, pdftotext, etc.  Some things can be emulated with ported binaries or through Cygwin, but I feel a lot more comfortable developing on a platform that is representative of the live server the web site will run on.

I have not removed XAMPP as it is very useful for developing small scripts or sites without the overhead of running a virtual machine.  Therein lies the problem with this solution – it is virtual machine based and that will mean your local development machine will suffer when the virtual machine steals computing time from the CPU or more memory.  So whilst I can use XAMPP on my netbook I am not so sure a VM will run smoothly.

Setting up a new development environment

  1. Download VirtualBox 2.1 from http://www.virtualbox.org
  2. Download the latest Ubuntu from http://www.ubuntu.com
    Your choice of server or desktop. I chose desktop to give me another web browser testing environment.
  3. Install VirtualBox and open it up
    1. Click create new VM (Virtual Machine)
    2. Give your VM name (I called mine Development)
    3. From the drop downs choose
      1. Linux
      2. Ubuntu (only choose Ubuntu 64 bit if you are running 64 bit Windows)
    4. Choose how much of your machines physical memory the virtual machine is allowed to steal. I chose 512MB as I am running the desktop version of Ubuntu.
    5. You will need to create a new virtual hard disk – a new hard disk wizard will open
      1. Choose dynamically expanding storage
      2. Choose
        1. Give the virtual hard disk a name (mine is called Development just like my virtual machine)
        2. The location of the storage on your hard drive
  4. Now your new virtual machine should be setup so right click on it and choose Start
    1. The Virtual Machine will pop up a message asking you to go through its first run wizard
    2. Choose your installation location
      1. CD/DVD ROM
      2. Image file – point this to the location of your Ubuntu installation ISO you downloaded and saved earlier
    3. This will then mount your CD image and boot from it
  5. Install Ubuntu by going through its installation wizard which is very easy and does not require detail here (if you have chosen the desktop version this will be even easier because you can use the mouse!)
  6. Once you have the virtual machine setup you will want the nice Linux drivers so you can have a larger screen size and for networking etc. For this you need to install the Virtual Guest Additions.
    1. Mount a new CD drive/ISO Image in your virtual machine whilst it is running from the top menu item called Devices
    2. Add the new image which you will find in your VirtualBox program folder
  7. Back to your virtual machine and open up a terminal window
    1. In your terminal navigate to the CD Rom drive
    2. Execute the following command sudo sh ./VBoxLinuxAdditions-x86.run
    3. Once complete you need to reboot the machine so execute sudo reboot
  8. Once the machine reboots get back into the terminal and run the following commands
    1. sudo apt-get update
    2. sudo apt-get upgrade
    3. sudo apt-get install apache2 mysql-server-5.0 php5 php5-xdebug
    4. Just to be on the safe side restart apache with sudo /etc/init.d/apache2 restart
    5. Try accessing your web server by opening a web browser in the virtual machine and typing in localhost if you chose the desktop and you should see a message like It Works!
  9. We need to be able to see folders on our host machine inside the development machine quickly and easy so from the top menu bar choose Devices -> Shared Folders
    1. Add a new folder
    2. Tell it which folder to look in
    3. Give it a memorable name
    4. Tick make permanent
  10. Jump back into the virtual machine and execute the following commands to add your shared folder to the virtual machine, in a terminal
    1. sudo mkdir /mnt/yourFolderNameHere (mine is /mnt/htdocs/)
    2. sudo mount -t vboxsf memorableFolderName /mnt/yourFolderNameHere
      1. Replace memorableFolderName with name you set in step 9.III
      2. Replace /mnt/yourFolderNameHere with the folder you made in step 10.I
    3. If you navigate to /mnt/yourFolderNameHere and execute ls you should see a list of the files on your host systems shared folder
    4. If that worked then we want to add our folder to the fstab file so that the mount point is loaded every time our virtual machine boots up
      1. sudo vim /etc/fstab
      2. Add the following line to the bottom of the file:
        memorableFolderName /mnt/yourFolderNameHere vboxsf defaults 0 0
        1. Replace memorableFolderName with name you set in step 9.III
        2. Replace /mnt/yourFolderNameHere with the folder you made in step 10.I
  11. Now to make this development machine available over the network shut the virtual machine down by going to top menu bar Machine -> Close and choosing Power Off
    1. Right click on the virtual machine and choose settings
    2. From the left hand menu choose Network
      1. Tick Enable Adapter
      2. Adapter Type: Intel PRO/1000 T Server
      3. Attached to: Host Interface
      4. Tick Cable Connected
      5. Choose the interface on your host machine that gives you access to the outside world. You can find out which one this is by looking in your control panel.
    3. Save the settings and start your virtual machine back up again
    4. To find out the IP address of your virtual machine open a terminal execute ifconfig
  12. You should now be able to visit your web server from your host machine by entering that IP address into your web browser.

Configuring our web server

  1. We need to enable mod_rewrite which involves making a simple symbolic link
    1. Navigate to /etc/apache2/mods-enabled
    2. Execute sudo ln -s /etc/apache2/mods-available/rewrite.load rewrite.load
  2. Reboot the server sudo /etc/init.d/apache2 restart and test it is function ok.

Setting up Mass Virtual hosts

The idea behind this step is to minimise the time it takes to setup a new host on the server. Basically all you have to do is create a new directory an away you go. (Don’t forget it will still need to appear in your hosts file).

  1. We need to enable mod_vhost_alias
    1. Navigate to /etc/apache2/mods-enabled
    2. Execute sudo ln -s /etc/apache2/mods-available/vhost_alias.load vhost_alias.load
  2. Now to setup the rules it will create virtual hosts by
    1. Execute sudo vim /etc/apache2/apache2.conf
    2. Go to the base of the file and add the following rules:

      http://gist.github.com/294736

      VirtualDocumentRoot sets the directory that the VHosts public directory is contained in. This will basically convert http://subdomain.localhost/ to /mnt/htdocs/subdomain and pull the relevant files through.

  3. Now restart the apache process sudo /etc/init.d/apache2 restart

A side note when using this method that you should be aware of. This will affect your rewrite rules if they are placed into a .htaccess file. To avoid any problems always declare the RewriteBase rule in your .htaccess.

For example:

http://gist.github.com/294737

VirtualBox Shared Folders Permissions

Nathan brought a glaring omission from my post to the fore – thanks!  Currently you maybe having permissions issues with your shared folders because they might be being mounted as root:root.  To get them to load with a specified user and group you will need to edit your /etc/fstab file again and change ‘defaults‘ to be ‘uid=username,gid=groupname‘ – an example would be ‘uid=simon,gid=www-data‘.

A full line example would be from:
htdocs /mnt/htdocs vboxsf defaults 0 0
to
htdocs /mnt/htdocs vboxsf uid=simon,gid=www-data 0 0

Agavi 1.0 Beta on XAMPP 1.7.0

To install the new XAMPP ensure you firstly uninstall and remove your current XAMPP folder. Upgrades are not supported with this version due to the differences one of which is the removal of PHP4 support from the XAMPP package.

I like to install agavi via the pear package that is available:

  1. Open a command prompt and navigate to your XAMPP directory eg. D:\xampp\php
  2. Execute:
    1. pear channel-discover pear.agavi.org
    2. pear config-set auto_discover 1
    3. pear config-set preferred_state beta
    4. pear install -a agavi/agavi
  3. Wait for a bit as it installs
  4. Execute the command agavi and you will get a phing error

To rectify the error we must complete a little bit of a hack to trick the agavi batch file into recognising our phings version is greater than 2.3.1. Navigate into your XAMPP PEAR folder (D:\xampp\php\PEAR\phing) and create a new directory called ‘etc’. Inside your ‘etc’ directory create a new text file called ‘VERSION.TXT’ containing the following text ‘Phing 2.3.3 BRANCH (2.3dev)’.

Try executing the agavi command on the command line again and you should have a successful response like:

D:\xampp\php>agavi

Agavi > status:

[echo] PHP:
[echo] Version: 5.2.8
[echo] Include path: .;D:xamppphppear
[echo]
[echo] Phing:
[echo] Version: Phing 2.3.3 BRANCH (2.3dev)
[echo]
[echo] Agavi:
[echo] Installation directory: D:xamppphppearagavi
[echo] Version: 1.0.0-beta6
[echo] URL: http://www.agavi.org
[echo]
[echo] Project:
[echo] (not found)
[echo]
[echo] For a list of possible build targets, call this script with the -l a
rgument.

D:\xampp\php>

Hope that helps you out and you can continue to follow the official tutorial.

XAMPP VirtualHosts

XAMPP

XAMPP

Here are some hints for those of you that use a XAMPP install for testing your developments on your local machine.

I am using a Windows machine running XP Pro and this is how I setup my VirtualHosts. The conf file you need to amend is located at c:\xampp\apache\conf\extra\httpd-vhosts.conf Open it up in your favourite editor and un-comment the following line near the top of the file:

NameVirtualHost *:80

This will enable the creation of VirtualHosts in your XAMMP installation.

Firstly you need a VirtualHost setup for localhost so that you can access the XAMPP scripts and demo files and any projects you might already have in the default htdocs location. This will look something similar to this:

http://gist.github.com/294730

Now for your custom VirtualHost. This can be placed anywhere on your computer where there are read permissions setup. It does not have to fall under the standard XAMPP htdocs folder. It will look something like this:

http://gist.github.com/294729

You will notice that in the above example there is a directory directive applied to the VirtualHost where there wasn’t one in the standard localhost VirtualHost we setup first. This is because the default install of XAMMP does not allow us to have folders outside of the DocumentRoot (c:\xampp\htdocs). The VirtualHost I setup was in c:\xampp however so I had to allow Apache access in the VirtualHost container.

Don’t forget to add your new ServerName to your hosts file. Usually found in c:\WINDOWS\System32\drivers\etc\hosts and editable with any text editor. Of course it goes without saying that Apache must be restarted after any configuration changes and you may need to restart your browser after some changes to the hosts file.

Installing Agavi on XAMPP Windows

Having recently heard of the Agavi project from a web framework showdown at a PHP conference in the UK I have decided to trial it. My setup is a WinXP computer with a default install of the latest XAMPP which has thrown up some issues with installing and building Agavi. Please see my hints below to overcome these issues.

  1. Open a command prompt (type cmd in the run console)
  2. Navigate to your XAMMP PHP directory. Mine is C:\xampp-test\php
  3. Execute pear.bat channel-discover pear.agavi.org
  4. Execute pear.bat install agavi/agavi

Agavi is now installed! Now we just need a new default project to work from.

Agavi needs to be told where the phing batch file is stored.

  1. Edit the agavi.bat file in the XAMPP php directory. Mine is C:\xampp-test\php\agavi.bat
  2. Change set PHING_COMMAND=phing to contain the full absolute path to phing.bat which is in the XAMPP php folder. Mine looks like this: set PHING_COMMAND=C:\xampp-test\php\phing.bat

Begin setting up your project directory.

  1. Create a new directory in your XAMPP directory. Mine is C:xampp-testhtdocssimonholywell.com
  2. Create an empty text file called build.properties in the directory (this banishes a build error where phing fails if it cannot find the file)
  3. Open a command prompt and navigate to the new directory
  4. Execute agavi.bat project The agavi.bat file is stored in the XAMPP php folder. My command looked like this: C:\xampp-test\php\agavi.bat project
  5. Follow the prompts the installer gives you (hitting enter will supply the installer with the [default] value)

Agavi should now be setup for your project. View it in your browser to verify.