Migrate Laravel to Railway (with Storage)

robzlabz
HOBBY

21 days ago

Hi, i want to migrate my vps into railway beccause it was very easy to use and deploy. but i have one problem that my images are save on app/storage/ folder, so i need to move files into storage. do you have any idea how to upload files into storage? i think that i can upload with some image and then reattach to my laravel volumes, bu ti dont know how

Solved$10 Bounty

5 Replies

robzlabz
HOBBY

21 days ago

8d515ec7-5921-444d-afc6-12a63a8fe7d1


mycodej
HOBBYTop 10% Contributor

21 days ago

Hey robzlabz,

By default, files written to app/storage in a Railway container won’t persist across deploys, since the filesystem is ephemeral. You have two straightforward options to keep your uploads safe:

1) Attach a Railway Volume

Railway supports block storage volumes that can be mounted into your container. Simply add a Volume plugin to your Laravel service and configure it like this:

  1. In the Railway project dashboard, open the command palette (⌘ K or right-click) and choose Add Plugin → Volume, then select your Laravel service.

  2. Mount the Volume at /app/storage/app/public—that’s where Laravel’s default “public” disk writes its files.

  3. Ensure the public/storage symlink exists by running php artisan storage:link in a build or post-deploy step.

  4. Redeploy. Now calls to Storage::disk('public')->put(...) will write into the attached Volume and survive future deploys.

This keeps your storage setup almost identical to what you’d have on a VPS.

2) Use an S3-Compatible Object Store (However I would recommend this approach for production)

For greater scalability and reliability, point Laravel’s filesystem at an S3-compatible service (AWS S3, DigitalOcean Spaces, Cloudflare R2, Backblaze B2, etc.):

  1. Create a bucket and obtain access credentials from your chosen provider.

  2. In your .env file, set:

    FILESYSTEM_DRIVER=s3
    AWS_ACCESS_KEY_ID=your_key
    AWS_SECRET_ACCESS_KEY=your_secret
    AWS_DEFAULT_REGION=your_region
    AWS_BUCKET=your_bucket
    AWS_URL=https://your-bucket.s3.amazonaws.com
  3. Add those environment variables in Railway under Project → Variables.

  4. In your application, store uploads with:

    Storage::disk('s3')->putFile('images', $request->file('avatar'));

Files written to the S3 disk remain safe regardless of how many times you redeploy or scale your containers.

Either mounting a Volume or using an S3-style disk will prevent uploaded images from disappearing after a deploy. Choose the Volume approach for a quick lift-and-shift, or switch to S3 storage for a production-ready solution.

Let me know if you need help with the mount configuration or environment variables!


yogia17
HOBBY

19 days ago

Hi, you can try add new "Filebrowser" app from template and then use this environtment USE_VOLUME_ROOT=1 then remove default storage that included in instalion with storage that use for laravel project. After login on Filebrowser you can upload all your files there. Please note that you must set month path correctly like /app/storage on volumes Mounth Path. Good luck!


robzlabz
HOBBY

18 days ago

nice, thanks for all, i will check all of your solution!


robzlabz
HOBBY

18 days ago

@mycodej change to s3 bucket is good choice but there is to many database need to be updated for migration, and thanks to @yogia17. itry to use file browser and success upload on /app/storage folder with that app. Mount and Unmount Volume is best choice for me for now. thanks all


mycodej
HOBBYTop 10% Contributor

18 days ago

Hey robzlabz, glad to hear you're making progress! Using Filebrowser to upload directly into /app/storage and managing everything via Volumes sounds like a solid approach, especially if switching to S3 would mean too much database migration work right now. Looks like you've found a setup that fits—good luck with the rest of the move!


Status changed to Solved chandrika 18 days ago


Migrate Laravel to Railway (with Storage) - Railway Help Station