Middlebury

WordPress Development

Revision as of 15:21, 24 March 2014 by Matthew La France (talk | contribs) (Applying plugin updates)

WordPress is used at Middlebury by a variety of individuals and groups including faculty, staff, students, administrators, designers, developers, librarians, technologists, academic and administrative departments, offices, student organizations, courses, initiatives, projects and so on. This document compiles recommendations about how Wordpress at Middlebury should be configured, updated and maintained.

Initial Setup

The initial setup of WordPress requires:

  1. cloning the Midd WordPress git repository
  2. editing the config.php and .htaccess files
  3. copying production database

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@git.middlebury.edu:web/wordpress.git wordpress
  3. cd into new wordpress directory
    cd wordpress
  4. initialize submodules and then update:
    git submodule init
    git submodule update

Configuring WordPress

  1. cd to your wordpress directory:
    cd ~/public_html/wordpress/
  2. Create a local copy of your WordPress configuration
    cp wp-config.php-midd wp-config.php
  3. Update local copy of WordPress configuration
    -define('DB_NAME', 'username_wordpress');
    +define('DB_NAME', 'yourname_wordpress');
    -$base'/';
    +$base'/~yourname/wordpress/';
  4. Create a local copy of your .htaccess file:
    cp .htaccess-midd .htaccess
  5. Update local copy of .htaccess file:
    -RewriteBase
    +RewriteBase /~yourname/wordpress/

Copying production database to development

  1. Create a database, (e.g. yourname_wordpress) on development server
  2. Dump the production database

mysqldump -h snipe -u wordpress -p --lock-tables=false --skip-extended-insert wordpress > yourname_wordpress.sql

  1. Re-write server specific values in SQL using perl scripts

perl -p -i -e 's#http://blogs.middlebury.edu#http://chisel.middlebury.edu/~yourname/wordpress#gi' yourname_wordpress.sql perl -p -i -e 's#blogs.middlebury.edu#chisel.middlebury.edu#gi' yourname_wordpress.sql perl -p -i -e "s#chisel\.middlebury\.edu','/#chisel.middlebury.edu','/~yourname/wordpress/#gi" yourname_wordpress.sql

  1. Import updated sql into your development database
    mysql -u testuser -ptestpassword -D yourname_wordpress < yourname_wordpress.sql

Updating WordPress

Applying Core Updates

  1. Save your .htaccess, and wp-config.php files outside of wordpress directory
    mkdir ~/wp-settings/; cp .htaccess wp-config.php ~/wp-settings
  2. Delete all files except the .git and .gitignore directories
    find . -maxdepth 1 ! -name '.git*' ! -name '.' ! -name '..' -exec rm -Rf {} \;
  3. Copy the WordPress codebase zip file to your WordPress directory and unzip
    unzip latest.zip
  4. cd into wordpress dir and move files to parent directory
    cd wordpress
    mv * ..
  5. cd to main wordpress directory and delete empty wordpress directory and the zip file
    cd ../
    rm -r wordpress
    rm latest.zip
  6. Add and commit the changes (and additions/removals)
    git-add
    git-add -u
    git-commit -m "Updated Wordpress from version 3.x to version 3.y
  7. Checkout the plugins branch and merge the core changes
    git checkout plugins
    git merge core
  8. Checkout the plugins-miis branch and merge the core changes from plugins
    git checkout plugins-miis
    git merge plugins
  9. Checkout the master-miis branch and merge the core changes from plugins-miis
    git checkout master-miis
    git merge plugins-miis
  10. Checkout the master branch and merge the core changes from plugins
    git checkout master
    git merge plugins
  11. Copy your wp-settings files saved in step 1
    cp ~/wp-settings/.htaccess .
    cp ~/wp-settings/wp-config.php .

Applying language updates

Create a bash script named wp_lang.sh on your development machine with these contents:

#!/bin/bash

