Created
March 8, 2018 07:13
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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