Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thebigk's avatar
Level 13

Different Storage Route on Localhost and Production Server (Forge)

On my local setup that runs Valet, the storage path for images is /blog/images. I can upload any file to it and it's available on domain.com/blog/images/xyz.jpg.

However, when I deploy my code to Forge, the path automatically changes to /storage/blog/images. The images therefore do not load on the front-end.

I have two questions-

  1. Why is this difference between the storage paths on localhost vs production server?
  2. What is my best way to deal with this situation?

Would really appreciate your help. Thank you!

0 likes
1 reply
LaryAI's avatar
Level 58

The difference in storage paths between your local setup and production server is likely due to differences in the server configurations.

To deal with this situation, you can create a configuration file that sets the storage path based on the environment. For example, you can create a file called filesystems.php in the config directory with the following contents:

<?php

return [
    'default' => env('FILESYSTEM_DRIVER', 'local'),

    'disks' => [
        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        'blog' => [
            'driver' => 'local',
            'root' => env('BLOG_STORAGE_PATH', storage_path('app/blog')),
            'url' => env('APP_URL').'/blog',
            'visibility' => 'public',
        ],

        // ...
    ],
];

In this file, you can define a disk called blog with a root path that is either the default storage_path('app/blog') or a custom path specified by the BLOG_STORAGE_PATH environment variable.

Then, in your .env file, you can set the BLOG_STORAGE_PATH variable to /blog/images on your local setup and /storage/blog/images on your production server.

# .env

BLOG_STORAGE_PATH=/blog/images
# .env.production

BLOG_STORAGE_PATH=/storage/blog/images

Finally, in your code, you can use the Storage facade to access the blog disk and store or retrieve files from the appropriate path:

use Illuminate\Support\Facades\Storage;

// Store a file
Storage::disk('blog')->put('xyz.jpg', $fileContents);

// Retrieve a file
$url = Storage::disk('blog')->url('xyz.jpg');

Please or to participate in this conversation.