Creating Taxonomy vocabulary and terms programmatically in Drupal 7

Adding taxonomy vocabulary and terms to features is quite expensive you have to install few modules to make it work. another way around is to include it on your hook_update_N() here's how you do it.

<?php

/**
 * Implements hook_update_N().
 */
function hook_update_7001() {
  // Create a Taxonomy vocabulary location.
  $vocab = new StdClass();
  $vocab->name = 'Location';
  $vocab->description = 'List of cities and provinces';
  $vocab->machine_name = 'location';
  taxonomy_vocabulary_save($vocab);
  // Print message.
  drush_print('Taxonomy vocabulary ' . $vocab->name . ' created');
  // Array of cities
  $cities = array(
    'ANGELES CITY',
    'BACOLOD CITY (Capital)',
    'BACOOR CITY',
    'BAGO CITY',
    'BAGUIO CITY',
    'BAIS CITY',
    'BATANGAS CITY (Capital)',
    'BUTUAN CITY (Capital)',
    'CABANATUAN CITY',
    'CABUYAO CITY',
    'CADIZ CITY',
    'CAGAYAN DE ORO CITY (Capital)',
  );
  // Save new taxonomy term.
  foreach($cities as $name) {
    $term = new stdClass();
    $term->name = $name;
    $term->vid = $vocab->vid;
    taxonomy_term_save($term);
    // Print message.
    drush_print('Taxonomy term ' . $term->name . ' created');
  }
}