How to Install a Composer package from a local zip

Nov 8, 2021 composer laravel php
This post is more than 18 months old. Since technology changes too rapidly, this content may be out of date (but that's not always the case). Please remember to verify any technical or programming information with the current release.

I use Laravel Nova in a lot of my projects, but I’ve never liked the idea of storing the files in a local directory after download. Yes, you can use credentials for a Composer-based install, true, but I wanted something that didn’t require that. Turns out you can install packages like Laravel Nova from a zip file locally. Here’s how.

First of all, I should say that this is all covered in the Composer repositories documentation section - but I never fully put it all together. Maybe this example will save you some time as well.

Now, get your zip file that is in the format of a Composer repository source. This means it has a composer.json file in its root directory. I downloaded one from Nova’s downloads, but you might also find these in the releases of Github projects.

Store that in some place that’s in your project but out of your normal browsing / searching. (I didn’t like unzipping the Nova project into my project source code because my IDE would find multiple copies of the same file. I could have filtered that out, but I think this is better.) I’m placing my file at /packages/ in my Laravel project. This is the same level as /app or /tests folders.

Finally, you need to modify or add a section to your composer.json file like so:

"repositories": [
    "type": "artifact",
    "url": "./packages"

This is in the top level. Now, Composer knows to check for artifacts and will install from that directory if it can find it.

So, now it’s simple:

composer require laravel/nova

And we’re good to go.

Looking for more Laravel Tips & Tricks? Join Joel and I on the No Compromises bi-weekly podcast; around 15 minutes of thoughtful real-world advice and helpful info.
Go to All Posts