Persisting the Storage Folder
The storage folder by default, holds several "generated" essentials of your Laravel application.
It's the default burrow for session, cache, and file data amongst others. If you'd opt to persist data on this folder, you'll have to mount a volume to it.
Make sure you are in your Laravel Fly App's directory
Create a volume, you'll be attaching this later to your Laravel Fly App's storage directory
fly volumes create storage_vol --region ams --size 20
Revise your Laravel Fly App's
fly.tomlfile to mount the volume created for your storage directory, and connect with an sqlite database you'll be configuring further down below:
[mounts] source="storage_vol" destination="/var/www/html/storage"
To fix the little storage-content-erasure issue as stated in the callout above, please go ahead and make a copy of your storage folder in a "backup" folder. You can name this directory "storage_".
cp -r storage storage_
You'll later use this folder to copy over its contents to the volumized storage folder.
Next create a Startup Script that will initialize the volumized storage folder's contents.
Side Note: Start up scripts are run in numeric-alphabetical order. Naming
1_storage_init.shmakes sure it is the first script run. Otherwise, naming the file as
storage_init.shalone would've moved the
caches.shscript above it, and would've executed before storage initialization happened. One of the commands in the
caches.shwill not have worked properly, due to a lack of properly initialized storage directory.
On to the content of the Start Up script:
FOLDER=/var/www/html/storage/app if [ ! -d "$FOLDER" ]; then echo "$FOLDER is not a directory, copying storage_ content to storage" cp -r /var/www/html/storage_/. /var/www/html/storage echo "deleting storage_..." rm -rf /var/www/html/storage_ fi
So what happened above?
- The condition statement checks if the app folder does not exist in the volumized storage folder. If it does not exist, it copies over the contents of the storage_ folder to the volumized storage folder.
Finally, deploy your Laravel Fly App!