I'm trying to bootstrap drupal from a standalone PHP script at the command line from sites/all/modules/mymodule/mymodule.php.

  require_once './includes/bootstrap.inc'; 

I'm attempting to run it from the command line, but I get Drupal site-offline when I do (trimmed for brevity):

cd /sandbox/mysite
php sites/all/modules/mymodule/mymodule.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Site off-line | Pressflow</title>

The site is online and works fine from the browser. DRUPAL_BOOTSTRAP_DATABASE is where this fails, since I can bootstrap the DRUPAL_BOOTSTRAP_CONFIGURATION and DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE phases without a problem. Anyone run into this before? Thanks in advance.

  • What are you trying to do that requires a separate *.php script as opposed to a regular Drupal module? If you are looking to execute command line scripts against Drupal, then I would highly suggest you write your own Drush commands. Jul 5, 2012 at 20:55

2 Answers 2


An easy way of writing CLI code for Drupal is implementing your own drush (http://drupal.org/project/drush) commands. Drush itself commes wirh handy example code.

  • It's a custom module/script that creates many nodes and will eventually run from its own crontab. I'm testing it locally currently and trying to bootstrap Drupal from it since it has some hardcoded paths that I can better write with access to Drupal globals. All info I've seen on bootstrapping Drupal from a CLI script etc. all use this technique and none mention running into Site Offline in the process.
    – Vincent
    Jul 5, 2012 at 22:20

I was running this from MAMP and had to specify the direct path to PHP at the CLI for drupal to bootstrap correctly. It was calling Mac system php, not MAMP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.