WP_DIR='/home/path/to/wordpress/'
LANGS=()
LANGS+=("ar")     # Arabic
LANGS+=("de_DE")  # German - Germany
LANGS+=("es_ES")  # Spanish - Spain
LANGS+=("es_PE")  # Spanish - Peru
LANGS+=("fr_FR")  # French - France
LANGS+=("he_IL")  # Hebrew - Israel
LANGS+=("it_IT")  # Italian - Italy
LANGS+=("ja")     # Japanese
LANGS+=("ko_KR")  # Korean - Korea, Republic of
LANGS+=("pt_BR")  # Portuguese - Brazil
LANGS+=("pt_PT")  # Portuguese - Portugal
LANGS+=("ru_RU")  # Russian - Russian Federation
LANGS+=("zh_CN")  # Chinese - China
LANGS+=("zh_TW")  # Chinese - Taiwan

VERSIONS=()
VERSIONS+=("3.3.2")
VERSIONS+=("3.3.3")
VERSIONS+=("3.4")
VERSIONS+=("3.4.1")
VERSIONS+=("3.4.2")
VERSIONS+=("3.5")
VERSIONS+=("3.6")
VERSIONS+=("3.6.1")
VERSIONS+=("3.7")
VERSIONS+=("3.8")
VERSIONS+=("3.8.1")

# Fetch new copies
for LANG in "${LANGS[@]}"
do
  for VERSION in "${VERSIONS[@]}"
  do
    wget -r -np -nH --cut-dirs=5 -e robots=off -R index.html -P${WP_DIR}wp-content/languages/ http://svn.automattic.com/wordpress-i18n/${LANG}/tags/${VERSION}/messages/
    wget -r -np -nH --cut-dirs=7 -e robots=off -R index.html -P${WP_DIR}wp-content/languages/ http://svn.automattic.com/wordpress-i18n/${LANG}/tags/${VERSION}/dist/wp-content/languages/
  done
done

# Move the theme-specific files and delete their directories
cp ${WP_DIR}wp-content/languages/twentyten/* ${WP_DIR}wp-content/themes/twentyten/languages/
rm -rf ${WP_DIR}wp-content/languages/twentyten/
cp ${WP_DIR}wp-content/languages/twentyeleven/* ${WP_DIR}wp-content/themes/twentyeleven/languages/
rm -rf ${WP_DIR}wp-content/languages/twentyeleven/
cp ${WP_DIR}wp-content/languages/twentytwelve/* ${WP_DIR}wp-content/themes/twentytwelve/languages/
rm -rf ${WP_DIR}wp-content/languages/twentytwelve/
cp ${WP_DIR}wp-content/languages/twentythirteen/* ${WP_DIR}wp-content/themes/twentythirteen/languages/
rm -rf ${WP_DIR}wp-content/languages/twentythirteen/
cp ${WP_DIR}wp-content/languages/twentyfourteen/* ${WP_DIR}wp-content/themes/twentyfourteen/languages/
rm -rf ${WP_DIR}wp-content/languages/twentyfourteen/

  1. Change the value of WP_DIR to be the path to your development copy of WordPress.
  2. Update the LANGS array to include the languages you want to update.
  3. Update the VERSIONS array with the version numbers of WordPress releases since the least up-to-date language with language files in the repository at http://svn.automattic.com/wordpress-i18n/
  4. Make sure the script is executable by running
    chmod u+x wp_lang.sh
  5. Run the script
    ./wp_lang.sh
  6. cd into your WordPress development directory
  7. Add the updated language files
    git add .
  8. Commit the new language files
    git commit -m "Updated language files to latest version."

Applying plugin updates

  1. Checkout the plugins branch
    git checkout plugins
  2. Remove the old plugin
    rm -rf wp-content/plugins/name-of-plugin
  3. Unzip the plugin and move it into place
    unzip name-of-plugin.zip
    mv name-of-plugin wp-content/plugins/
    rm name-of-plugin.zip
  4. Add and commit the changes (and additions/removals)
    git add wp-content/plugins/name-of-plugin
    git add -u wp-content/plugins/name-of-plugin
    git commit -m "Updated name-of-plugin from version x to version y
  5. Checkout the master branch and merge the plugin changes from plugins
    git checkout master
    git merge plugins