Report this

What is the reason for this report?

Asset files not getting loaded.

Posted on November 6, 2020

I have followed the tutorial and installed latest version of laravel with docker. The problem is asset files are not getting uploaded while I have given the correct path for it.

Please help me with this?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @humblecoder,

Can you confirm if you followed this tutorial :

https://www.digitalocean.com/community/tutorials/how-to-install-and-set-up-laravel-with-docker-compose-on-ubuntu-20-04

Additionally, I’m not sure which asset files are you referring to exactly. Can you please provide with as much information as possible in order to provide you with a more accurate answer?

Regards, KFSys

**code**

A quick update if anyone stumbles upon this:

If your Laravel application running in Docker is not serving or uploading asset files correctly, it could be due to misconfiguration of your Docker setup, Laravel configuration, or file permissions. Here’s a step-by-step guide to troubleshoot and resolve this issue:


1. Check Laravel’s Asset Configuration

Ensure that Laravel is set up to handle assets correctly:

  • Verify the public_path() points to the correct directory (/var/www/html/public in most Docker setups).
  • If you’re using Storage::put() or a similar function, ensure the storage symlink is created:
php artisan storage:link
  • This creates a symbolic link from storage/app/public to public/storage.

2. Verify Docker Volume Mounts

Check your Docker Compose file (or docker run command) to ensure the correct directories are mounted into the container:

volumes:
  - ./your-laravel-project:/var/www/html
  - ./your-laravel-project/public:/var/www/html/public
  • The ./your-laravel-project/public directory should be accessible for serving files.

3. Check File Permissions

Ensure the web server in your Docker container has the correct permissions to write and serve files:

# Inside the container
sudo chmod -R 775 /var/www/html/storage
sudo chmod -R 775 /var/www/html/public
sudo chown -R www-data:www-data /var/www/html/storage /var/www/html/public

4. Nginx/Apache Configuration

If you’re using Nginx or Apache in your Docker setup:

  • Ensure the public directory is set as the root. Example for Nginx:
server {
    root /var/www/html/public;
    index index.php index.html;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass php-fpm:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
    }
    location ~ /\.ht {
        deny all;
    }
}
  • Confirm that your container’s web server can serve static files (CSS, JS, images) from public.

5. Environment Variables and .env

Ensure the APP_URL in your .env file matches your application’s URL (e.g., http://localhost or the IP address of your droplet).

If you are using Laravel’s storage, verify that the filesystem is set correctly:

FILESYSTEM_DRIVER=local

6. Clear Cache and Restart Services

Clear any cached configurations and restart services:

php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.