Skip to content

Instantly share code, notes, and snippets.

@kevinmeyvaert
Created March 8, 2018 07:13
Show Gist options
  • Save kevinmeyvaert/ec15d0bdc2492f33ec247262e700cdae to your computer and use it in GitHub Desktop.
Save kevinmeyvaert/ec15d0bdc2492f33ec247262e700cdae to your computer and use it in GitHub Desktop.
Serving Craft 3 from webroot: how to setup your index.php entry file.
<?php
/**
* Craft web bootstrap file
*/
// Set path constants
define('CRAFT_BASE_PATH', dirname(__FILE__));
define('CRAFT_VENDOR_PATH', './vendor');
// Load Composer's autoloader
require_once CRAFT_VENDOR_PATH.'/autoload.php';
// Load dotenv?
if (file_exists(CRAFT_BASE_PATH.'/.env')) {
(new Dotenv\Dotenv(CRAFT_BASE_PATH))->load();
}
// Load and run Craft
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
$app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
$app->run();
@kevinmeyvaert
Copy link
Author

kevinmeyvaert commented Mar 8, 2018

I know this is NOT the recommended setup for Craft. However, some clients just want cheap shared hosting. ¯_(ツ)_/¯

This is how my web root structure looks like for the provided index.php
schermafdruk 2018-03-08 08 13 51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment