Drupal Dev Environment Virtual Machine. Install notes and scripts.

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
MichaelCole's picture

Hi,

Imagine being able to teach someone to review/create patches, without having to teach them to setup a LAMP development environment.
Imagine windows and mac users, friends, learning together to do (blank) with a virtual machine development environment.

I created a virtualbox Drupal development image. I wanted a simple platform to collaborate with several others on for a project. I thought others might benefit from the work.

Features include:
- Slim lightweight image (OS+tools are under 1gig)
- LAMP with APC
- Netbeans and Eclipse with debugging
- Backup restore scripts (with gui interface - zenity)
- One-click drupal "subdomain" installers (wget or cvs) including config of hosts file and apache. E.g. site1.dev, site2.dev (all localhost)
- Step-by-step instructions to create image from scratch (see below)
- I could seed a bittorrent if there is any interest.

My intent was to create something I could share with collaborators so we had the same context, and to save time when ramping up a project. Maybe this could be useful for teaching "Patch bingo" or a some class like this.

I'm interested in feedback. The notes below are a bit stream of consciousness.

The attached zip file includes:
- 3 bash scripts to install: slim ubuntu, install lamp, and install netbeans
- backup/restore scripts
- install scripts

Would this be useful to continue working on? What would you use it for?

Mike

======= Desktop/Scripts/Dev Environment Setup/install notes.txt ========

What:

I want to setup a Drupal development environment with these features:
- PHP Debugging (XDebug + IDE)
- Javascript Debugging (FF, Firebug, Drupal for Firebug, and YSlow)
- Configured like a hosting environment (can run linux commands)
- Runs on windows! I don't want to reinstall my OS thankyouverymuch.
- Something I could create and share with others to collaborate from a shared context.
- A way to get someone "up and running" with development very quickly.

Windows + Linux + Same time = Virtual Machine :-)

So, why not create a virtual machine with this environment inside it?
If it was under 4GB, I could put it on a FAT32 USB flash drive and it would be portable to my several computers.

For others, it would be as simple as downloading and they could start testing patches/development/etc?

Why VirtualBox instead of VMWare?
- VirtualBox has a smaller download (20mb vs 340mb).

Why Ubuntu 9.04?
- Linux is the L in LAMP. Hosting is LAMP
- Popular distro. Let's make this easy for us linux n00bs
- Good support: Googling "ubuntu configure blah" has always turned up current relevant information

Info about the virtualbox image?
- Linux user is "drupaldev"
- Linux user password is "password"
- MySQL root password is "password"

To install the image:

1) Bittorrent the DrupalDev virtualbox image:
- (not hosted yet - see instructions below)

2) Install Virtualbox
- http://www.virtualbox.org/wiki/Downloads

3) Virtualbox -> File -> Import Appliance
- choose the drupaldev.ovf file (not hosted yet)

4) Read the next section "Plan" for how to use the image.

5) If you want to recreate it yourself, read the section after that "How".

6) Make a difference! Try some patch-bingo!
- http://drupal.org/patch-bingo
- http://drupal.org/contrib-patch-bingo
- http://dc2009.drupalcon.org/session/howto-test-patch-and-make-difference

=======

Plan:

Ok, here's the plan:

Let's say you want to work on three Drupal sites.
- hello.com
- world.net
- resume.org

To work on these sites, we'd like the following:
- Run private copies of each website running on our computer:
- hello.dev
- world.dev
- resume.dev
- http://hello.dev/index.php - for Firefox browsing/debugging of Drupal
- http://hello.dev/phpmyadmin - for database view/edit
- /home//websites/hello.dev - for convienent editing
- Debug/profile it with an IDE.

How do we do that?

1) Configure LAMP: Linux Apache MySQL PHP

2) Configure Virtual hosts so we can run more than one website

