DrupalDrupal 7 Bootstrap : Load Drupal from an external PHP script

Drupal 7 Bootstrap : Load Drupal from an external PHP script

This is how to load or bootstrap Drupal 7 into an external script.

We are doing a full Drupal bootstrap here. There are many phases which you can bootstrap, for eg bootstrap only the database layer. You can read about them on the Drupal site

// display all errors
error_reporting(E_ALL);
ini_set("display_errors", 1);

// drupal root and include
define('DRUPAL_ROOT', '/path/to/drupal');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

// you might need to define some of these if the script is not called from a webpage
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';             // required, else drupal will complain
$_SERVER['HTTP_HOST'] = 'www.mysitename.com:8888'; // optional but required for multi site configs
$_SERVER['REQUEST_METHOD'] = 'GET';                // optional
$_SERVER['SCRIPT_NAME'] = '/' . basename(__FILE__);// optional

// Load Drupal
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// Drupal is fully loaded and all Drupal functions are available - your code goes here

Categories: Drupal

Comments

  1. srikanth ganta

    October 14, 2015 12:04 pm

    Reblogged this on Srikanth's Blog.

Post a comment

Your email address will not be published. Required fields are marked *