My hard drive crashed this last week and I ended up setting up a local dev environment on Ubuntu on a couple machines. Here are the steps I took; this should get anyone to a place where they're ready to start Drupal development on a local machine. In a nutshell, this how-to includes installing and configuring Ubuntu 12.04, Apache 2.2 (including virtual hosts configuration), MySQL 5.5, PHP 5.3.x, phpMyAdmin, SVN 1.7, Git, Eclipse (with PDT, Remote System Explorer, Subclipse, Egit), dnsmasq, and Drush.

Last night I installed it on my home computer following these steps and it took less than 2 hours, including download time.

  1. Install Ubuntu
    1. I use the Ubuntu windows installer; Google it
  2. Add the terminal to the launcher ribbon (on left side of screen) by clicking on Dash Home and then searching for terminal, then drag and drop on launcher ribbon
    1. sudo apt-get update
  3. Install vim
    1. sudo apt-get install vim
    2. Here’s a nice vim cheatsheet: http://www.tuxfiles.org/linuxhelp/vimcheat.html
  4. Install LAMP
    1. sudo apt-get install lamp-server^
      1. test apache
        1. Test: http://localhost
      2. test php
        1. echo "{C}{C}

          " | sudo tee /var/www/testing.php

        2. sudo service apache2 restart
        3. Test: http://localhost/testing.php
      3. Set Apache fully qualified domain name (sometimes an error may come up, I set it anyways, even if the error doesn’t come up)
        1. echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn
        2. sudo service apache2 reload
      4. Test MySQL
        1. cat /etc/hosts | grep localhost
          1. Should say that 127.0.0.1 is home
        2. cat /etc/mysql/my.cnf | grep bind-address
          1. Should say that 127.0.0.1 is home
  5. Install phpmyadmin to manage your databases through a UI
    1. sudo apt-get install phpmyadmin
    2. sudo vim /etc/apache2/apache2.conf
      1. last line of file: Include /etc/phpmyadmin/apache.conf
    3. sudo service apache2 restart
    4. test: http://localhost/phpmyadmin
  6. Install svn and git
    1. sudo apt-get install subversion (installs 1.6)
      1. you’ll need to update svn to 1.7 to use with Subclipse 1.8
        1. echo "deb http://opensource.wandisco.com/ubuntu lucid svn17" | sudo tee /etc/apt/sources.list.d/svn.list
        2. sudo wget -q http://opensource.wandisco.com/wandisco-debian.gpg -O- | sudo apt-key add -
        3. sudo apt-get update
        4. sudo apt-get dist-upgrade (this may take a really long time)
        5. sudo apt-get install libsvn-java (you’ll need this for eclipse)
    2. sudo apt-get install git
  7. Install and configure Eclipse
    1. Open Ubuntu Software Center and search for Eclipse
      1. Upon first open, it’ll ask to set your default workspace location; I set mine as /home/$USER/www
    2. Open Eclipse, go to Help -> Install Software and select “Use all sites”. Search and install the following:
      1. PDT (PHP Dev Tools)
      2. remote system explorer (for SSH support)
      3. subclipse
        1. http://subclipse.tigris.org/update_1.8.x (subclipse)
      4. Drupal for Eclipse (see http://groups.drupal.org/node/39938 for details)
        1. http://xtnd.us/downloads/eclipse
      5. egit
        1. http://download.eclipse.org/releases/juno (egit)
    3. Add svn 1.7 from above to eclipse.ini
      1. sudo vim /usr/lib/eclipse/eclipse.ini
      2. Add to a line immediately after “-vmargs”:
        1. -Djava.library.path=/usr/lib/jni
    4. Add a few views to Eclipse
      1. Window -> Show View -> Remote System Explorer, SVN repositories, Git
    5. Add a SVN or Git repo, used in the next step
    6. Some other configuration changes you'll want to make
      1. Package Explorer -> View Menu -> Filters -> uncheck .* resources.
      2. Window -> Preferences -> Remote Systems -> Files
        1. Select "Show hidden files"
  8. Either checkout a project to your workspace or create one from scratch
    1. I use this to configure Apache virtual hosts, which I why I do it now
    2. I use ~/www/[project_dir]/public_html for web root (Note; in Drupal practice, this would be the [project_dir]/Drupal directory, which is included in the checkout)
  9. Setup your Apache virtual hosts
    1. Note: If you use dnsmasq for DNS resolution (discussed below), do not use .local extension, it’s a PITA
    2. mkdir ~/www/[project_dir]/public_html (if you didn’t do a checkout from above)
    3. mkdir ~/www/logs/[project_dir]
    4. sudo touch /etc/apache2/conf.d/virtual.conf
      1. vim /etc/apache2/conf.d/virtual.conf
      2. Add the following: NameVirtualHost *
    5. sudo touch /etc/apache2/sites-available/example.dev
      1. vim /etc/apache2/sites-available/example.dev
      2. File should look something like this:

#
# Example.dev (/etc/apache2/sites-available/example.dev)
#
ServerAdmin webmaster@example.dev
ServerName example.dev
ServerAlias www.example.dev
# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /home/$USER/www/[proj_dir]/public_html
# Logfiles
ErrorLog /home/$USER/www/logs/[proj_dir]/error.log
CustomLog /home/$USER/www/logs/[proj_dir]/access.log combined

    1. sudo a2ensite example.dev
    2. sudo service apache2 restart
    3. Note: in some instances, you may get a “[warn] mixing * ports and non-* ports with a NameVirtualHost address is not supported, or that “[warn] NameVirtualHost *:80 has no virtual hosts”. I fix this by commenting out NameVirtualHost * in the /etc/apache2/ports.conf file and then removing :80 in /etc/apache2/sites-available/default file.
    4. Enable mod_rewrite while you're at it
      1. cd /etc/apache2/modules-enabled
      2. sudo ln -s ../mods-available/rewrite.load rewrite.load
      3. sudo service apache2 restart
  1. Now you need DNS to resolve locally
    1. Option 1: edit your hosts file
      1. sudo vim /etc/hosts
      2. Add the following: 127.0.0.1 example.dev
    2. Option 2: Alternatively, I recommend running dnsmasq and configuring all .dev extensions to resolve to 127.0.0.1. Note that using the .local extension results in lots of problems and kills baby kittens, don’t use it.
      1. First, Ubuntu 12.04 has dnsmasq installed and enabled by default. Config file, y u no work? This needs to be disabled so we can install a version of dnsmasq that allows configuration.
        1. sudo vim /etc/NetworkManager/NetworkManager.conf
        2. Comment out dns=dnsmasq
        3. sudo restart network-manager
      2. Now, install dnsmasq
        1. sudo apt-get install dnsmasq
        2. sudo vim /etc/dnsmasq.conf
        3. Uncomment line 62 and update to: address=/.dev/127.0.0.1
        4. Uncomment line 90 and update to: listen-address=127.0.0.1
        5. sudo /etc/init.d/dnsmasq restart
      3. Test to make sure any subdomain of .dev resolves to local
        1. dig example.dev
        2. nslookup example.dev
  2. Navigate to http://example.dev and test!
  3. Install Drush
    1. Install PEAR: sudo apt-get install php-pear
    2. sudo pear channel-discover pear.drush.org
    3. sudo pear install drush/drush
    4. sudo drush
    5. Navigate to /home/$USER/.drush and run:
      1. sudo chown –R $USER ./
      2. sudo chgrp –R $USER ./

Comments

Add new comment