Middlebury

Difference between revisions of "Drupal Development"

(Copy the production database to your development copy)
(Log in as the admin user)
Line 127: Line 127:
 
=== Log in as the admin user ===
 
=== Log in as the admin user ===
  
Go to [http://chisel.middlebury.edu/~yourname/drupal_dir_name/?q=user http://chisel.middlebury.edu/~yourname/drupal_dir_name/?q=user] and log in as 'admin'. If you are not privy to the admin password, you can reset it in your database by running the following command:
+
Go to [http://chisel.middlebury.edu/~yourname/drupal_dir_name/?q=user http://chisel.middlebury.edu/~yourname/drupal_dir_name/?q=user] and log in as 'admin'.  
 +
 
 +
If you are not privy to the admin password, you can reset it in your database by running the following command:
 
<pre>echo "UPDATE users SET pass = MD5( 'MyPassword' ) WHERE uid = 1;" | mysql -utestuser -ptestpassword -D yourname_drupal</pre>
 
<pre>echo "UPDATE users SET pass = MD5( 'MyPassword' ) WHERE uid = 1;" | mysql -utestuser -ptestpassword -D yourname_drupal</pre>
  

Revision as of 13:11, 14 April 2010

_

_

Checking Out the Project

Add your user to the SVN configuration

On chisel:

  • emacs /var/svn/repos/drupal/conf/authz
    • Add "username = rw" where username is your username below the "imcbride = rw" line
  • emacs /var/svn/repos/drupal/conf/passwd
    • Add "username = password" where username is your username and password is the password you'd like to use for SVN
  • emacs ~/.subversion/config
    • Uncomment L13 "store-passwords = no"
    • Uncomment L19 "store-auth-creds = no"

Checking out drupal

svn checkout svn://chisel.middlebury.edu/drupal/trunk drupal_dir_name

Remember the value you use for "drupal_dir_name" as you will need to enter it later.

Set up the database

Create a new database on chisel using http://chisel/phpmyadmin. If you preface the database name with "drupal_", the testuser account will have automatic access to the database. Otherwise, you will need to set up user privileges for the database. In order for drupal to work with the modules we have installed, you will need to grant the database user the following privileges:

  • Data
    • SELECT
    • INSERT
    • UPDATE
    • DELETE
    • FILE
  • Structure
    • CREATE
    • ALTER
    • INDEX
    • DROP
    • CREATE TEMPORARY TABLES
    • SHOW VIEW
    • CREATE ROUTINE
    • ALTER ROUTINE
    • EXECUTE
    • CREATE VIEW
  • Administration
    • LOCK TABLES
    • REFERENCES

You can import a blank database from the central drupal instance:

mysqldump -u testuser -p -h chisel.middlebury.edu drupal > ~/drupal.sql
mysql -u testuser -p -h chisel.middlebury.edu -D your_db_name < ~/drupal.sql

Set up the Webserver

You do not need to perform this step if you are setting up Drupal in your user home directory on chisel, however it is required when setting up new pre-production instances on longhouse. You must be logged in as root to perform these actions.

Edit /etc/httpd/conf/httpd.conf and add the following in the Directory section:

<Directory "/path/to/drupal">
AllowOverride All
</Directory>

Then run "service httpd restart".

Set up the Filesystem

Assuming you've set this up in ~/public_html/drupal_dir_name on chisel:

  • cp /var/www/html/drupal/.htacccess ~/public_html/drupal_dir_name
    • Edit L101 to read "RewriteBase /~username/drupal_dir_name".
  • cp /var/www/html/drupal/sites/default/settings.php ~/public_html/drupal_dir_name/sites/default/
    • Edit L93 to end with the name of the database you set up previously.
  • chmod -R 777 ~/public_html/drupal_dir_name/sites/default/files

Log in as the admin user

Go to http://chisel.middlebury.edu/~yourname/drupal_dir_name/?q=user and log in as 'admin'.

Development with Git

The Git Documentation site is a great resource for tutorials and details on all commands. If you are used to Subversion, the Git-SVN Crash Course is a good resource.

Initial Setup

Cloning the central repository

Your ssh keys must be authorized to access the central repository. All chisel accounts' ssh keys have been authorized to do so at the time of this writing. Contact Adam to add ssh keys for other machines (such as your desktop) if desired.

  1. cd to your public_html directory on chisel:
    cd ~/public_html/
  2. clone the repository and create a working directory with git-clone:
    git-clone git@chisel.middlebury.edu:drupal.git
    You should now have a working directory at ~/public_html/drupal/

Configuration

  1. Export the default versions of the two ignored files, .htaccess and sites/default/settings.php to your working directory:
    git-diff -p origin/core -- .htaccess | git-apply -R
    cp sites/default/default.settings.php sites/default/settings.php
  2. Modify the .htaccess file. In particular you want to change the RewriteBase to point at the path of your Drupal installation. Change the line
      # RewriteBase /
    to
    RewriteBase /~yourname/drupal/
  3. Modify your sites/default/settings.php to point at your database on chisel. Change $db_url to
    $db_url = 'mysql://testuser:testpassword@localhost/yourname_drupal';

Copy the production database to your development copy

Create a new database on chisel using http://chisel/phpmyadmin. If you preface the database name with "yourname_", the testuser account will have automatic access to the database. Otherwise, you will need to set up user privileges for the database. In order for drupal to work with the modules we have installed, you will need to grant the database user the following privileges:

  • Data

o SELECT o INSERT o UPDATE o DELETE o FILE

  • Structure

o CREATE o ALTER o INDEX o DROP o CREATE TEMPORARY TABLES o SHOW VIEW o CREATE ROUTINE o ALTER ROUTINE o EXECUTE o CREATE VIEW

  • Administration

o LOCK TABLES o REFERENCES

Dump the production data and import it into your database with the following command:

mysqldump -h production_db_host -u production_db_user -p production_db_database | mysql -utestuser -ptestpassword -D yourname_drupal

Log in as the admin user

Go to http://chisel.middlebury.edu/~yourname/drupal_dir_name/?q=user and log in as 'admin'.

If you are not privy to the admin password, you can reset it in your database by running the following command:

echo "UPDATE users SET pass = MD5( 'MyPassword' ) WHERE uid = 1;" | mysql -utestuser -ptestpassword -D yourname_drupal

Browsing History

You can use the command-line program git-log and git-show-branchto browse the history, but a much better experience is provided by the gitk graphical browser.

gitk can be started from the git-gui's "Repository" menu, or from the command line:

  1. SSH to chisel using an XTerm:
    ssh -X chisel.middlebury.edu
  2. cd to the working directory:
    cd ~/public_html/drupal/
  3. open gitk showing all branches:
    gitk --all &

Committing Customizations

No customizations to Drupal should be made on the core or modules branches. These two branches are reserved for code coming directly from third-parties. Keeping our customizations off of these branches allows us to be able to easily see where our modifications to core code and modules reside and to maintain those modifications more easily through upgrades.

  1. cd to the working directory:
    cd ~/public_html/drupal/
  2. Ensure that you are on the master branch:
    git-status
    If not, check out your master branch:
    git-checkout master
  3. Get any changes from the central (origin) repository if desired:
    git-pull origin master
  4. Make some changes to files....
  5. Stage changes to one or more files:
    git-add path/to/desired/file
    or stage all changes:
    git-add .
  6. Commit the staged changes to your repository:
    git-commit -m "My commit message."
  7. Repeat steps 4-6 as many times as desired.
  8. Push your changes to the central repository:
    git-push origin master

Push conflicts

Sometimes you get an error like the following when you go to push your changes to the central repository:

[afranco@chisel drupal-tmp (master)]$ git-push origin master
To git@chisel.middlebury.edu:drupal.git
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'git@chisel.middlebury.edu:drupal.git'

This error indicates that there are new change-sets in the central repository that come after commit that your new changes are based off of. To resolve this issue, the easiest way is to "rebase" your changes on top of those in the central repository. This is done with:

git-pull --rebase origin master

This is equivalent to:

git-fetch origin master
git-rebase origin/master

With this command, your change-sets since you diverged from the central repository's master branch will be set aside, your master branch updated from the central repository's, then your change-sets will be replayed. Once your repository has been rebased, you can push successfully:

git-push origin master

Adding or Upgrading a Module

  1. cd to the working directory:
    cd ~/public_html/drupal/
  2. This process will wipe out your .htaccess file since it is untracked, so copy it to a location outside of your working directory:
    mkdir ~/drupal-settings/; cp .htaccess ~/drupal-settings/
  3. Check out your modules branch.
    • You will initially need to create a modules branch that will track the central repository's modules branch. Do this with
      git-checkout --track -b modules origin/modules
    • If you have already created your modules branch, use
      git-checkout modules
      to check out your modules branch, then
      git-pull origin modules
      to bring your modules branch up to date with the central repository's modules branch.
  4. cd to the modules directory:
    cd sites/all/modules
  5. Delete the original modules directory if upgrading so that we get rid of files that are no longer in the new version
    rm -R modulename
  6. fetch the new module tarball:
    wget http://ftp.drupal.org/files/projects/modulename-6.x-2.6.tar.gz
  7. Decompress the new module tarball:
    tar xzf modulename-6.x-2.6.tar.gz
  8. Delete the new module tarball:
    rm modulename-6.x-2.6.tar.gz
  9. Stage the changes (and additions/removals):
    git-add .
  10. Commit the changes (and additions/removals):
    git-commit -m "Upgraded modulename to version 6.x-2.6 from tarball."
  11. If you are upgrading multiple modules, repeat steps 5-10 for each module.
  12. Check out your master branch:
    git-checkout master
  13. Merge the changes from the modules branch into the master branch:
    git-merge modules
    Note that any customizations to the module should be retained in the merge.
  14. Copy your .htaccess file back:
    cp ~/drupal-settings/.htaccess .
  15. Verify that everything is hunky-dory and the new versions of modules work as expected.
  16. Push all changes in your master and modules branches to the matching branches in the central (origin) repository:
    git push origin modules
    then
    git push origin master
    These can be both pushed at the same time with
    git push origin master modules

Removing a Module

Removing a module is like upgrading one, but we use the git-rm command to delete files and stage the deletions.

  1. cd to the working directory:
    cd ~/public_html/drupal/
  2. This process will wipe out your .htaccess file since it is untracked, so copy it to a location outside of your working directory:
    mkdir ~/drupal-settings/; cp .htaccess ~/drupal-settings/
  3. Check out your modules branch.
    • You will initially need to create a modules branch that will track the central repository's modules branch. Do this with
      git-checkout --track -b modules origin/modules
    • If you have already created your modules branch, use
      git-checkout modules
      to check out your modules branch, then
      git-pull origin modules
      to bring your modules branch up to date with the central repository's modules branch.
  4. cd to the modules directory:
    cd sites/all/modules
  5. Delete the original modules directory:
    git-rm -rf modulename
  6. Commit the deletion:
    git-commit -m "Deleted modulename."
  7. Check out your master branch:
    git-checkout master
  8. Merge the changes from the modules branch into the master branch:
    git-merge modules
    Note that any customizations to the module may result in merge conflicts that will need to be resolved (by using git-rm again on the master branch, then committing.
  9. Copy your .htaccess file back:
    cp ~/drupal-settings/.htaccess .
  10. Verify that everything is hunky-dory and no dependencies are broken.
  11. Push all changes in your master and modules branches to the matching branches in the central (origin) repository:
    git push origin modules
    then
    git push origin master
    These can be both pushed at the same time with
    git push origin master modules

Upgrading the Drupal Core

Upgrading core code is similar to upgrading a module. The only difference to watch out for is that we want to delete everything in our working directory except the .git/ directory before we add in the new code.

  1. cd to the working directory:
    cd ~/public_html/drupal/
  2. This process will wipe out your settings in .htaccess and sites/default/settings.php, so copy them to a location outside of your working directory:
    mkdir ~/drupal-settings/; cp .htaccess sites/default/settings.php ~/drupal-settings/
  3. Check out your core branch.
    • You will initially need to create a core branch that will track the central repository's core branch. Do this with
      git-checkout --track -b core origin/core
    • If you have already created your core branch, use
      git-checkout core
      to check out your core branch, then
      git-pull origin core
      to bring your core branch up to date with the central repository's core branch.
  4. Delete all files and directories except the .git directory
    find . -maxdepth 1 ! -name '.git' ! -name '.' ! -name '..' -exec rm -Rf {} \;
  5. fetch the new drupal tarball:
    wget -O ../drupal.tar.gz http://ftp.drupal.org/files/projects/drupal-6.16.tar.gz
  6. Decompress the new drupal tarball:
    tar --strip-components 1 -xzf ../drupal.tar.gz
  7. Delete the new Drupal tarball:
    rm ../drupal.tar.gz
  8. Stage the changes (and additions):
    git-add .
  9. Check for any removals with:
    git-status
  10. Stage any removals with:
    git-rm path/to/file
  11. Commit the changes (and additions/removals):
    git-commit -m "Upgraded Drupal to version 6.16 from tarball."
  12. Check out your modules branch:
    git-checkout modules
  13. Merge the changes from the core branch into the modules branch:
    git-merge core
    Note that any module additions will be retained in the merge.
  14. While you are on the modules branch, upgrade any modules that need upgrading (as detailed above).
  15. Check out your master branch:
    git-checkout master
  16. Merge the changes from the modules branch into the master branch:
    git-merge modules
    Note that any customizations should be retained in the merge.
  17. Copy your .htaccess and sites/default/settings.php back:
    cp ~/drupal-settings/.htaccess .; cp ~/drupal-settings/settings.php sites/default/
  18. Verify that everything is hunky-dory and the new versions of modules work as expected.
  19. Push all changes in your master, core and modules branches to the matching branches in the central (origin) repository:
    git push origin master core modules

Deploying change-sets to Production

Coming soon...

Version-control of production configuration

Coming soon...