Search code examples
laravel-5storagesymlinkgitignore

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!


Solution

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