PHPackages                             merlinthemagic/mtm-shells - 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. merlinthemagic/mtm-shells

ActiveLibrary

merlinthemagic/mtm-shells
=========================

Shell tools for PHP 7

271[1 issues](https://github.com/merlinthemagic/MTM-Shells/issues)PHP

Since Feb 15Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/merlinthemagic/MTM-Shells)[ Packagist](https://packagist.org/packages/merlinthemagic/mtm-shells)[ RSS](/packages/merlinthemagic-mtm-shells/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

MTM-Shells
==========

[](#mtm-shells)

What is this?
-------------

[](#what-is-this)

A way to create and work with shells. You can execute any command you want, there is full parity with the underlying shell.

Install:
--------

[](#install)

```
composer require merlinthemagic/mtm-shells

```

### Get shell:

[](#get-shell)

#### Bash as current user (e.g. apache, www-data, etc):

[](#bash-as-current-user-eg-apache-www-data-etc)

```
$ctrlObj		= \MTM\Shells\Factories::getShells()->getBash(false);

```

#### Execute commands

[](#execute-commands)

```
$strCmd		= "whoami";
$data		= $ctrlObj->getCmd($strCmd)->get();
echo $data; //webserver user or if you got a root shell, then root :)

$strCmd1	= "cd /var";
$ctrlObj->getCmd($strCmd1)->get(); //enter the /var directory

$strCmd2	= "ls -sho --color=none";
$data		= $ctrlObj->getCmd($strCmd2)->get();
echo $data; //directory and file listing from /var

```

#### Bash as root:

[](#bash-as-root)

Obviously letting PHP anywhere near root is a poor idea, but the option is there.

##### Allowing PHP user to run sudo:

[](#allowing-php-user-to-run-sudo)

Add last line of the below snippit to the file: /etc/sudoers

```
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
## Add the line below, replace apache with whatever name your run your webserver with e.g. www-data
apache	ALL=(ALL)NOPASSWD:/usr/bin/python3

```

Then get a shell allowing MTM-Shells to use the sudo permissions we gave the webserver user over python3:

```
//get a root shell via sudo
$ctrlObj		= \MTM\Shells\Factories::getShells()->getBash(true);

```

If you dont like giving sudo permissions to the webserver, you can use SU and provide the password:

```
//get a root shell with password
$username		= "root";
$password		= "very_secret";

$ctrlObj		= \MTM\Shells\Factories::getShells()->getBash();
\MTM\Shells\Factories::getStencils()->getLinux()->getSu()->byPassword($ctrlObj, $username, $password);

echo $ctrlObj->getCmd("whoami")->get(); //root

```

### Files and directories:

[](#files-and-directories)

#### SFTP Copy directory recursively to remote server

[](#sftp-copy-directory-recursively-to-remote-server)

Note: SFTP will not include the source directory only all child files and directories into the specified destination directory Note: Destination directories that do not exist will be created

```
$ctrlObj		= \MTM\Shells\Factories::getShells()->getBash(); //can also be a ssh shell obj from MTM-SSH
$toolObj		= \MTM\Shells\Factories::getFiles()->getSftpTool();

$srcDir			= "/path/to/dir/";
$dstDir			= "/";
$ipAddr			= "192.168.1.15";
$username		= "myUserName";
$password		= "verySecret";

$toolObj->passwordCopy($ctrlObj, $srcDir, $dstDir, $ipAddr, $username, $password);

```

#### SCP Copy directory recursively to remote server

[](#scp-copy-directory-recursively-to-remote-server)

Note: SCP will include the source directory and all child files and directories into the specified destination directory Note: The base destination directory must exist and will not be created

```
$ctrlObj		= \MTM\Shells\Factories::getShells()->getBash(); //can also be a ssh shell obj from MTM-SSH
$toolObj		= \MTM\Shells\Factories::getFiles()->getScpTool();

$srcDir			= "/path/to/dir/";
$dstDir			= "/dst/dir/"; //must exist
$ipAddr			= "192.168.1.15";
$username		= "myUserName";
$password		= "verySecret";

$toolObj->passwordCopy($ctrlObj, $srcDir, $dstDir, $ipAddr, $username, $password);

```

#### Rsync Copy directory recursively to remote server

[](#rsync-copy-directory-recursively-to-remote-server)

Note: RSync will include the source directory and all child files and directories into the specified destination directory Note: The base destination directory must exist and will not be created

```
$ctrlObj		= \MTM\Shells\Factories::getShells()->getBash(); //can also be a ssh shell obj from MTM-SSH
$toolObj		= \MTM\Shells\Factories::getFiles()->getRsyncTool();

$srcDir			= "/path/to/dir/";
$dstDir			= "/dst/dir/"; //must exist
$ipAddr			= "192.168.1.15";
$username		= "myUserName";
$password		= "verySecret";

$toolObj->passwordCopy($ctrlObj, $srcDir, $dstDir, $ipAddr, $username, $password);

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance49

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity11

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8021715?v=4)[Martin Peter Madsen](/maintainers/merlinthemagic)[@merlinthemagic](https://github.com/merlinthemagic)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/merlinthemagic-mtm-shells/health.svg)

```
[![Health](https://phpackages.com/badges/merlinthemagic-mtm-shells/health.svg)](https://phpackages.com/packages/merlinthemagic-mtm-shells)
```

PHPackages © 2026

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