How to category Design category Development category News category

Standard LAMP Virtual Machine Set-up

Getting started with VM – from the ground up

These notes cover the generation of a standard base image from which you can clone many VM’s for development.

We will cover –

  • Initial setup.
  • Addition of packages we commonly use for web-dev.
  • Setup and configuration of Apache.
  • Setup of DNS server for forwarding virtual domains.
  • Setup and configuration of RSYNC.
  • Cloning of the VM.

Initial setup.

Using VirtualBox to create a new machine, using all the default settings, except changing the disc size to a reasonable size at least 200GB, you can then choose the installation type – for us that will be linux and Red Hat (64 bit).

Quickest and simplest option for getting running is to follow the net-install route, grab the ISO for the net-install from one of the many mirrors available. Note – when the partitioning options are given be sure to remove the home partition and expand the root partition to fill the available space.

Within Virtual Box you can then add this ISO as the mounted CD/DVD device. Boot the VM and follow the instructions. You’ll need to specify the URL of the mirror with the packages. When prompted select web-server from the minimal install options. Don’t forget to un-mount the disc upon restart

From Virtual Box you will need to set network interface to “Bridged”, on the VM you should then restart the network service –

> service network restart

Run the following to get your IP address (assuming adapter was set to auto configure during install)

> ipconfig /all

Optional – you can logon to you router and reserve the IP permanently for you machines MAC address – this mill ensure your IP address remains the same.

Addition of packages we commonly use for web-dev.

OK – now we need to get a solid web development "stack" installed. Note some of the following packages may already be installed, if they are then yum will skip that package.

yum update
yum install httpd php mysql mysql-server mysql-dev
yum install ImageMagick ImageMagick-devel 
yum install php-mysql php-pecl php-pear php-dev
yum install php-soap php-xml php-xmlrpc 
yum install nano inetd xinetd rsync openssh-clients

We use apache running php as a module, this is flexible and easy to use and ideal for a virtual setup. Our build tools use RSYNC and this will also need to be configured.

Apache – virtual hosts

We need a virtual root for the sites to be homed, for now we’re just going to create the folders – configuration we’ll cover later.

mkdir /var/www/vhosts
chown apache:apache /var/www/vhosts

We need a home for these to be based and a quick way to manage them.

Configure RSYNC, we use this for project deployment. Note in the packages we installed earlier was nano this is an excellent easy to use terminal text editor, we highly recomend using this saving you having to learn vi, which I am sure is a great editor for those who know it…

$lt; nano /etc/rsyncd.conf
log file = /var/log/rsync.log

path = /var/www/vhosts
uid = apache
gid = apache
read only = no
list = yes
hosts allow = *

Configure the service.

Edit (you can use nano FILENAME) the file /etc/inetd.conf add the line –

rsync stream tcp nowait root /usr/bin/rsync rsync --daemon

check rsync is in the list of services –

cat /etc/services | grep rsync

should show

rsync 873/tcp

If you don’t see the line above then add this to the end of the /etc/services file.

nano /etc/xinetd.d/rsync

It should read as follows – (it should do as at the time of writing yum installed).

service rsync
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID

As this is the first time install we will need to start xinetd –

service xinetd start
chkconfig xinetd on

SE linux we don’t need to run – so lets disable that –

setenforce 0

Edit /etc/sysconfig/selinux

# SELINUX=enforcing

we dont want a firewall either – VM setup is meant to be permissive as it’s for routine destruction.

service iptables stop
chkconfig --del iptables

In reality within our local network your VM will not and should not be exposed to the world, its only used on the local network and on your machine for routine development and as such it is useful to keep your VM as open and easy to work with as possible. Obviously the opposite is true if you want to explore and test the implications of security features such as firewall and SE Linux and a VM is a good way to do this – however this is not generally what we work on day to day when developing sites.

Configure MySQL

Start and add it to started services –

chkconfig mysqld on
/etc/init.d/mysqld start

As this is a development install you may want to make the security more relaxed, the installer will ask you questions about how you want to secure your install.

Configure Apache

nano /etc/httpd/conf.d/zzz_myserver.conf
NameVirtualHost *:80
ServerName myserver:80
<Directory />
Options FollowSymLinks
AllowOverride All
Include /var/www/vhosts/*.conf

Generally we create one config file per domain, any *.conf’s in your web root will now be read by apache. Lets start the server and make sure it’s in the startup –

chkconfig httpd on
service httpd start

Domain example

mkdir /var/www/vhosts/default
mkdir /var/www/vhosts/default/httpdocs
mkdir /var/www/vhosts/default/statistics

nano /var/www/vhosts/default.conf

here is a starter template –

<VirtualHost *:80>
ServerName default
DocumentRoot /var/www/vhosts/default/httpdocs
CustomLog /var/www/vhosts/default/statistics/access_log combined
ErrorLog /var/www/vhosts/default/statistics/error_log

If your editing these files as root, correct ownership and test your config –

chown apache:apache /var/www/vhosts -R
httpd -t

Assuming the check above works without issue –

reload apache

service httpd reload

Generally when your done with the VM you need to shut it down, you can save state if you want to using VirtualBox, however its safest to shut the VM down properly and boot it up when you need it again.

init 0

Good development practice – cloning your VM

DNS MASQ – settign up a wildcard domain to point to the VM on the local network. Note – when cloning you may need to reset the Mac adderss of your network interface within the linux – there are two config files that you need to update with a new Mac each time you clone. Assuming you want a separate IP/domain for each virtual machine (so you can run more than one). Remove the cached network configuration and reboot. Upon reboot this file will have the correct MAC address contained within it (will match your VM).
rm -f /etc/udev/rules.d/70-persistent-net.rules
Then edit the config, copy the correct MAC address into this file –
nano /etc/sysconfig/networking/devices/ifcfg-eth0

Remove the UUID line in the file above, make sure the mac address matches the new one. Finally – reboot the VM and the network should spring to life.


Other considerations, for your cloned VM’s

Specific PHP configuration options.

The following notes relate to a practical way to customise the PHP install for your VM, generally we prefer to run with the defaults, however this doesn’t always work for us.

For example – Allowing short hand codes in PHP – By default the install will set this to ‘Off’ in the php.ini file. This is good generally as it makes for code that is easier to read, however some sites may use short codes so you may need to enable them if this is a problem for you.

Generally we do not edit main configuration files, as with the apache config – In order to change this, rather than edit main php.ini file we add a discrete file to the php.d folder with our specific customisations stated there. This makes maintaining your VM easier. The file should start with a few zzz‘s to ensure it’s the last file processed as they (like the apache config) are loaded alphabetically.

$lt; nano /etc/php.d/zzz-web-engineer.ini
short_open_tag = On


Comments are closed.