Well, when a webbrowser makes a request http://www.hello.com/path/file.html:
1) Browser asks DNS server what the IP of web server "www.hello.com" is.
2) Browser connects to web server's IP on port 80, and sends a text request, like this one:
GET /path/file.html HTTP/1.1
Host: www.hello.com:80

Fix 1) by editing /etc/hosts file. Fix 2) by editing /etc/apache2/httpd.conf and adding VirtualHosts. See below.

======

How:

1) Install Virtualbox (2.24)
- http://www.virtualbox.org/wiki/Downloads

2) Install Ubuntu (9.04)
- http://www.ubuntu.com/getubuntu/download
- Configured:
- USA keyboard
- Los Angeles timezone.
- user: drupaldev
- password: password
- Install VirtualBox Extensions (makes using mouse and resizing window nicer)
- In VirtualBox machine,
- Devices -> Install Guest Additions... ->
- Mounts CD. Open CD and dbl-click VBoxLinuxAdditions - x86.run

NOTE: "-" means it's a comment. "$" means run it from the command line. Ubuntu -> Applications -> Accessories -> Terminal

3) Update install and housekeeping
$ sudo aptitude update
$ sudo aptitude upgrade

4) Install LAMP + phpMyAdmin + PEAR + dev tools + Kitchen Sink
- The big download
$ sudo aptitude install apache2 mysql-server phpmyadmin php5 php5-gd php5-mysql php-pear php5-dev apache2-threaded-dev # (php5-dev and apache2-threaded-dev for installing APC)
- Set database password to "password"

- Install APC for Op-code caching
  - Use APC/XCache/eAccelerator?
    - APC actively maintained by PHP developers.  
    - XCache and eAccelerator have "instability" FUD (2008), which I am repeating here without testing :-/
  $ sudo pecl install apc
  $ sudo echo "extension=apc.so" > /etc/php5/apache2/conf.d/apc.ini 

- Install XDebug - PHP Debugging
  $ sudo aptitude install php5-xdebug
  $ echo "xdebug.remote_enable=1" >> /etc/php5/conf.d/xdebug.ini
  # http://wiki.netbeans.org/HowToConfigureXDebug

- Clear up after install
  $ sudo aptitude clean

- Configure for Drupal performance:
  - Enable "Clean URL's"
    $ sudo a2enmod rewrite
  - change default memory limit
    $ sudo nano /etc/php5/apache2/php.ini
    - set memory_limit = 32m
    - Hint: Ctrl-w and then type "memory_limit" to search.  Ctrl-w to search again
  - Turn off some unneeded apache modules to help performance
    $ sudo a2dismod cgi
    $ sudo a2dismod autoindex

- restart apache to activate changes
  $ sudo apache2ctl restart

- UBUNTU 9.04 CONDENSED COMMANDS SUMMARY (run as root):

slim.sh

!/bin/bash

sudo aptitude update
sudo aptitude safe-upgrade
echo "Set password to 'password'"
sudo aptitude -y install apache2 mysql-server phpmyadmin php5 php5-gd php5-mysql php-pear # apache2-threaded-dev php5-dev
sudo pecl install apc
echo "extension=apc.so" > /etc/php5/apache2/conf.d/apc.ini
sudo aptitude install php5-xdebug
echo "xdebug.remote_enable=1" >> /etc/php5/conf.d/xdebug.ini
sudo aptitude clean
sudo a2enmod rewrite
echo "Set memory_limit to 32M"
sudo nano /etc/php5/apache2/php.ini
sudo a2dismod cgi
sudo a2dismod autoindex
sudo apache2ctl restart
mkdir ~/websites

4) Test LAMP install:
- Check LAMP config in phpinfo()
$ echo "

<?php
phpinfo
();
?>
" > /var/www/phpinfo.php
$ firefox http://localhost/phpinfo.php
- Check for these sections (hint: use Ctrl-f to search):
- xdebug
- apc
- rewrite
- memory_limit (32m)
- Check out database http://localhost/phpmyadmin
- user: root
- password: password
- Troubles? Go back and check all the steps.

