Installation:
composer require tunnelhunt/laravel-tunnelhunt
No manual service provider registration needed (auto-discovered).
First Use Case: Test webhooks (e.g., Telegram, Stripe) or share a live demo without deploying. Run:
php artisan serve:tunnel
http://127.0.0.1:8000) and public tunnel URL (e.g., http://a1b2c3d4.tunnelhunt.ru).Where to Look First:
php artisan serve:tunnel --help for options.Local Development + Public Access:
serve:tunnel during feature development requiring external API calls (e.g., payment gateways).php artisan serve:tunnel --port=8080 --plan=pro
8080 with a pro plan tunnel.http://<random>.tunnelhunt.ru with stakeholders for testing.CI/CD Integration:
# .github/workflows/test.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: php artisan serve:tunnel --port=8000 &
- run: sleep 30 # Wait for tunnel to stabilize
- run: curl http://$(php artisan serve:tunnel --url) # Fetch public URL
Environment-Specific Config:
.env (not natively supported; use custom config):
// config/tunnelhunt.php
return [
'default_port' => env('TUNNELHUNT_PORT', 8000),
'default_plan' => env('TUNNELHUNT_PLAN', 'nokey'),
];
php artisan serve:tunnel --port=$TUNNELHUNT_PORT
Webhook Testing:
Log::info() to verify incoming requests in routes/web.php:
Route::post('/webhook', function () {
Log::info('Webhook received', ['data' => request()->all()]);
});
HTTPS:
php artisan serve:tunnel --port=8000 --host=0.0.0.0
Then access via https://<tunnel-url>.Long-Running Processes:
nohup or screen to keep the tunnel alive after closing the terminal:
nohup php artisan serve:tunnel --port=8000 > tunnel.log 2>&1 &
SSH Dependencies:
ssh: command not found.PATH. On macOS/Linux:
which ssh # Should return /usr/bin/ssh
Port Conflicts:
Address already in use if port 8000 is occupied.php artisan serve:tunnel --port=8080
Tunnel Stability:
nokey plan tunnels may drop after inactivity.--plan=pro for persistent tunnels or ping the endpoint periodically:
watch -n 5 "curl -s http://$(php artisan serve:tunnel --url)"
Firewall/Network Restrictions:
tunnelhunt.ru (port 2222).SSH Verbose Mode: Enable debug logs to troubleshoot connection issues:
php artisan serve:tunnel --debug
Connection refused or Permission denied.Public URL Extraction: If the URL isn’t auto-detected, parse SSH output manually:
php artisan serve:tunnel 2>&1 | grep "Your public URL is"
Plan Limitations:
nokey: Free but less reliable (random URLs, no persistence).pro: Requires a paid TunnelHunt account (contact support for credentials).Host Binding:
0.0.0.0 exposes the server to LAN. Use cautiously:
php artisan serve:tunnel --host=0.0.0.0
Custom SSH Commands:
Override the SSH command in the service provider (app/Providers/TunnelHuntServiceProvider.php):
protected function getSshCommand(): string
{
return 'ssh -R 80:localhost:'.$this->port.' -p 2222 custom@tunnelhunt.ru';
}
Post-Tunnel Hooks:
Extend the command to run tasks after tunnel creation (e.g., update .env):
// app/Console/Commands/ServeTunnel.php
protected function handle()
{
$url = $this->getPublicUrl();
file_put_contents('.env', "TUNNEL_URL={$url}\n", FILE_APPEND);
}
URL Validation: Add validation to ensure the tunnel URL is reachable:
public function isUrlReachable(string $url): bool
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
return curl_errno($ch) === 0;
}
How can I help you explore Laravel packages today?