wiki:website/devEnvironment/workstation
Last modified 4 years ago Last modified on 05/17/13 13:12:55

Develop directly on your local workstation

This process assumes you have a few things:

  • The following installed on your your workstation: Apache/PHP/MySQL, drush, git.
  • An account on transitionnetwork.org with permissions to access Backup and Migrate.

In summary, we're going to:

  1. Create a "Virtual Host" on our workstation.
  2. Grab a drush makefile for the site from git.
  3. Use the makefile to download and organise all the core code we need with a single command.
  4. Get a copy of the site's database from the live site (it's a built-in feature).
  5. Create a database user and empty database on our workstation.
  6. Import the database on our workstation using phpMyAdmin.
  7. Add the database details to the settings.php file of our site.
  8. Manually download any user-generated files (logos, images, etc) our site needs to look spiffy.
  9. Pat ourselves on the back and make tea.

So, in detail, here we go...

Create a local "Virtual Host"

How you do this will depend on how you've installed your local web server.

If you're running Mac OS X and have MAMP installed, then check out Creating a virtual host in MAMP, more mac specific help from BenJ's experience

If you're running Linux, there is a script and apache config file template attached to this page which might help you automate the process. However, this is experimental, might require some tinkering to get it working on your system, and you may already have a better way of doing this.

Using the createwebsite script attached, I navigated to my Development folder and ran the following in a terminal:

createwebsite transitiondev.local

That creates your web-root and logs folders, configures and enables your new website with apache, restarts apache, and adds a line to your /etc/hosts file so that you can now visit http://transitiondev.local and see your new (empty) website.

Build your codebase with drush make

Open a terminal in the web root of your website. For example, /home/mark/Development/transitiondev.local/htdocs, and run the following:

wget https://raw.github.com/transitionnetwork/transitionnetwork.org-d6.profile/master/transitionnetwork.org-d6.make
drush make transitionnetwork.org-d6.make .

Type "Y" and ENTER to the question "Make new site in the current directory? (y/n)", and drush will automagically grab all the code you need for your working copy of transitionnetwork.org (core, contributed and custom modules, themes and features). It can take a little while, so you might want to carry on to the next step and set up the database while this is cooking.

Create a database and populate it with data from transitionnetwork.org

Create a database user and empty database:

  • Open phpMyAdmin in your browser - probably http://localhost/phpmyadmin.
  • Navigate to "Privileges".
  • Click "Add user".
  • Supply a username, set Host:localhost, generate and make note of the username and password.
  • Check the option for "Create database with same name and grant all privileges".
  • Click "Create user".

Download and import the latest data from transitionnetwork.org:

  • Log in to transitionnetwork.org and go to Admin > Content Management > Backup and Migrate.
  • In the Quick Backup box, using the default settings (Default Database / Download / Manual Backups), click the Backup Now button.
  • Save the resulting file somewhere sensible on your workstation.
    • Bear in mind the database file you download is pretty big, so chances are it'll be too big to import with phpMyAdmin. So get your trusty terminal open again...
  • In a terminal, navigate to the place you downloaded the database dump to.
  • First extract the file from its gzip wrapping:
    • gunzip transitionnetwork.sql.gz
  • Next, pipe the database file into your database:
    • mysql -u username -p databasename < transitionnetwork.sql
    • This will take a little while to complete. Maybe 10 minutes or more. You can check the progress by looking at the list of tables for this database in phpMyAdmin if you like. The tables get added in alphabetical order. It's pretty boring to watch though, so go make yourself a cuppa :)

And that's it. You should now have a complete copy of the transitionnetwork.org database on your workstation.

Set up your site to connect to the database

The codebase that drush-make built for you is basically a blank site waiting to be installed. If you visit the site in your browser, you'll get the Drupal Installation page. We don't want to use this. Instead, we need to manually create a settings.php file so that our site connects with the database you've just installed.

  • Navigate to the folder sites/default/ in your site.
  • Copy the file default.settings.php to settings.php
  • Edit line 91 that starts $db_url, replacing the values for username, password and databasename with the details you noted from setting up the database. If you followed the instructions above, the username and database name will be the same.

If you visit your site now in your browser, you should see that, apart from missing a few important images, your copy of the site it working pretty well.

Finishing off (images, tea, etc)

Disable irritating modules: Before we do anything to our site, it's important that we disable some modules that will cause you problems on a development copy of the site. The following drush command will take care of this for you:

drush dis -y notifictions messaging piwik google_analytics mailchimp captcha mollom session443 moopapi botcha

This will actually cause the following list of modules to be disabled: messaging, piwik, mailchimp, captcha, mollom, session443, messaging_mail, messaging_simple, messaging_template, notifications, messaging_mime_mail, notifications_anonymous, notifications_autosubscribe, notifications_content, notifications_nodetype, notifications_tags, notifications_ui, notifications_views, transition_pse, transition_pse_widget, recaptcha, moopapi, botcha.

Reroute Email. You should also turn on the Reroute Email module, which will force all email generated by Drupal to be rerouted to a single, configurable address (ie. yours). This module should already be installed and enabled, and you'll just need to add permission to use it to the developer role ([url]admin/user/permissions#module-reroute_email). Once you've got the permission to use it, go to Admin > Site Configuration > Reroute Email, check " Enable rerouting", enter your own email address, and click "Save configuration".

Check filesystem permissions. You may have a little tinkering to do to get your file permissions working properly. One quick fix is simply to change the entire contents of sites/www.transitionnetwork.org/files so it's owned by your webserver ('www-data' on some systems), or so it's all "world"-writeable. Another solution is to use the Apache mpm_itk_module so your website runs PHP with your permissions. On systems with an encrypted home directory, there can be an issue with access to the Temporary Directory, which can be solved by changing this to /tmp in Admin > Site Configuration > File system

Get any images you need. The images added by users to the site will be in the live files directory, which isn't copied to your workstation as it would result in massive unnecessary data transfer. Instead, if you need any of the user-added images, you'll need to grab them manually. For example, the main logo is in "sites/www.transitionnetwork.org/files/transition2_logo.jpg" on the live site. So, the quick and dirty way to grab it, is to have the live site open, right click on the image and choose "open image in new tab", then download the image from that tab and place it in the right place locally. Other useful tools to make this process less fiddly are a code inspector in your browser, good ol' "View source" (followed up with a Ctrl+F search for "src=" to locate images in the code), and the wget command line utility.

At about this point, you're pretty close to having your own local development copy. Next up, you'll be wanting to actually start developing...