PHPackages                             laratusk/cloudflare-tunnel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. laratusk/cloudflare-tunnel

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laratusk/cloudflare-tunnel
==========================

Start and manage Cloudflare Tunnels directly from Artisan. Supports both quick (random URL) and named (static hostname) tunnels with callback hooks.

v0.2.0(3mo ago)010↓90%1MITPHPPHP ^8.2CI passing

Since Apr 2Pushed 3mo agoCompare

[ Source](https://github.com/laratusk/cloudflare-tunnel)[ Packagist](https://packagist.org/packages/laratusk/cloudflare-tunnel)[ Docs](https://github.com/laratusk/cloudflare-tunnel)[ RSS](/packages/laratusk-cloudflare-tunnel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (9)Versions (3)Used By (0)

Cloudflare Tunnel for Laravel
=============================

[](#cloudflare-tunnel-for-laravel)

[![CI](https://github.com/laratusk/cloudflare-tunnel/actions/workflows/ci.yml/badge.svg)](https://github.com/laratusk/cloudflare-tunnel/actions/workflows/ci.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/0ebb25fe42e2d80cab2902e4eb05300a02d6e4f3bd5dd880c80fe776122df62e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6172617475736b2f636c6f7564666c6172652d74756e6e656c2e737667)](https://packagist.org/packages/laratusk/cloudflare-tunnel)[![License](https://camo.githubusercontent.com/93e77a755ff6aa143785e9e66ce6fde434aa118bf099d2ad8c24469423f06f51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6172617475736b2f636c6f7564666c6172652d74756e6e656c2e737667)](LICENSE.md)

Start and manage [Cloudflare Tunnels](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/) directly from Artisan. Expose your local Laravel application to the internet with a single command — using either a **quick tunnel** (random URL, zero config) or a **named tunnel** (static hostname, permanent URL).

```
php artisan cloudflare:tunnel
```

Features
--------

[](#features)

- **Quick tunnels** — Random `*.trycloudflare.com` URL, no account required
- **Named tunnels** — Static hostname under your own domain (e.g. `tunnel.example.com`)
- **Events** — `TunnelConnected` and `TunnelDisconnected` events for webhook registration, notifications, etc.
- **Graceful shutdown** — Clean process termination on `Ctrl+C`

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10, 11, 12, or 13
- The `pcntl` PHP extension
- The [`cloudflared`](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/) CLI binary

Installation
------------

[](#installation)

### 1. Install `cloudflared`

[](#1-install-cloudflared)

**macOS (Homebrew):**

```
brew install cloudflared
```

**Linux (Debian/Ubuntu):**

```
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt update && sudo apt install cloudflared
```

**Other platforms:** See the [official download page](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/).

Verify the installation:

```
cloudflared --version
```

### 2. Install the package

[](#2-install-the-package)

```
composer require laratusk/cloudflare-tunnel
```

### 3. Publish the config (optional)

[](#3-publish-the-config-optional)

```
php artisan vendor:publish --tag=cloudflare-tunnel-config
```

Quick Start
-----------

[](#quick-start)

### Quick Tunnel (zero config)

[](#quick-tunnel-zero-config)

Run the command with no additional setup — you get a random public URL instantly:

```
php artisan cloudflare:tunnel
```

```
 Tunnel URL: https://random-words.trycloudflare.com
 Tunnel is running. Press Ctrl+C to stop.

```

### Named Tunnel (static hostname)

[](#named-tunnel-static-hostname)

A named tunnel gives you a **permanent, predictable URL** under your own domain. Follow these steps once to set it up:

#### Step 1: Authenticate with Cloudflare

[](#step-1-authenticate-with-cloudflare)

```
cloudflared tunnel login
```

This opens your browser. Select the domain you want to use and authorize `cloudflared`.

#### Step 2: Create a tunnel

[](#step-2-create-a-tunnel)

```
cloudflared tunnel create my-app
```

Note the tunnel ID in the output — you'll see it in `cloudflared tunnel list` too.

#### Step 3: Route DNS to the tunnel

[](#step-3-route-dns-to-the-tunnel)

```
cloudflared tunnel route dns my-app tunnel.example.com
```

This creates a CNAME record pointing `tunnel.example.com` to your tunnel.

#### Step 4: Create the cloudflared config file

[](#step-4-create-the-cloudflared-config-file)

Create `~/.cloudflared/config.yml`:

```
tunnel:
credentials-file: /path/to/.cloudflared/.json

ingress:
  - hostname: tunnel.example.com
    service: http://127.0.0.1
    originRequest:
      httpHostHeader: my-app.test
  - service: http_status:404
```

> Replace `` with your actual tunnel ID. The `httpHostHeader` should match your local development domain. The credentials file path is printed when you create the tunnel.

#### Step 5: Configure the package

[](#step-5-configure-the-package)

Add to your `.env`:

```
CLOUDFLARE_TUNNEL_MODE=named
CLOUDFLARE_TUNNEL_NAME=my-app
CLOUDFLARE_TUNNEL_HOSTNAME=tunnel.example.com
```

#### Step 6: Run it

[](#step-6-run-it)

```
php artisan cloudflare:tunnel
```

```
 Tunnel URL: https://tunnel.example.com
 Tunnel is running. Press Ctrl+C to stop.

```

Configuration
-------------

[](#configuration)

Environment VariableDefaultDescription`CLOUDFLARE_TUNNEL_MODE``quick``quick` or `named``CLOUDFLARE_TUNNEL_NAME`—Named tunnel name (required for `named` mode)`CLOUDFLARE_TUNNEL_HOSTNAME`—Static hostname (required for `named` mode)`CLOUDFLARE_TUNNEL_LOCAL_URL``http://127.0.0.1`Local URL to forward traffic to`CLOUDFLARE_TUNNEL_HOST_HEADER`—Override the Host header for local requests`CLOUDFLARE_TUNNEL_TIMEOUT``30`Seconds to wait for tunnel connectionEvents
------

[](#events)

The package dispatches two events you can hook into with standard Laravel listeners:

EventPayloadWhen`TunnelConnected``string $url`, `TunnelMode $mode`After the tunnel is established`TunnelDisconnected``string $url`Before the process exits (Ctrl+C)### Example: Register a Telegram webhook

[](#example-register-a-telegram-webhook)

Create a listener:

```
php artisan make:listener RegisterTelegramWebhook --event='\Laratusk\CloudflareTunnel\Events\TunnelConnected'
```

```
namespace App\Listeners;

use Laratusk\CloudflareTunnel\Events\TunnelConnected;
use Telegram\Bot\Laravel\Facades\Telegram;

class RegisterTelegramWebhook
{
    public function handle(TunnelConnected $event): void
    {
        Telegram::setWebhook(['url' => $event->url . '/api/telegram/webhook']);
    }
}
```

```
namespace App\Listeners;

use Laratusk\CloudflareTunnel\Events\TunnelDisconnected;
use Telegram\Bot\Laravel\Facades\Telegram;

class RemoveTelegramWebhook
{
    public function handle(TunnelDisconnected $event): void
    {
        Telegram::deleteWebhook();
    }
}
```

Laravel auto-discovers listeners, so no manual registration is needed.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance82

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

91d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/755245aa5e4ba6c690b039cedcce5a86cd01b4f00d490cd71f03e6377ac302d5?d=identicon)[laratusk](/maintainers/laratusk)

---

Top Contributors

[![azer1ghost](https://avatars.githubusercontent.com/u/27803185?v=4)](https://github.com/azer1ghost "azer1ghost (4 commits)")

---

Tags

laraveldevelopmentwebhookcloudflaretunnelcloudflared

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/laratusk-cloudflare-tunnel/health.svg)

```
[![Health](https://phpackages.com/badges/laratusk-cloudflare-tunnel/health.svg)](https://phpackages.com/packages/laratusk-cloudflare-tunnel)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M184](/packages/laravel-ai)[laravel/sail

Docker files for running a basic Laravel application.

1.9k205.7M1.3k](/packages/laravel-sail)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M145](/packages/laravel-mcp)[propaganistas/laravel-disposable-email

Disposable email validator

6023.0M7](/packages/propaganistas-laravel-disposable-email)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
