Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 762
Afraz Ahmad Avatar asked Jan 27 '26 05:01

Afraz Ahmad


2 Answers

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.

like image 192
Marcin Orlowski Avatar answered Jan 31 '26 14:01

Marcin Orlowski


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).

like image 33
VonC Avatar answered Jan 31 '26 15:01

VonC