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

sebastiansulinski's avatar

Deploying with the 'media' directory unaffected

Is there a way of having a certain directory in the current directory unaffected by the new versions being deployed?

I'm working on the CMS - which is already live and client is uploading lots of content such as images, pdf files etc. All these files are going into the current/media directory.

If I exclude it from commits - then the directory will be removed completely - if on the other hand I leave it included - it will overwrite it with every deployment.

I'm sure there is an easy fix for that, but I just don't know what it is - any help would be greatly appreciated.

0 likes
7 replies
mstnorris's avatar

Have a look at how Laravel Envoyer does this with the storage directory. I think your best bet is to symlink that directory to another one outside your version control.

sebastiansulinski's avatar

I was considering symlinking, but would prefer more direct / clean approach to it - if project has to be moved anywhere else then symlinking will have to be re-done - another unnecessary step, which I would prefer to avoid. I wish Envoyer would have an option to exclude certain paths from being overwritten under the current directory structure - the project I'm currently working on is built using custom framework - not Laravel.

mstnorris's avatar

I'll be honest with you, symlinking is going to be one of (if not the) cleanest way to do it. It is how Forge does it, I don't see that as an issue.

symlink your current/media directory to storage/media. What is the issue?

sebastiansulinski's avatar

It seem to be the only option - just had a reply from Taylor - it's Manage Linked Folders under Development Hooks tab. The only problem with it is - as already explained - when you want to move project across to a different server - it just adds to the list of tasks you have to remember about. Anyway - if that's the only option then that's it.

pmall's avatar

Remove this directory from git, thats all. So when you pull files on the server, the media folder on the server is untouched.

sebastiansulinski's avatar

It will be removed when you deploy - everything is overwritten with the new version. Don't worry - as you can see we've already found the answer.

pmall's avatar

everything is overwritten with the new version

No, if you pull files from a git repo and this folder is not tracked, it wont be erased.

Please or to participate in this conversation.