5) Setup reusable Apache development environment.

We're setting up these sites: hello.dev, world.dev, and resume.dev

1) Set DNS by editing /etc/hosts file.  This file resolves domains to IP addresses.
  $ sudo nano /etc/hosts
      - add these lines at the top of the file:

127.0.0.1 hello.dev
127.0.0.1 www.hello.dev
- the www. entries are so both www.hello.dev and hello.dev URLs resolve.
- Test this out but browsing to http://hello.dev/phpinfo.php
- It should be the same page we tested with above.

2) Create a place for your websites files:

    Because hello.dev and world.dev can have totally different files, Apache uses the "Host:" header to find the right "virtual host".  

  - For convienence, let's put the website files in our users home directory (/home/drupaldev/websites):
        /home/drupaldev/websites/hello.dev
    - Don't create them as user "root"!  Either logout of "sudo", or create them through the GUI.
      - Ubuntu Menu -> Places -> Home
      - right-click -> Create folder -> "websites"
      - Create project folders inside "websites"

3) When Apache answers the request, it needs to know what files to serve.  
    - We'll edit the httpd.conf and add two sections
      - Add a <Directory> tag to set permissions on the /home/drupaldev/websites folder
      - Add a <VirtualHost> tag for each website
      - This file may be empty when you open it.
      $ sudo nano /etc/apache2/httpd.conf

Include /etc/phpmyadmin/apache.conf

Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1

ServerAdmin webmaster@hello.dev
DocumentRoot "/home/drupaldev/websites/hello.dev/"
ServerName hello.dev
ServerAlias www.hello.dev
ErrorLog "/home/drupaldev/websites/hello.dev-apache-error.log"

      - restart apache
      $ apache2ctl restart

  - Notice the "ServerAlias" in the VirtualHost tag?  Use this to setup Multi-site.  E.g.
    - ServerAlias site1.dev site2.dev

  - To add another website in the future, edit these files again.  Remember to restart Apache.  Here is a shell script I put in my websites folder:

! /bin/bash

gksudo gedit /etc/hosts
gksudo gedit /etc/apache2/httpd.conf
sudo apache2ctl restart

  - P.S. This was the hard part :-)

6) Setup Drupal - Simplest Method - manual install:

Go to installation folder.

cd /home/drupaldev/websites/hello.dev

Download from drupal.org with wget. (like a command line "Save file as")

wget http://ftp.drupal.org/files/projects/drupal-6.12.tar.gz
tar -zxvf drupal-* --strip-components=1

Create a settings.php file and setup file permissions

cp ./sites/default/default.settings.php ./sites/default/settings.php
chmod a+w ./sites/default
chmod a+w ./sites/default/settings.php

Create a database, create database user:

mysqladmin -uroot -ppassword create hello
echo "GRANT ALL ON hello.* TO 'hello'@'localhost' IDENTIFIED BY 'password'; exit" > mysql -uroot -ppassword

Start the drupal installer

firefox http://hello.dev

follow the prompts

When finished, reset the permissions

chmod a-w ./sites/default
chmod a-w ./sites/default/settings.php

7) Install Netbeans PHP and Netbeans for Drupal module
- Netbeans PHP 6.7rc2 (find updated version here: http://www.netbeans.org/)
sudo aptitude -y install sun-java5-jre
cd ~/Desktop
wget "http://dlc-cdn-rd.sun.com/c1/netbeans/sync/6.7.1/bundles/netbeans-6.7.1-ml-php-linux.sh"
chmod +x ./netbeans-6.7.1-ml-php-linux.sh
wget "https://nbdrupalsupport.dev.java.net/files/documents/8560/115265/org-netbeans-modules-php-drupal-module.nbm"

double-click file on desktop

- Netbeans Drupal Module
  Start Netbeans -> Tools -> plugins -> downloaded tab -> Add Plugins...

8) Install Eclipse PHP
- We'll focus more on Netbeans, but Eclipse is included: http://2tbsp.com/node/109 http://eclipse.org/pdt/downloads/
cd ~
wget "http://download.eclipse.org/technology/epp/downloads/release/galileo/RC2/eclipse-php-galileo-RC2-linux-gtk-x86_64.tar.gz"
tar -xvf eclipse-php-galileo-RC2-linux-gtk.tar.gz
rm eclipse-php-galileo-RC2-linux-gtk.tar.gz
ln ~/eclipse/eclipse ~/Desktop/Eclipse_PDT_RC2

