Answers.Body: <p>Your answer didn't end up working for me, but I did get it working.</p>
  <ol>
  <li>Update (or add) <code>&quot;vlucas/phpdotenv&quot;: &quot;^5.0&quot;</code> to <code>composer.json</code></li>
  <li>Edit the <code>craft</code> (or <code>index</code>) file's contents:</li>
  </ol>
  <pre class="lang-php prettyprint-override"><code>// Load dotenv?
  // if (class_exists('Dotenv\Dotenv') &amp;&amp; file_exists(CRAFT_BASE_PATH.'/.env')) {
  //     Dotenv\Dotenv::create(CRAFT_BASE_PATH)-&gt;load();
  // }
  $dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
  if (file_exists(CRAFT_BASE_PATH.'/.env')) {
    $dotenv-&gt;load();
  }
  </code></pre>
  <p>I can then retrieve my environment vars with:</p>
  <pre class="lang-php prettyprint-override"><code>$varOne = $_ENV['VAR_ONE'];
  $varTwo = $_SERVER['VAR_TWO'];
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-02T11:17:02.027Z
Answers.LastActivityDate: 2020-07-02T11:17:02.027Z
Answers.UserDisplayName: Tammy Shipps
Answers.Body: <p>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.</p>
  
  <p>Simply re-installed php (with no need to uninstall anything first) then all worked perfectly after that.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-18T07:33:58.193Z
Answers.LastActivityDate: 2019-07-18T07:33:58.193Z
Answers.UserDisplayName: WillBV
Body: <p>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 &amp; 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:</p>
  
  <blockquote>
    <p>
    
    <p>// Set path constants define('CRAFT_BASE_PATH', dirname(<strong>DIR</strong>));
    define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH.'/vendor');</p>
    
    <p>// Load Composer's autoloader require_once
    CRAFT_VENDOR_PATH.'/autoload.php';</p>
    
    <p>// Load dotenv? if (class_exists('Dotenv\Dotenv') &amp;&amp;
    file_exists(CRAFT_BASE_PATH.'/.env')) {
        (new Dotenv\Dotenv(CRAFT_BASE_PATH))->load(); }</p>
    
    <p>// Load and run Craft define('CRAFT_ENVIRONMENT',
    getenv('ENVIRONMENT') ?: 'production'); $app = require
    CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php'; $app->run();</p>
  </blockquote>
  
  <p>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.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-07-16T11:02:30.333Z
Comments.Text: 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.
Comments.UserDisplayName: dmatthams
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-07-16T13:42:58.573Z
Comments.Text: 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!
Comments.UserDisplayName: WillBV
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-07-17T00:04:07.600Z
Comments.Text: @WillBV can you add that as an official answer in case it ends up helping someone in the future?
Comments.UserDisplayName: Brad Bell
Tags: <craft3><install><installation>
Title: Craft CMS 3 Installed but not working
ThreadText: # Craft CMS 3 Installed but not working
  
  (Asked by: username_0 on 2019-07-16)
  
  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.
  
  **Tags:** craft3, install, installation
  
  > **Comments:**
  > **username_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.  
  > **username_0**: 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!  
  > **username_2**: @username_0 can you add that as an official answer in case it ends up helping someone in the future?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2020-07-02. Score: 3
  
  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:
  
  ```php
  // 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')) {
    $dotenv->load();
  }
  
  ```
  
  I can then retrieve my environment vars with:
  
  ```php
  $varOne = $_ENV['VAR_ONE'];
  $varTwo = $_SERVER['VAR_TWO'];
  
  ```
  
  
  ---
  
  ### Answer by username_0 on 2019-07-18. Score: 1
  
  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.
  
  
  ---
  
  