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

cbil360's avatar

Using the same vendor directory for multiple projects

I am using wamp stack and facing issue of doing a composer install(ok I konw that's what composer is for) in every git project I checkout to my www directory.
I am fine to do it if I am switching from L5 to L5.1 as there are major updates,but for all L5 projects how can I refer to the same vendor directory?
This is time-consuming as many projects have too many packages,so how can we have a central repo of vendor folder and refer the same from all projects?
Sorry if the question is already raised I did a google search and also a forum search but couldn't find a relevant answer.

0 likes
3 replies
willvincent's avatar
Level 54

If the only thing you need/want to share between them is the vendor directory, you could simply create symlinks in each project except whatever the main one is that actually has the vendor directory.

So, for example:

cd /var/www/SiteA
composer install
# git clone new project into /var/www/SiteB
cd ../SiteB
# If vendor directory is already there, delete it: rm -rf vendor
# create symlink to Site A's vendor directory
ln -s /var/www/SiteA/vendor

Unless you know for sure that all projects are definitely going to share exactly the same versions of packages though, this probably isn't a good plan.

If you're wanting to share more or less the whole codebase, you'll want to research building a multi-tenant application with laravel.

2 likes
bobbybouwmann's avatar

Like @willvincent mentioned this is not a good idea. Let's say you haven't worked on one of your projects for a month and some package decides to update something. You will notice this change on your current project, but the vendor directory of the project of a month is also updated and might throw errors on the update!

What you can do is create a generic composer.json file and reuse that on your projects. Composer is smart enough to cache the already downloaded package, so you should be good to go and create more projects faster using the same composer.json file

cbil360's avatar

@willvincent I think this should work,actually I would like to use it more on the test servers which will have replications of the same application for different features.Also,the space there is a problem with limited storage,vendor would consume additional space. I have two copies of the same application one in var/www/siteA/ and other in var/www/html/siteB. I believe symlink should solve my problem.
But on my local windows environment as @bobbybouwmann pointed will have issues with it.I will carry on the traditional way on local and implement the solution for my test server.
Thank you

1 like

Please or to participate in this conversation.