| 1 | = Develop directly on your local workstation = |
| 2 | |
| 3 | This process assumes you have a few things: |
| 4 | |
| 5 | * The following installed on your your workstation: Apache/PHP/MySQL, drush, git. |
| 6 | * An account on transitionnetwork.org with permissions to access Backup and Migrate. |
| 7 | |
| 8 | In summary, we're going to: |
| 9 | |
| 10 | 1. Create a "Virtual Host" on our workstation. |
| 11 | 2. Grab a drush makefile for the site from git. |
| 12 | 3. Use the makefile to download and organise all the core code we need with a single command. |
| 13 | 4. Get a copy of the site's database from the live site (it's a built-in feature). |
| 14 | 5. Create a database user and empty database on our workstation. |
| 15 | 6. Import the database on our workstation using phpMyAdmin. |
| 16 | 7. Add the database details to the settings.php file of our site. |
| 17 | 8. Manually download any user-generated files (logos, images, etc) our site needs to look spiffy. |
| 18 | 9. Pat ourselves on the back and make tea. |
| 19 | |
| 20 | So, in detail, here we go... |
| 21 | |
| 22 | == Create a local "Virtual Host" == |
| 23 | |
| 24 | '''How you do this will depend on how you've installed your local web server'''. 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. |
| 25 | |
| 26 | Using the {{{createwebsite}}} script attached, I navigated to my Development folder and ran the following in a terminal: |
| 27 | |
| 28 | {{{ |
| 29 | createwebsite transitiondev.local |
| 30 | }}} |
| 31 | |
| 32 | 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. |
| 33 | |
| 34 | == Build your codebase with drush make == |
| 35 | |
| 36 | Open a terminal in the web root of your website. For example, {{{/home/mark/Development/transitiondev.local/htdocs}}}, and run the following: |
| 37 | |
| 38 | {{{ |
| 39 | wget https://raw.github.com/transitionnetwork/transitionnetwork.org-d6.profile/master/transitionnetwork.org-d6.make |
| 40 | drush make transitionnetwork.org-d6.make . |
| 41 | }}} |
| 42 | |
| 43 | 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. |
| 44 | |
| 45 | == Create a database and populate it with data from transitionnetwork.org == |
| 46 | |
| 47 | Create a database user and empty database: |
| 48 | |
| 49 | * Open phpMyAdmin in your browser - probably http://localhost/phpmyadmin. |
| 50 | * Navigate to "Privileges". |
| 51 | * Click "Add user". |
| 52 | * Supply a username, set Host:localhost, generate and make note of the username and password. |
| 53 | * Check the option for "Create database with same name and grant all privileges". |
| 54 | * Click "Create user". |
| 55 | |
| 56 | Download and import the latest data from transitionnetwork.org: |
| 57 | |
| 58 | * Log in to transitionnetwork.org and go to [[https://transitionnetwork.org/admin/content/backup_migrate|Admin > Content Management > Backup and Migrate]]. |
| 59 | * In the Quick Backup box, using the default settings (Default Database / Download / Manual Backups), click the Backup Now button. |
| 60 | * Save the resulting file somewhere sensible on your workstation. |
| 61 | * 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... |
| 62 | * In a terminal, navigate to the place you downloaded the database dump to. |
| 63 | * First extract the file from its gzip wrapping: |
| 64 | * {{{gunzip transitionnetwork.sql.gz}}} |
| 65 | * Next, pipe the database file into your database: |
| 66 | * {{{mysql -u username -p databasename < transitionnetwork.sql}}} |
| 67 | * 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 :) |
| 68 | |
| 69 | And that's it. You should now have a complete copy of the transitionnetwork.org database on your workstation. |
| 70 | |
| 71 | == Set up your site to connect to the database == |
| 72 | |
| 73 | 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. |
| 74 | |
| 75 | * Navigate to the folder {{{sites/default/}}} in your site. |
| 76 | * Copy the file default.settings.php to settings.php |
| 77 | * 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. |
| 78 | |
| 79 | 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. |
| 80 | |
| 81 | == Finishing off (images, tea, etc) == |
| 82 | |
| 83 | '''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: |
| 84 | |
| 85 | {{{drush dis -y notifictions messaging piwik google_analytics mailchimp captcha mollom session443}}} |
| 86 | |
| 87 | 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. |
| 88 | |
| 89 | '''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". |
| 90 | |
| 91 | '''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 |
| 92 | |
| 93 | '''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. |
| 94 | |
| 95 | 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... |