9) Configure Firefox (3.1.2deb1)
- Open Firefox
- Menu -> Tools -> Addons
- Add these addons:
- Firebug (I had to click around to find version 1.3.3 compatible with Firefox 3.1.0)
- YSlow
- Drupal for Firebug
- And these other handy extensions:
- Colorzilla (color eyedropper)
- MeasureIt (pixel ruler)
- Web Developer (more web developer kung-fu)
- Dust-Me Selectors (find unnecessary CSS)
- Try these others too:
- FireRainbow (javascript syntax highlighting) (experimental)
- Firecookie (view/modify cookies)
- Tamper Data (view/modify headers)
- Page validator (test page for standards compliance)
- Clear Cache Button
- CodeBurner for Firebug (inline HTML/CSS reference) (check license)
- Firefinder for Firebug (CSS/Xpath search)
- Icons will appear in the bottom left and right. A toolbar (web developer) will appear at the top. Clear Cache has to be enabled manually.

BONUS POINTS:

A) Configure error logs:

Apache error logs are configured in the VirtualHosts section of httpd.conf

Php error logs

#change: log_errors = On
#change: error_log = /var/log/php-error.log
sudo nano /etc/php5/apache2/php.ini
sudo touch /var/log/php-error.log
ln /var/log/php-error.log /home/drupaldev/websites/php-error.log
sudo apache2ctl restart

MySQL error logs

ln /var/log/mysql.err /home/drupaldev/websites/mysql.err

B) Easier site install method - automate with Drush command line. http://drupal.org/project/drush
- Install Drush
$ mkdir ~/websites/drush
$ cd ~/websites/drush
$ wget http://ftp.drupal.org/files/projects/drush-All-Versions-2.0-rc1.tar.gz
$ tar -zxvf drush-* --strip-components=1
$ echo "alias drush='php ~/websites/drush/drush.php'" >> ~/.bash_profile
$ alias drush='php ~/websites/drush/drush.php'
- What is drush?
$ drush
- Install a new site with latest CCK, views, and Zen theme:
$ cd ~/websites/world.dev
$ drush dl drupal cck views zen
$ firefox

AttachmentSize
Scripts.zip_.doc25.6 KB

Comments

Extremely useful

ddysart's picture

I'll say that as someone who struggled through all of the above in the past, this would have been a welcome step through to get a drupal dev environment setup. What is nice is the practice you get from running through all of these steps translates weill to seting drupal up on a hosted server.

Well done.

MichaelCole's picture

Thanks! I'm not sure what, if anything to do with it next, but I'm glad you found it interesting.

Cheers,

Mike

Have you tried CoLinux?

voipfc's picture

CoLinux is also a virtualization solution for Windows which is even simpler. Its installation is much smaller and it is easier to carry around and install elsewhere.

With regards to patch-bingo are there some scripts or modules which allow you to test a patch by pointing and clicking. Something anyone can do without much patching knowledge.

eg. is it possible to use drush to test a patch from the command line?

Pendrive alternative

carmichael84's picture

I use a pendrive with any portable edition of some WAMP server if I want a fast windows environment, or I use a pendrive with a live distribution of linux with a LAMP server.
Then I assign different ports for te DBs and HTTPD servers and i have my fast and comfortable environments always with me.

Great

corbacho's picture

I really like this project.

