<p>That bootstrap file is only meant to be used by web applications. Even if you got past this error, the file is still going to give you a <a href="http://buildwithcraft.com/classreference/etc/web/WebApp" rel="nofollow">WebApp</a> instance, when what you really want to be working with in that environment is a <a href="http://buildwithcraft.com/classreference/etc/console/ConsoleApp" rel="nofollow">ConsoleApp</a>.</p>

<p>If you want to load Craft from the command line, use craft/app/etc/console/yiic instead (make sure it has executable permissions), or if you already have a PHP script running, load yiic.php.</p>

<p>Unfortunately those files don’t work like bootstrap.php though - they will not only instantiate a ConsoleApp instance, they’ll <a href="http://www.yiiframework.com/doc/api/1.1/CApplication#run-detail" rel="nofollow">run it</a> as well. So you would need to provide your own functionality through a plugin that adds custom <a href="http://www.yiiframework.com/doc/guide/1.1/en/topics.console#creating-commands" rel="nofollow">console commands</a>. You would do that by creating a <code>consolecommands</code> folder in your plugin folder, with files inside it that end with <code>Command.php</code> (e.g. <code>MyPlugin_UtilsCommand.php</code>) and a matching class name, which extends <a href="http://buildwithcraft.com/classreference/consolecommands/BaseCommand" rel="nofollow">BaseCommand</a>.</p>

<p>More details about how to write the class are available from <a href="http://buildwithcraft.com/classreference/consolecommands/BaseCommand" rel="nofollow">BaseCommand’s class reference</a>.</p>

CC BY-SA 3.0
2015-01-19T19:09:32.627Z
2015-01-19T19:09:32.627Z
Brandon Kelly
<p>I'm using Craft Pro 2.3.2625</p>

<p>I'm trying to write a command-line called script which can call Craft's functions (to create new entries with assets).</p>

<p>Based on Brandon's updated answer here:</p>

<p><a href="https://craftcms.stackexchange.com/questions/608/bootstrap-craft-from-another-app">Bootstrap Craft from another app</a></p>

<p>Using:</p>

<pre><code>$craft = require 'craft/app/bootstrap.php';
</code></pre>

<p>in a standalone script should just work after Craft 2.2 - but doing so gives me the following errors (paths tweaked to remove project name):</p>

<pre><code>PHP Notice:  Undefined index: SERVER_NAME in craft/app/bootstrap.php on line 105

Notice: Undefined index: SERVER_NAME in craft/app/bootstrap.php on line 105

Notice: Undefined property: Craft\WebApp::$request in craft/app/controllers/TemplatesController.php on line 156

Fatal error: Call to a member function isSiteRequest() on a non-object in craft/app/controllers/TemplatesController.php on line 156
</code></pre>

<bootstrap-craft>
Bootstrapping Craft gives fatal error
# Bootstrapping Craft gives fatal error

(Asked by: username_0 on 2015-01-19)

I'm using Craft Pro 2.3.2625
I'm trying to write a command-line called script which can call Craft's functions (to create new entries with assets).
Based on Brandon's updated answer here:
Bootstrap Craft from another app
Using:
$craft = require 'craft/app/bootstrap.php';

in a standalone script should just work after Craft 2.2 - but doing so gives me the following errors (paths tweaked to remove project name):
PHP Notice:  Undefined index: SERVER_NAME in craft/app/bootstrap.php on line 105

Notice: Undefined index: SERVER_NAME in craft/app/bootstrap.php on line 105

Notice: Undefined property: Craft\WebApp::$request in craft/app/controllers/TemplatesController.php on line 156

Fatal error: Call to a member function isSiteRequest() on a non-object in craft/app/controllers/TemplatesController.php on line 156

**Tags:** bootstrap-craft


---

## 1 answers

### Answer by username_1 on 2015-01-19. Score: 3

That bootstrap file is only meant to be used by web applications. Even if you got past this error, the file is still going to give you a [WebApp](http://buildwithcraft.com/classreference/etc/web/WebApp) instance, when what you really want to be working with in that environment is a [ConsoleApp](http://buildwithcraft.com/classreference/etc/console/ConsoleApp).

If you want to load Craft from the command line, use craft/app/etc/console/yiic instead (make sure it has executable permissions), or if you already have a PHP script running, load yiic.php.

Unfortunately those files don’t work like bootstrap.php though - they will not only instantiate a ConsoleApp instance, they’ll [run it](http://www.yiiframework.com/doc/api/1.1/CApplication#run-detail) as well. So you would need to provide your own functionality through a plugin that adds custom [console commands](http://www.yiiframework.com/doc/guide/1.1/en/topics.console#creating-commands). You would do that by creating a `consolecommands` folder in your plugin folder, with files inside it that end with `Command.php` (e.g. `MyPlugin_UtilsCommand.php`) and a matching class name, which extends [BaseCommand](http://buildwithcraft.com/classreference/consolecommands/BaseCommand).

More details about how to write the class are available from [BaseCommand’s class reference](http://buildwithcraft.com/classreference/consolecommands/BaseCommand).


---

