I have a remote repository with a Craft install and am trying to pull it to a new environment. I run the composer install and Craft & other packages install seemingly correctly, added the .env file and set up the Apache server to point to the /web folder. When I load up the url I get a visual of the index.php file:

// Set path constants define('CRAFT_BASE_PATH', dirname(DIR)); define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH.'/vendor');

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

// Load dotenv? if (class_exists('Dotenv\Dotenv') && 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();

No urls seem to be working e.g. /admin or /index.php?p=admin/install and I can even put anything as the url and nothing errors, just shows this file still.

  • 1
    If the PHP code is getting rendered as HTML then it seems like this is a server issue, is PHP definitely installed? You could create a PHP file with <?php phpinfo(); ?> in to check.
    – dmatthams
    Commented Jul 16, 2019 at 11:02
  • Yep this was it, somehow my new server config had php there and responded with "php -v" but wasn't actually installed, just ran the install for it and works now, thanks!
    – WillBV
    Commented Jul 16, 2019 at 13:42
  • @WillBV can you add that as an official answer in case it ends up helping someone in the future?
    – Brad Bell
    Commented Jul 17, 2019 at 0:04

2 Answers 2


Your answer didn't end up working for me, but I did get it working.

  1. Update (or add) "vlucas/phpdotenv": "^5.0" to composer.json
  2. Edit the craft (or index) file's contents:
// Load dotenv?
// if (class_exists('Dotenv\Dotenv') && file_exists(CRAFT_BASE_PATH.'/.env')) {
//     Dotenv\Dotenv::create(CRAFT_BASE_PATH)->load();
// }
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
if (file_exists(CRAFT_BASE_PATH.'/.env')) {

I can then retrieve my environment vars with:

$varOne = $_ENV['VAR_ONE'];
$varTwo = $_SERVER['VAR_TWO'];

Now fixed, turns out that with my server config that copied across php was there and appeared to be installed when viewing the version with the command 'php -v' and enabled with 'a2enmod php7.x' but wasn't in fact installed.

Simply re-installed php (with no need to uninstall anything first) then all worked perfectly after that.

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.