I'm working on a site that is running Craft v2 and also has an installation of Simple Machines Forum (SMF). This has been fine using the approach outlined in this answer, i.e.

$craft = include '/craft/app/bootstrap.php';
echo $craft->templates->render('includes/nav');

Now the site is being upgraded to v3 and this isn't working anymore. I've tried this:

$craft = include '/craft/vendor/craftcms/cms/bootstrap/web.php';
echo Craft::$app->getView()->renderTemplate('includes/nav');

but with that I get:

Uncaught Error: Class 'craft\services\Config' not found in /craft/vendor/craftcms/cms/bootstrap/bootstrap.php on line 165

What else is missing to get this to work for Craft 3?


You should take a look into Craft's index.php file. It sets some constants, autoloads Composer dependencies and loads the environment file before actually loading the script that you tried. Here is the snippet:

 * Craft web bootstrap file

// Set path constants
define('CRAFT_BASE_PATH', dirname(__DIR__));

// Load Composer's autoloader
require_once CRAFT_VENDOR_PATH.'/autoload.php';

// Load dotenv?
if (class_exists('Dotenv\Dotenv') && file_exists(CRAFT_BASE_PATH.'/.env')) {

// Load and run Craft
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
$app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
  • Thanks, that did it. :)
    – Tyssen
    Apr 21 at 22:54

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.