PHPackages                             kanti/ssh-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. kanti/ssh-tunnel

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

kanti/ssh-tunnel
================

SSH Port forward via PHP Code

1.0.1(8mo ago)018[1 PRs](https://github.com/Kanti/ssh-tunnel/pulls)PHPPHP ^8.2CI passing

Since Feb 12Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/Kanti/ssh-tunnel)[ Packagist](https://packagist.org/packages/kanti/ssh-tunnel)[ RSS](/packages/kanti-ssh-tunnel/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

kanti/ssh-tunnel
================

[](#kantissh-tunnel)

This is a simple SSH tunneling library for PHP.
It allows you to create SSH tunnels to remote servers and use them to forward ports on your local machine to the remote server.

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

[](#installation)

You can install the package via composer:

```
composer require kanti/ssh-tunnel
```

Usage
-----

[](#usage)

### tcp:

[](#tcp)

```
$tunnel = new \Kanti\SshTunnel\SshTunnel(
    sshHost: "testServer", // uses the default ssh config ~/.ssh/config
    remote: \Kanti\SshTunnel\Remote::tcp(3306, '127.0.0.1'),
    localPort: null, // if empty will auto select a local port for you (recommended)
);
$localPort = $tunnel->start();
$connection = new \PDO('mysql:host=127.0.0.1;port=' . $localPort, 'user', 'password');
```

### linux socket as tcp port:

[](#linux-socket-as-tcp-port)

```
$tunnel = new \Kanti\SshTunnel\SshTunnel(
    sshHost: "testServer", // uses the default ssh config ~/.ssh/config
    remote: \Kanti\SshTunnel\Remote::socket('/var/run/mysqld/mysqld.sock'), // can also expose the mysql socket as tcp port.
    localPort: null,
);
$localPort = $tunnel->start();
$connection = new \PDO('mysql:host=127.0.0.1;port=' . $localPort, 'user', 'password');
```

### advanced usages:

[](#advanced-usages)

```
use \Kanti\SshTunnel\SshTunnel;

// tunnel to connect to a remote MySQL server
$tunnel = new SshTunnel(
    // set custom ssh settings:
    sshUser: 'user',
    sshHost: "1.1.1.1",
    sshPort: 221,
    remote: \Kanti\SshTunnel\Remote::tcp(3306, '192.168.0.2'),
    localPort: null,
);
$localPort = $tunnel->start();

// connect to mysql
$connection = new \PDO('mysql:host=127.0.0.1;port=' . $localPort, 'user', 'password');

// do something with the connection

$tunnel->stop(); // stops the tunnel
// OR
unset($tunnel); // also stops the tunnel (can be disabled in the constructor disconnectAfterTunnelDestroyed: false)
// OR
// you can stop the PHP Script, that will also stop the tunnel (via inactivity timeout)
```

How does it work?
-----------------

[](#how-does-it-work)

The library uses the `ssh` command line tool to create the tunnel.
It uses the control\_socket feature of ssh to keep the connection open and reuse it for multiple tunnels (if needed).
The tunnel is created in the background.
By default it will not output anything to the console and will exit after 5s (option: `autoDisconnectTimeout: '10s'`) of inactivity.
If you want to see the output of the tunnel you can set the `debugMasterOutput: true` in the constructor.

Linting
-------

[](#linting)

```
composer install
grumphp run
```

Author
------

[](#author)

```
made with ❤️ by Kanti (Matthias Vogel)
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance66

Regular maintenance activity

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 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 ~247 days

Total

2

Last Release

260d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/471387?v=4)[Matthias Vogel](/maintainers/Kanti)[@Kanti](https://github.com/Kanti)

---

Top Contributors

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

---

Tags

phpphp-libraryssh-forwardingssh-tunnel

### Embed Badge

![Health badge](/badges/kanti-ssh-tunnel/health.svg)

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

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.2k](/packages/friendsofphp-php-cs-fixer)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[phpactor/phpactor

PHP refactoring and intellisense tool for text editors

1.9k17.1k1](/packages/phpactor-phpactor)

PHPackages © 2026

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