4

I'm trying to setup Craft 3 on a shared host. It succeeds when I place all files in the public directory and then go to /web.

But if I move the craft files to the folder /private_html/craft and the web files in /public_html it won't work (error 500). Do I need to edit the index.php file after all (not mentioned in the installation docs)?

Tried setting the index.php lines to ../private_html/craft/vendor and ../private_html/craft/.env, but no luck. I get the feeling the index.php needs a pointer where the craft folder resides?

<?php

// Set path constants
define('CRAFT_BASE_PATH', dirname(__DIR__));
define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH.'../private_html/craft/vendor');

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

// Load dotenv?
if (file_exists(CRAFT_BASE_PATH.'../private_html/craft/.env')) {
    (new Dotenv\Dotenv(CRAFT_BASE_PATH))->load();
}

// Load and run Craft
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
$app = require CRAFT_VENDOR_PATH.'../private_html/craft/vendor/craftcms/cms/bootstrap/web.php';
$app->run();
  • Have you tried ../../ instead of ../ ? – tom Apr 7 '18 at 9:37
  • No difference I'm afraid... – noregt Apr 9 '18 at 7:33
5

Finally figured out how to edit this index.php file if you're not able to point your document root to the web folder, or if you are forced to put craft in the folder private_html that shared hosters tend to use (or any other given structure above root)

In the index.php file you only need to edit this line:

define('CRAFT_BASE_PATH', dirname(__DIR__));

If your index.php file resides in public_html, __DIR__ will be something like:

/home/hostname.com

To point the index.php to the hidden craft folder, above root, in my case I had to add the folders after the CRAFT_BASE_PATH:

define('CRAFT_BASE_PATH', dirname(__DIR__).'/private_html/craft');
  • One hopefully useful tip: when moving files around, make sure that the hidden files (esp. .env) are getting copied/moved other. 500 error would be thrown if the .env file is missing. – biko Aug 30 at 2:20

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.