Assets (in assets folder) failing to load locally [Craft 2]

Craft CMS Asked by J. Ktz on August 29, 2020

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 (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?

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'] == '' ) {
    $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, 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:

What do you think?

One Answer

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.

Answered by whoisjuan on August 29, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP