kieranbrown / laraworker
Run Laravel on Cloudflare Workers via php-cgi-wasm
Package info
github.com/kieranbrown/laraworker
Language:JavaScript
pkg:composer/kieranbrown/laraworker
Requires
- php: ^8.5
- illuminate/console: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.27
- orchestra/testbench: ^10.0
- pestphp/pest: ^3.0
- dev-main
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/composer/composer-bc2e42b409
- dev-release-please--branches--main
- dev-epic/performance-memory-optimizations-e-7205b8
- dev-epic/fix-memory-regression-opcache-0-e-ec3148
- dev-feat/demo-live-opcache-stats
- dev-epic/fix-ci-pipeline-failures-e-e957c7
- dev-epic/improve-wasm-memory-efficiency-to-e-422e63
- dev-epic/isolated-playground-deployments-with-automatic-e-fb1dfd
- dev-epic/fix-inertia-link-support-e-792604
- dev-epic/showcase-demo-app-for-laraworkerkswbdev-e-a29302
- dev-epic/opcache-sapi-lifecycle-fix-e-63b7fd
- dev-epic/static-assets-opcache-performance-e-6db597
- dev-epic/fix-ci-build-pipeline-and-e-75b83c
This package is auto-updated.
Last update: 2026-04-19 22:57:40 UTC
README
Deploy Laravel applications to Cloudflare Workers via PHP WASM.
Laraworker packages your Laravel app into a compressed tar archive, then runs it on Cloudflare Workers using php-cgi-wasm. On each request, the Worker unpacks the app into an in-memory filesystem and processes it through the PHP WASM runtime — no traditional server required.
Requirements
- PHP 8.5+
- Laravel 12
- Node.js or Bun
- A Cloudflare account
Installation
composer require kieranbrown/laraworker
Then run the install command to configure your project:
php artisan laraworker:install
This will:
- Publish the
config/laraworker.phpconfiguration file - Add build scripts and dependencies to
package.json - Update
.gitignoreto exclude the.laraworker/build directory - Install npm dependencies (
php-cgi-wasm,wrangler, etc.) - Run an initial build into
.laraworker/
Configuration
After installation, configure your setup in config/laraworker.php:
return [ // PHP extensions to include in the WASM bundle 'extensions' => [ 'mbstring' => true, // ~742 KiB gzipped 'openssl' => true, // ~936 KiB gzipped ], // Directories included in the app bundle (relative to project root) 'include_dirs' => [ 'app', 'bootstrap', 'config', 'database', 'routes', 'resources/views', 'vendor', ], // Individual files to include 'include_files' => [ 'public/index.php', 'artisan', 'composer.json', ], // Regex patterns for files to exclude 'exclude_patterns' => [ '/\.git\//', '/\/node_modules\//', '/\/tests\//', // ... ], ];
Wrangler Configuration
Deployment settings like worker_name, account_id, and compatibility_date are configured in config/laraworker.php. The wrangler.jsonc is auto-generated into .laraworker/ at build time from these config values.
Usage
Laraworker provides five Artisan commands:
laraworker:install
Configure the project for Cloudflare Workers and run an initial build.
php artisan laraworker:install
php artisan laraworker:install --force # Overwrite existing files
laraworker:build
Build the Laravel application for production deployment. Caches config, routes, and views, then packages everything into app.tar.gz.
php artisan laraworker:build
laraworker:dev
Build and start a local development server using wrangler dev.
php artisan laraworker:dev
laraworker:deploy
Build and deploy to Cloudflare Workers.
php artisan laraworker:deploy
php artisan laraworker:deploy --dry-run # Build without deploying
laraworker:status
Check installation status, bundle sizes, and tier compatibility.
php artisan laraworker:status
How It Works
- Build — Your Laravel app is optimized (cached config/routes/views, classmap autoload) and packaged into a compressed
app.tar.gz - Deploy — The archive and PHP WASM binary are deployed to Cloudflare Workers as static assets
- Request — On cold start, the Worker fetches
app.tar.gz, unpacks it into an in-memory filesystem (MEMFS), and boots the PHP runtime - Process — Each HTTP request is routed through
php-cgi-wasm, which executes your Laravel application and returns the response
The entire bundle (WASM binary + app archive + Worker code) fits within Cloudflare Workers' free tier limit of 3 MB.
Custom Domain Setup
To serve your app from a custom domain, configure your Cloudflare account with the domain and set up routes. The wrangler.jsonc is auto-generated at build time from config/laraworker.php — for advanced wrangler settings, you can customize the stubs/wrangler.jsonc.stub template.
Make sure your domain is added to your Cloudflare account and DNS is configured.
Extensions
Two PHP extensions can be toggled in config/laraworker.php:
| Extension | Default | Size Impact |
|---|---|---|
mbstring |
Enabled | ~742 KiB gzipped |
openssl |
Enabled | ~936 KiB gzipped |
Disabling unused extensions reduces your bundle size, which can help stay within Cloudflare's tier limits.
License
Laraworker is open-sourced software licensed under the MIT license.