Download the PHP package artemyurov/laravel-autossh-tunnel without Composer

On this page you can find all versions of the php package artemyurov/laravel-autossh-tunnel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-autossh-tunnel

Laravel AutoSSH Tunnel

Modern SSH Tunnel Manager for Laravel with autossh support and automatic lifecycle management.

Features

Installation

Publish Configuration

After publishing, copy the tunnel environment variables to your .env:

Configuration

Environment Variables

The configuration uses a clear logical order:

  1. SSH Connection - How to connect to the SSH server
  2. Remote/Local - What to forward and where
  3. SSH Options - Connection behavior settings

Configuration File

After publishing the config, edit config/tunnel.php:

Multiple Connections Example

For multiple tunnel connections, use unique prefixes for each connection:

Tunnel Types

The package supports two types of SSH tunnels:

Forward Tunnel (-L) - Access Remote Services

Forward tunnels allow you to access remote services from your local machine.

SSH Command:

Use Cases:

Example:

Reverse Tunnel (-R) - Expose Local Services

Reverse tunnels expose your local application to a remote server, making it accessible from the internet.

SSH Command:

Important: remote_host is the bind address on the remote server:

Use Cases:

Example:

Usage

Callback Pattern (Recommended)

Automatic tunnel closure after execution:

With Laravel Database Integration

Manual Management

Multiple Tunnels Simultaneously

Using in Artisan Commands

Long-Running Tunnels

For persistent tunnels that stay active (similar to ngrok), use the Artisan commands:

Start with Live Monitoring

Start a tunnel with real-time status updates (like ngrok):

This will show a live dashboard with tunnel information:

Press Ctrl+C to gracefully stop the tunnel.

Start in Background (Daemon Mode)

Run tunnel in background without monitoring (detached daemon mode):

Check Tunnel Status

View status of running tunnels:

Stop Tunnel

Stop a running tunnel:

Run as System Service

For production environments, you can run the tunnel as a persistent systemd service.

📖 See detailed guide: SYSTEMD.md

Quick example:

Related Resources

AutoSSH

The package automatically detects autossh availability and uses it instead of regular ssh to provide automatic reconnection on connection loss.

Installing autossh

macOS:

Ubuntu/Debian:

The package uses command -v autossh to detect autossh automatically. No additional configuration needed.

Disable AutoSSH

If you want to use regular SSH even when autossh is available:

Docker & DDEV

SSH tunnels work inside containers — you need access to SSH keys and autossh installed.

DDEV (Docker Desktop)

DDEV runs on Docker Desktop, which provides built-in SSH agent forwarding through the socket /run/host-services/ssh-auth.sock.

  1. Add autossh to config.yaml:

  2. Create .ddev/docker-compose.ssh-auth-socket.yaml for SSH agent forwarding:

  3. Restart and verify:

Docker Compose (Server / Docker Engine)

On servers there is no Docker Desktop, so SSH agent forwarding via /run/host-services/ssh-auth.sock is not available. Instead, mount the host's ~/.ssh directory directly into the container (read-only).

  1. Add openssh-client autossh to your Dockerfile:

  2. Create docker-compose.ssh-keys.yaml:

Note: Adjust the target path (/root/.ssh) to match the user running the application inside the container (e.g. /home/www-data/.ssh or /var/www/.ssh).

  1. Include it via COMPOSE_FILE in .env:

  2. Rebuild and verify:

Error Handling

Important Notes

MySQL/MariaDB: localhost vs 127.0.0.1

Critical: In MySQL and MariaDB, localhost has a special hardcoded meaning - it always represents a Unix socket connection, not a TCP/IP connection. This behavior cannot be changed.

The Difference

When using SSH tunnels with MySQL/MariaDB:

Configuration Example

Environment Variables:

Tunnel Configuration:

Database User Permissions

MySQL/MariaDB treat user@localhost and [email protected] as different users:

Important: When using SSH tunnels to access remote MySQL/MariaDB:

  1. Create database user with @127.0.0.1 host (not @localhost)
  2. Set remote_host to 127.0.0.1 in tunnel config
  3. Use 'host' => '127.0.0.1' in database connection config

Why This Matters

This issue commonly occurs when:

Solution: Always use 127.0.0.1 for both remote_host in tunnel config and database connection host when working with MySQL/MariaDB over SSH tunnels.

Advanced Features

Tunnel Reuse

The package can automatically detect and reuse existing SSH tunnels instead of creating new ones. This is useful for:

Smart Tunnel Discovery

The package uses two methods to find existing tunnels:

  1. PID file - Fastest method, stores tunnel PID in temp directory
  2. Port scan - Uses lsof/netstat to find processes by port

Reuse Command

Find and reuse existing tunnel from command line:

Retry Logic

Execute database operations with automatic retry on connection errors:

If the operation fails due to connection error, the tunnel will automatically reconnect and retry the operation.

Configuration

Configure retry behavior in config/tunnel.php:

Or use environment variables:

Database Validation

Verify that database is actually accessible through tunnel (not just port checking):

Signal Handling

Tunnels can automatically handle system signals for graceful shutdown:

Requires pcntl extension. Configure in config/tunnel.php:

Keep-Alive Tunnels

Create tunnels that persist after script ends:

To stop keep-alive tunnel, use the stop command:

Diagnostic Tools

Diagnose Command

Comprehensive tunnel health check:

The diagnostic tool checks:

ManagesTunnel Trait for Commands

Convenient trait for managing tunnels in Laravel commands:

ManagesTunnel Methods

API Reference

Artisan Commands

Tunnel

Static Methods

Instance Methods

TunnelConnection

TunnelManager

Logging

The package uses standard Laravel Log facade. For detailed logging:

Or in config/tunnel.php:

Requirements

License

MIT License

Author

Artem Yurov ([email protected])


All versions of laravel-autossh-tunnel with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/config Version ^10.0|^11.0|^12.0|^13.0
illuminate/log Version ^10.0|^11.0|^12.0|^13.0
symfony/process Version ^6.0|^7.0|^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package artemyurov/laravel-autossh-tunnel contains the following files

Loading the files please wait ...