Answers.Body: <p>My guess is that your bucket doesn't have the right permissions. Try adding this permission to your bucket (use with caution since this will make the S3 100% public):</p>
  <pre><code>{
      &quot;Version&quot;: &quot;2012-10-17&quot;,
      &quot;Statement&quot;: [
          {
              &quot;Sid&quot;: &quot;PublicReadGetObject&quot;,
              &quot;Effect&quot;: &quot;Allow&quot;,
              &quot;Principal&quot;: &quot;*&quot;,
              &quot;Action&quot;: &quot;s3:GetObject&quot;,
              &quot;Resource&quot;: &quot;arn:aws:s3:::bucketname/*&quot;
          }
      ]
  }
  </code></pre>
  <p>Replace <code>bucketname</code> with your actual bucket name. You can add this policy via the AWS UI console. In S3 &gt; YourBucket &gt; Permissions &gt; Bucket Policy.</p>
  <p>If by doing this you actually manage to get URLs that resolve, then your problem are permissions. I would still delete this bucket policy and set the correct permissions for your use case.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-17T10:31:35.847Z
Answers.Text: Thanks @whosisjuan – really appreciate the lead. I gave it a go and opened up the bucket to public but unfortunately it didn't rectify things.  It appears that all problems loading seem be coming from the "assets" folder and I am getting at: Failed to load resource: the server responded with a status of 404 (Not Found). Could it be a Craft issue?
Answers.UserDisplayName: J. Ktz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-24T07:51:05.390Z
Answers.Text: Hi @whoisjuan – any further ideas? I'm completely stuck still on this.
Answers.UserDisplayName: J. Ktz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-27T17:57:22.013Z
Answers.Text: @J.Ktz I'm thinking this is a misconfiguration problem. What I would do is go to the local installation CP at Settings > Assets > Volumes, and I would delete your S3 volume and add it again. Maybe you have the wrong URL or wrong credentials.
Answers.UserDisplayName: whoisjuan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-31T13:41:13.237Z
Answers.Text: thanks for the suggestion. I tried, but it sadly wasn't the issue, though doing so pointed out the fact that the bits that aren't loading, despite being located in the assets/ folder, are not actually coming from S3, rather sitting in the craft public assets folder. So it seems the problem might not be with S3, rather the local path to the assets or permissions. I tried to changing the folder permissions on the assets folder (recursively), making sure everyone had read and write access, but that didn't do the trick. It sounds like something to do with the asset path?
Answers.UserDisplayName: J. Ktz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-02T00:10:37.377Z
Answers.Text: @J.Ktz I think the problem is then with Docker itself. Seems like Docker is preventing the write and/or blocking S3. Still could be a policy issue on S3 side (see: https://stackoverflow.com/questions/54237228/access-aws-s3-bucket-from-a-container-on-a-server)
Answers.UserDisplayName: whoisjuan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-04T00:23:13.297Z
Answers.Text: yeah it feels like Docker is often more harm than it's worth. It very well may be Docker, but i think the assets folder is probably also an issue. I have edited the question above with a lot more detail on that. Any thoughts?
Answers.UserDisplayName: J. Ktz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-17T02:50:10.297Z
Answers.LastActivityDate: 2020-07-17T02:50:10.297Z
Answers.UserDisplayName: whoisjuan
Body: <p>I'm trying to get my Craft 2 site running locally again (it worked at one point but now does not).
  I have gotten all the db related issues (seemingly) done and dusted and the admin loads fine, but it seems that anything linked to Amazon S3 (or perhaps the {{ craft.config.rootUrl }}?) seems to be failing.</p>
  <p>The devtools console has a lot of :
  <code>Failed to load resource: the server responded with a status of 404 (Not Found)</code></p>
  <p>The local set up is using docker inside a virtual machine and is brought up using vagrant. I have all the code locally tied to lvh.me (on a specific port) and when the site loads, some external services (such as Imager) are still working – just nothing relating to aws / S3 for some reason.</p>
  <p>Has anyone encountered this before? Have I forgotten to set something up re: Multi Environment variables or perhaps did Google change a policy that requires me to add permissions to the IAM user to allow for local access?</p>
  <p>Thanks in advance for any steers.</p>
  <p>Really at an impasse here. Can anyone help?</p>
  <p><strong>edit:</strong>
  After helpful comments, I am getting the impression that since the path to the root of the Assets folder is something that is controlled by the general.php file and the files that aren't loading seem to be directly inside there (and local, as opposed to on S3), that maybe this isn't an S3 issue (yet). It seems that the local path to the Assets folder is least part of the problem.<br />
  Here's what my set up in general.php looks like:</p>
  <pre><code>// $protocol = isset($_SERVER['CRAFT_PROTOCOL']) ? $_SERVER['CRAFT_PROTOCOL'] : 'https';
  $protocol = $_ENV['CRAFT_PROTOCOL'];
  // force http on local environment
  if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' ) {
      $protocol = 'http';
  }
  
  return array(
      '*' =&gt; array(
          'devMode' =&gt; false,
          'omitScriptNameInUrls' =&gt; true,
          'preserveImageColorProfiles' =&gt; true,
          'backupDbOnUpdate' =&gt; false,
          'generateTransformsBeforePageLoad' =&gt; true,
          'maxUploadFileSize' =&gt; 33554432,
          'environmentVariables' =&gt; array(
              'baseUrl' =&gt; $protocol.'://'.$_ENV['SITE_URL'].'/',
              'basePath' =&gt; $_ENV['DOCUMENT_ROOT'].'/',
              'assetsUrl' =&gt; $protocol.'://'.$_ENV['SITE_URL'].'/'
          ),
          'rootUrl' =&gt; $protocol.'://'.$_ENV['SITE_URL'],
          'siteUrl' =&gt; array(
              'en_gb' =&gt; $protocol.'://'.$_ENV['HTTP_HOST'].'/',
              'ja_jp' =&gt; $protocol.'://'.$_ENV['HTTP_HOST'].'/'
          ),
      ),
  );
  </code></pre>
  <p>Anything look out of place to anyone? The assets that won't load locally, via lvh.me, are in the *<em>public &gt; assets &gt; <em>folder</em></em> (e.g. <strong>public&gt; assets &gt; js &gt; app.js</strong>). They load fine in the staging environment, but just not locally.  It feels like either a Docker / CI issue relating to the Sandbox or just a config issue with the settings above.
  The error is a 404 not found and that URL is reading:
  <a href="http://lvh.me/assets/js/app.js?v=14" rel="nofollow noreferrer">http://lvh.me/assets/js/app.js?v=14</a></p>
  <p>What do you think?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-15T02:00:13.723Z
Comments.Text: Do you have the S3 volume set through the Control Panel?
Comments.UserDisplayName: whoisjuan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-15T15:49:32.817Z
Comments.Text: @whoisjuan thanks for the reply. Yes, it's all working as it should on staging and production (assuming you mean the craft control panel?). Everything locally matches up with what is on the servers, except obviously the base url which changes to either _localhost_ or _lvh.me_ (both running on specific ports). It just seems like for some reason the site isn't able to resolve the amazon S3 links. Other services though, such as Imager, are still delivering. Any ideas?
Comments.UserDisplayName: J. Ktz
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-17T17:04:21.263Z
Comments.Text: It feels like it might be relating to the assetsURL potentially though, looking at the assets repos locally in the Craft CP, they all have a URL Prefix corresponding to the S3 bucket. When on the server, it seems that craft is able to parse these and load from mydomain.com/assets/pathtofile, but locally this isn't the case. Do I need to change the basePath and baseURL for this to work?
Comments.UserDisplayName: J. Ktz
Tags: <craft2><multi-environment><s3><docker>
Title: Assets (in assets folder) failing to load locally [Craft 2]
ThreadText: # Assets (in assets folder) failing to load locally [Craft 2]
  
  (Asked by: username_0 on 2020-07-14)
  
  I'm trying to get my Craft 2 site running locally again (it worked at one point but now does not).
  I have gotten all the db related issues (seemingly) done and dusted and the admin loads fine, but it seems that anything linked to Amazon S3 (or perhaps the {{ craft.config.rootUrl }}?) seems to be failing.
  
  The devtools console has a lot of :
  `Failed to load resource: the server responded with a status of 404 (Not Found)`
  
  The local set up is using docker inside a virtual machine and is brought up using vagrant. I have all the code locally tied to lvh.me (on a specific port) and when the site loads, some external services (such as Imager) are still working – just nothing relating to aws / S3 for some reason.
  
  Has anyone encountered this before? Have I forgotten to set something up re: Multi Environment variables or perhaps did Google change a policy that requires me to add permissions to the IAM user to allow for local access?
  
  Thanks in advance for any steers.
  
  Really at an impasse here. Can anyone help?
  
  **edit:**
  After helpful comments, I am getting the impression that since the path to the root of the Assets folder is something that is controlled by the general.php file and the files that aren't loading seem to be directly inside there (and local, as opposed to on S3), that maybe this isn't an S3 issue (yet). It seems that the local path to the Assets folder is least part of the problem.  
  Here's what my set up in general.php looks like:
  
  ```
  // $protocol = isset($_SERVER['CRAFT_PROTOCOL']) ? $_SERVER['CRAFT_PROTOCOL'] : 'https';
  $protocol = $_ENV['CRAFT_PROTOCOL'];
  // force http on local environment
  if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' ) {
      $protocol = 'http';
  }
  
  return array(
      '*' => array(
          'devMode' => false,
          'omitScriptNameInUrls' => true,
          'preserveImageColorProfiles' => true,
          'backupDbOnUpdate' => false,
          'generateTransformsBeforePageLoad' => true,
          'maxUploadFileSize' => 33554432,
          'environmentVariables' => array(
              'baseUrl' => $protocol.'://'.$_ENV['SITE_URL'].'/',
              'basePath' => $_ENV['DOCUMENT_ROOT'].'/',
              'assetsUrl' => $protocol.'://'.$_ENV['SITE_URL'].'/'
          ),
          'rootUrl' => $protocol.'://'.$_ENV['SITE_URL'],
          'siteUrl' => array(
              'en_gb' => $protocol.'://'.$_ENV['HTTP_HOST'].'/',
              'ja_jp' => $protocol.'://'.$_ENV['HTTP_HOST'].'/'
          ),
      ),
  );
  
  ```
  
  Anything look out of place to anyone? The assets that won't load locally, via lvh.me, are in the \**public > assets > *folder** (e.g. **public> assets > js > app.js**). They load fine in the staging environment, but just not locally. It feels like either a Docker / CI issue relating to the Sandbox or just a config issue with the settings above.
  The error is a 404 not found and that URL is reading:
  <http://lvh.me/assets/js/app.js?v=14>
  
  What do you think?
  
  **Tags:** craft2, multi-environment, s3, docker
  
  > **Comments:**
  > **username_1**: Do you have the S3 volume set through the Control Panel?  
  > **username_0**: @username_1 thanks for the reply. Yes, it's all working as it should on staging and production (assuming you mean the craft control panel?). Everything locally matches up with what is on the servers, except obviously the base url which changes to either _localhost_ or _lvh.me_ (both running on specific ports). It just seems like for some reason the site isn't able to resolve the amazon S3 links. Other services though, such as Imager, are still delivering. Any ideas?  
  > **username_0**: It feels like it might be relating to the assetsURL potentially though, looking at the assets repos locally in the Craft CP, they all have a URL Prefix corresponding to the S3 bucket. When on the server, it seems that craft is able to parse these and load from mydomain.com/assets/pathtofile, but locally this isn't the case. Do I need to change the basePath and baseURL for this to work?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-07-17. Score: 1
  
  My guess is that your bucket doesn't have the right permissions. Try adding this permission to your bucket (use with caution since this will make the S3 100% public):
  
  ```
  {
      "Version": "2012-10-17",
      "Statement": [
          {
              "Sid": "PublicReadGetObject",
              "Effect": "Allow",
              "Principal": "*",
              "Action": "s3:GetObject",
              "Resource": "arn:aws:s3:::bucketname/*"
          }
      ]
  }
  
  ```
  
  Replace `bucketname` with your actual bucket name. You can add this policy via the AWS UI console. In S3 > YourBucket > Permissions > Bucket Policy.
  
  If by doing this you actually manage to get URLs that resolve, then your problem are permissions. I would still delete this bucket policy and set the correct permissions for your use case.
  
  > **Comments:**
  > **username_0**: Thanks @whosisjuan – really appreciate the lead. I gave it a go and opened up the bucket to public but unfortunately it didn't rectify things.  It appears that all problems loading seem be coming from the "assets" folder and I am getting at: Failed to load resource: the server responded with a status of 404 (Not Found). Could it be a Craft issue?  
  > **username_0**: Hi @username_1 – any further ideas? I'm completely stuck still on this.  
  > **username_1**: @username_0 I'm thinking this is a misconfiguration problem. What I would do is go to the local installation CP at Settings > Assets > Volumes, and I would delete your S3 volume and add it again. Maybe you have the wrong URL or wrong credentials.  
  > **username_0**: thanks for the suggestion. I tried, but it sadly wasn't the issue, though doing so pointed out the fact that the bits that aren't loading, despite being located in the assets/ folder, are not actually coming from S3, rather sitting in the craft public assets folder. So it seems the problem might not be with S3, rather the local path to the assets or permissions. I tried to changing the folder permissions on the assets folder (recursively), making sure everyone had read and write access, but that didn't do the trick. It sounds like something to do with the asset path?  
  > **username_1**: @username_0 I think the problem is then with Docker itself. Seems like Docker is preventing the write and/or blocking S3. Still could be a policy issue on S3 side (see: https://stackoverflow.com/questions/54237228/access-aws-s3-bucket-from-a-container-on-a-server)  
  > **username_0**: yeah it feels like Docker is often more harm than it's worth. It very well may be Docker, but i think the assets folder is probably also an issue. I have edited the question above with a lot more detail on that. Any thoughts?  
  
  ---
  
  