I am using cPanel on a live server and want to install a new craft4 project in a subdomain for testing instead of having a local dev setup on my computer. I have done this many times for craft 2 and 3. I usually create a folder on the server named "test" for example, and in that folder I would have 2 folders named public_html and craft. I would move all the contents of the web folder into public_html and the rest into the craft folder. The subdomain root would point to /test/public_html.

My other Craft3 sites, in the index.php in the web (or public_html) folder had a section for defining path constants. This is what I have in that file:

define('CRAFT_BASE_PATH', dirname(__DIR__,1).'/craft');
define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH . '/vendor');

The knowledgebase on the Craft site has a page, "Moving Craft’s Files Below the Webroot". This tells you to find the line "define('CRAFT_BASE_PATH', dirname(DIR));" and to change it. But there is no such line in the Craft 4 /web/index.php file. I know I'm not moving the app folder below root, more like above it,

What should my index.php file look like? Are there any other files that need editing?

1 Answer 1


The solution I finally worked out is that the index.php file in the web folder needs to be edited in the following way. The default code is:

require dirname(__DIR__) . '/bootstrap.php';

You need to change this to:

require dirname(__DIR__,1) . '/***/bootstrap.php';

The *** should be replaced by the name of the folder that the bootstrap file is in. The ,1 is how many levels to up in the folder structure from where the index.php is located. In my case the 2 folders are in the same parent folder, so it just need to go up 1 level top find the *** folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.