How to move Laravel storage from one server to another

Dr. Adam Nielsen
2 min readOct 20, 2023

Assume you have a Laravel application with a huge storage folder, which is directly on your server (local file storage). This document explains how to move the files from your current server to a new one, with minimal maintenance mode time.

Step 1: Zip storage folder

SSH into your server and zip your storage/app folder.

tar -cf storage-app.tar storage/app

The flagg c means a new tar archive will be created and -f means we want to specify the filename (which we did with storage.tar).

We intentionally did not use zip or gzip, because that would compress the storage file. At this step, we are only concerned about bundling it, because we may have a huge set of files here, and compressing could take ages, depending on your storage.

You can compress the .tar file afterwards if you have the need to do so:

gzip mydata.ta

Step 2: Transfer file:

scp mydata.tar.gz user@destination-server:/path/to/destination/

Step 3: Unzip at destination server

Now go to your new Laravel application. Untar like this:

tar -xf storage-app.tar

All files that already exists in /storage/app will be overwritten, if they existis in storage-app.tar

If you want to be warned about overwriting files, you may use

tar -xf /path/to/storage-app.tar --keep-old-files

Step 4: Set status at your current server at Maintenance

Move your current application to maintenance. If you have a public website and a dashboard, its probably enough to just disable the dashboard. The goal here is to avoid having new files in your storage folder.

Step 5: Resync remaining files

From the time you copied till you hit the maintenance mode, there may have been new files been received. To get them aswell, resync them using this command:

rsync -avz /path/to/your/website user@destination-server:/path/to/destination/

Step 6: Update DNS settings

Now change DNS settings, so that your new website will become eventually online.

Final Remark

A lot of hustle right? How about you use some external storage? If you had an external service for hosting your files, you would not need all of this.

I am not getting any money of this. So here are the two services that I found the cheapest for my use case:

Cloudflare is for free for the first 10 GB. Bunny starts with 0.1$ per month for the first 10 GB.

--

--