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

drewjo's avatar

Handling uploaded local files with Envoy.

I successfully migrated a Laravel 4 site over to deploy with Envoyer.io, really awesome!

The one thing I didn't account for, is we have files uploaded through an admin, but this throws a little wrench in everything. Since these files are in public/site/uploads, each deployment clears this directory out.

What's the proper way to handle this? (Without saving files to S3, etc... this is a small website, a very specific target, they don't need anything too fancy) :)

0 likes
6 replies
dertechniker's avatar

Why not move the uploaded files in a folder in the root (so your root contains your /public folder from laravel and a /uploaded folder) and then symlink /public/site/uploads to /uploads ?

1 like
toddvalentine's avatar

Just stumbled upon this same issue. Is there any way to prevent envoyer from overwriting existing files in public/img/uploads?

michaeldyrynda's avatar
Level 41

@toddvalentine, as @dertechniker suggests, anything you don't want to blow away on a fresh deploy you should move out of your release structure and symlink it in when you're done.

current -> releases/20150323231010
storage/
    app/
    framework/
    logs/
releases/
    20150323230130/
    20150323230745/
    20150323231010/
    20150324034448/
uploads/

When you're making a deploy, blow away the directory structure in your release and symlink in the external uploads folder:

cd releases/20150324034448
rm -rf public/img/uploads/
ln -nfs ../../../../uploads public/img/uploads

Instead of back references, it might be cleaner to use a full path reference, but that'll depend on your filesystem structure and is up to you.

4 likes
drewjo's avatar

Thanks guys! Just a final update, in Envoyer.io, I added a Deployment Hook for Before Activate New Release with:

cd {{release}}
rm -rf uploads/
ln -nfs ../../uploads ./uploads

I have a uploads directory in the root of my repo, and I created the uploads directory in the root of the site directory (this is one level up from my repo, or "release").

I think I was ultimately trying to avoid having any manual work be part of this process. But the only thing I had to do manually was create the uploads directory that everything gets symlinked to.

I didn't put a symlink in my repo, because for local testing, I don't want it to point to an uploads directory that is outside my project. :)

Swaz's avatar

@deringer Why do you back reference 4 times here? ln -nfs ../../../../uploads If you are in the releases directory shouldn't you only have to back reference twice? I am trying to do this myself and this part doesn't make any sense to me.

michaeldyrynda's avatar

@Swaz - it depends on where your uploads are. @drewjoh said that his uploads dir was in public/site/uploads so to get to your uploads which is in the base directory, you'd have to drop down 4 directories.

As I wrote, you'd more likely symlink the full path; on a default forge install you'd use:

cd /home/forge/releases/20150324034448
rm -rf public/site/uploads
ln -nfs /home/forge/default/uploads public/site/uploads

Please or to participate in this conversation.