Laravel deployment - avoid overwriting storage directory when deploying from git - laravel

I have a laravel app where users can upload images. The images are uploaded to the storage/app/public/images folder which has a symlink to public/storage
The first time i set up the project on digital ocean I use the following command to deply from github:
cd /var/www/html/quickstart
git clone https://github.com/laravel/quickstart-basic
Development and testing of the app is done locally and then pushed to github. After any patches I run the above each time to redeploy the updated application but that overwrites the storage directory.
How do I push updates to my live site from github without overwriting the storage directory?
Please note i'm not an expert on git so bear with me.
* UPDATE *
Note currently i have a gitignore file in the storage\app\ directory which has:
*
!public/
!.gitignore
There is also one inside storage\app\public\ directory which has:
*
!.gitignore

you can add the directory to .gitignore file.
like this:
/storage/app/public/images/

Related

Laravel 8 - Envoyer & Homestead Deployment Issues

So I am using Laravel Homestead for my local development. I opted to install it per-project rather than globally so that all of my Homestead configuration files would be tracked in my git repository. To keep my repository clean, I opted to place the entirety of the Laravel application into a sub-directory named 'code'.
This, however, has presented me with a challenge when attempting to deploy my application via Envoyer. It seems as though Envoyer assumes the Laravel application files are in the root directory of the repository. As such, when it attempts to deploy it fails.
I've been searching around and can't seem to find any way of specifying to Envoyer that my Laravel application files are not in the root directory of the repository but are in the 'code' directory. Any help would be greatly appreciated!
Repository Structure:
/
- Homestead related files
- /code
- Laravel application files

Laravel git ignoring images uploaded to storage

I'm running into an issue which i haven't been able to solve yet.
I was working on a laravel project and than moved this project folder to a newer version of MAMP. So far so good, everything was working fine. I just copied all the folders and files and all was good until i logged in to my laravel application on localhost and uploaded some images.
I know i can do this on my host but i like to work on localhost to add content and than push it to my prod env. Anyway, after i uploaded some images and did a git add . and commit it didnt add my uploaded images, on phpstorm they also turn out red in the storage/app/public/images folder.
On my previous mamp version everything used to work fine.
Stuff I have already tried:
I tried deleting the symlink storage folder and make a new link, didn't help.
I tried deleting the storage folder from gitignore, also didn't help.
My gitignore file looks like this:
/node_modules
/vendor
/public/hot
/public/storage
/storage/*.key
.env
.env.backup
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
/config/database.php
/public/sitemap.xml
When i login on my prod env and i upload images, they turn up fine, but i prefer sometimes to work from localhost to write content and push it to env.
I have also tried to:
git check-ignore -v -- path/to/file
To check why the file (image) is being ignored but it doesnt return anything.
I got one time a message with: Fatal: pathspec ... is beyond a symbolic link.
I hope someone can push me into the right direction. Thank you.

is it possible to copy public path from current release into next release in laravel envoyer?

I have a site that uses envoyer for deployment.
On my site users can save images/avatars/etc. These images are saved to the public path of laravel. /public/uploads/
The problem with this is that when I deploy an update, composer doesn't keep the new files in /public/uploads in the new release folder.
Is it to write a deployment script that'll copy everything from /public/uploads in the current release INTO the new release every time I push a new deployment?
Don't store them in public/uploads, store them in storage/uploads. Symlink storage/uploads to /public/uploads and move storage/uploads out of the project completely into it's own directory. Then symlink /storage/uploads to your own /storage/uploads, something like this:
ln -s /home/forge/storage/example.com/uploads /home/forge/example.com/storage/uploads
ln -s /home/forge/example.com/storage/uploads /home/forge/example.com/public/uploads
Make sure that the ownership of the new directory located at /home/forge/storage/example.com/uploads matches to your ownership of /home/forge/example.com.
This will allow persistence of storage on the device. Ensure that the symlinks are added to part of the deployment process, and you'll no longer lose your uploads each time you deploy.

laravel symlink is changed when code is pushed to live site

I am using laravel 5.5's storage symlink to store images. When I push code to the git and pull from live site then symlink path on live site becomes same as is on my local code .
My local has this symlink
storage -> /home/path/to/project/app/public/
But live site expects this symlink path
storage -> /var/www/html/website.com/public_html/project_code/storage/app/public/
Every time I have to delete symlink and create it again on live site.
I have do these steps on live site
cd public
rm storage
cd ..
php artisan storage:link
after doing these steps my symlink becomes according to live site and then it starts working.
Live site should have this symlink
storage -> /var/www/html/website.com/public_html/project_code/storage/app/public/
project_code/.gitignore :
public/storage
project_code/storage/app/.gitignore
*
!public/
!.gitignore
How I can get rid of this issue.
Thanks in advance!
As your symlink points to another location within the same project, you can safely use relative paths while linking, instead of having absolute one (which is what artisan is setting up). That would require manual linking though:
cd app/public
ln -s ../storage/app/public storage
Remove current storage symlink first if you have it already.
You might consider setting up a post-receive hook in the target Git repo (the one you are pushing to). See this one for instance.
In that hook, you can add any step you need (like fixing the symlink).

Openshift deployment is not doing what is in my local .gitignore file

I've got a line in my local .gitignore file to ignore a directory /user. I just don't want this directory to be changed in any way on the remote hosting version. People are using it to store files...
But when I push to openshift it deletes everything in that directory, instead of ignoring it. There is a mismatch now going on between git local and got remote. How can I reset what openshift is working form? Why are new files in that directory on the server being deleted, when I git push. I checked both the version of .gitignore on the local machine and on Openshift remote and they are the same. So it should ignore that directory. Damn it...
For persistent data storage, you should be using the OPENSHIFT_DATA_DIR directory. Check the Directory Environment Variables section at developers.openshift.com.

Resources