I see that you continue this project in other places, so these links can be useful to people that like me arrived from Google here.

Group Quickstart: http://groups.drupal.org/quickstart-drupal-development-environment
Project Quickstart: http://drupal.org/project/quickstart

In case anyone is interested

drurian's picture

In case anyone is interested in setting up Ubuntu on Virtualbox from scratch, I'm publishing a bunch of<a href="http://friendlydrupal.com/node/1>video tutorials on Friendlydrupal.com.

-Natalie

Friendlydrupal.com - Drupal Video Tutorials

Distro

MGParisi's picture

Is this a concept or is the Distro Available, I hate linux, hate setting it up, and have had the worse luck in the world with it. If something can go wrong it will, so a solution like this for me would be amazing. In not a computer idiot, Im actually a pro at windows, and I keep triing with Linux, but every time I try something does not work as documented, and even with help I usually end up dead in the water. A project like this would be Amazing!


--Sig--
Owner of Proper Programming, LLC a software and website development firm.

Have you tried Linux Mint?

Techivist's picture

I know most folks are hardcore Ubuntu & I was too until the day i tried installing it on my sister's laptop & wifi wasn't working out of the box. Things kept not working as intended then I tried Linux Mint which I'd read was very user/out-of-the-box-friendly. Booted right in & everything worked w/out me having to do a thing!

Since I usually tell folks about the wonderful world of Linux (& open source, in general), I end up taking all of their questions when they do so I mostly use the distro that I'm suggesting to folks so I can be ready for when the phone calls start. I've been using Linux Mint (it's based on Ubuntu) as my main distro ever since. Haven't looked back, everything always works no matter what type of hardware I've thrown at it. I use it as my main Drupal dev environment. You should give it a try, Michael.

Miguel Hernandez - www.migshouse.com
Founder & CEO - The OpenMindz Group
Writer- Linux Journal & TechZulu

Couldn't agree more

pyxio's picture

Techivist... I am with you. Linux Mint simply rocks. I just started on it but i am sure i will be able to say years from now that I never looked back. HIGHLY reccomend Mint... especially XTCE NADIA. Woah nelly

Hey guys, might want to check

patcon's picture

Hey guys, might want to check out Vagrant. It's a project (not necessarily Drupal-related) that is aiming to allow you to boot virtualbox environments from a couple of commands (literally). The environments are a pre-configured using config management provisioning with either Chef or Puppet. It can take some knowledge to create the initial provisioning instructions to tell Chef or Puppet how to set up the environment, but only one person needs to do it, and then everyone else can just use their box and run the one command to boot it.

Someone's already working on a Drupal box:
www.drupal.org/project/vagrant

So here's the workflow in theory (once the legwork is done):

1) download vagrant and it's pre-reqs (virtualbox and ruby).
2) Run git clone git@example.com/path/to/repo.git
3) cd /repo
4) Run vagrant up

The environment now downloads the base box from the vagrant servers, boots the virtualbox environment, provisions the environment using the chef instructions from the git repo (downloading, installing and configuring LAMP stack, drush, varnish, memcache, and whatever is specified). The best part is that Vagrant will also set up shared dirs and port forwarding, so that vagrant dir (which is the git repo dir) is shared with the virtualbox env as the docroot, and the site (running on the virtualbox env) is accessible in your browser at a specified port (say, 127.0.0.1:4567).

So once it's created by one person in the drupal community, we can use one command to have a full environment booted on any platform that virtualbox supports (which is linux, windows, mac, and "other").

It's worth checking out. Really promising solution :)

helpful

sangbk's picture

I see that you proceed with this task in different spots, so these connections can be helpful to individuals that like me landed from Google here.

This is actually an old

Jamie Holly's picture

This is actually an old topic. I think most have started using the DrupalVM project:

http://www.drupalvm.com/


HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

Drupal IDE

Group organizers

Group categories

Drupal IDE Tags

Dev Software

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: