How to Programmatically Bootstrap Drupal 8 from a PHP script

Boot that Drupal Eight!!!
Boot that Drupal Eight!!!

Here it is! Enjoy...

<?php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');
 
define('DRUPAL_DIR', $_SERVER["DOCUMENT_ROOT"]); //__DIR__ ); //.'/../drupal');
 
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
 
$autoloader = require_once 'autoload.php';
$kernel = new DrupalKernel('prod', $autoloader);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
 
// Do Drupally things...

Tags: