Distributing Laravel Zero apps with Windows package managers
Laravel Zero supports publishing a Phar file of your application. See this blog post for details on distributing on macOS via Brew.
To get started, make sure your Phar is published to your repository, and the repository is publicly accessible. You can build a Phar of your application using the following command:
php [my-application] app:build
This blog post will cover the following package managers for Windows.
Scoop / Shovel
Scoop is a command-line application installer for Windows, and Shovel is a custom version on top of this designed to be more user-friendly and have more advanced features.
Once your Phar has been published, you'll then need to create an application manifest file using JSON. I've provided an example of a Laravel Zero application manifest below. Replace any relevant details, and make sure you fill in the SHA-256 hash if it is a tagged release. The file should be named as your application binary is.
{
"description": "A Laravel Zero app that does something",
"homepage": "https://github.com/owenvoke/my-laravel-zero-app",
"version": "1.0.0",
"license": "MIT",
"url": "https://github.com/owenvoke/my-laravel-zero-app/raw/v1.0.0/builds/my-application",
"hash": "",
"depends": [
"php"
],
"bin": [
[
"php.exe",
"my-application",
"$dir\\my-application"
]
]
}
The depends
array allows you to define a list of packages that your application depends on. Using "depends": ["php"]
will make sure that the latest stable PHP version is always installed. If your application requires a specific version of PHP (e.g. PHP 7.3), you may need to use "depends": ["[email protected]"]
.
An alternative to using the depends
array is the suggest
array. This works by naming a feature, and if any of the specified applications are installed the suggestions won't be displayed. For example, to require PHP 8.0 or later, you could use the following:
{
// ...
"suggest": {
"PHP 8 or later": ["php", "php8.0", "php8.1"]
}
}
The benefit of this method is that it will not force a specific version to be installed, for example, if the user already has PHP installed without Scoop.
You can also add the checkver
and autoupdate
sections, which allow you to automatically update the manifest with the latest version from your GitHub tags, and other methods. This is the code that would need to be added:
{
// ...
"checkver": "github",
"autoupdate": {
"url": "https://github.com/owenvoke/my-laravel-zero-app/raw/v$version/builds/my-application"
}
}
Check out the App Manifests documentation for more options that are available.
Once this manifest has been added to either the Scoop bucket repositories or your own custom repository under a bucket
directory (e.g. my bucket repository) then you can install the application via Scoop or Shovel with the following command:
scoop install my-application
Note: If you are using a custom "bucket", make sure that you have added it to your buckets by running the following command first:
$ scoop bucket add [name] [git-url]
Once installed, your application will be available as the alias value in the second key of the bin
array, and you can test it has worked successfully by running [my-application] --version
.
For an example of a formula where I have used this, see my bucket manifest for the Oh Dear CLI by Oh Dear!.