Question

Exclude folders under public directory after deploy

At my Digital Ocean basic application, I used CRUD photo folder under public directory at laravel. But when I deploy the application from GitHub repo, it remove all photos and make same with my GitHub repo. Is there anyway to exclude the custom folders under public directory of laravel?


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
November 11, 2021
Accepted Answer

Hi there @rockoo,

This happens as the DigitalOcean App platform is based on Kubernetes, meaning that each deployment is a separate immutable container.

So after each redeployment, all changes to the container will be lost.

To sort this out, you need to use an Object Storage, like the DigitalOcean Spaces.

To do so, you can follow the instructions from step 5 of this tutorial here:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-scalable-laravel-6-application-using-managed-databases-and-object-storage

Basically, what you need to do is:

  • Include the additional package so that you could use the s3 driver:
composer require league/flysystem-aws-s3-v3
  • Add the following details to your .env file:
DO_SPACES_KEY=EXAMPLE7UQOTHDTF3GK4
DO_SPACES_SECRET=exampleb8e1ec97b97bff326955375c5
DO_SPACES_ENDPOINT=https://ams3.digitaloceanspaces.com
DO_SPACES_REGION=ams3
DO_SPACES_BUCKET=sammy-travellist
  • Then in your Storage config at config/filesystems.php you need to define the details for your S3 bucket as follows:
'spaces' => [
   'driver' => 's3',
   'key' => env('DO_SPACES_KEY'),
   'secret' => env('DO_SPACES_SECRET'),
   'endpoint' => env('DO_SPACES_ENDPOINT'),
   'region' => env('DO_SPACES_REGION'),
   'bucket' => env('DO_SPACES_BUCKET'),
],

Still, in the same file, locate the cloud entry and change it to set the new spaces disk as the default cloud filesystem disk:

'cloud' => env('FILESYSTEM_CLOUD', 'spaces'),
  • Then in your controllers, in order to upload an image to the DigitalOcean Space, you can do the following:
<?php
use Illuminate\Support\Facades\Storage;

   public function uploadPhoto(Request $request)
   {

       $photo->image = $request->image->store('/', 'spaces');
       Storage::setVisibility($photo->image, 'public');
       $photo->save();

       return redirect()->route('home');
   }
  • To access the images in your Blade views, you would use the following:
<img src="{{ asset('storage') . '/' . $photo->image }}" />

Once you implement the S3 driver or the DigitalOcean Space, you will have persistent storage, so when your users upload images via your app, the images will not be uploaded to the container inside the DigitalOcean App itself, but the S3 bucket, so once the container gets redeployed your images will stay intact on the object storage.

Hope that this helps. Let me know how it goes. Best, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel