PHP code example of omniglies / laravel-server-manager

1. Go to this page and download the library: Download omniglies/laravel-server-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

omniglies / laravel-server-manager example snippets


use ServerManager\LaravelServerManager\Services\SshService;

$sshService = app(SshService::class);

$config = [
    'host' => 'your-server.com',
    'username' => 'user',
    'password' => 'password', // or use 'private_key'
    'port' => 22
];

$connected = $sshService->connect($config);

if ($connected) {
    $result = $sshService->execute('ls -la');
    echo $result['output'];
}

use ServerManager\LaravelServerManager\Services\DeploymentService;

$deploymentService = app(DeploymentService::class);

$config = [
    'repository' => 'https://github.com/user/repo.git',
    'deploy_path' => '/var/www/html',
    'branch' => 'main',
    'build_commands' => ['npm install', 'npm run build'],
    'post_deploy_commands' => ['php artisan migrate', 'php artisan cache:clear']
];

$result = $deploymentService->deploy($config);

use ServerManager\LaravelServerManager\Services\MonitoringService;

$monitoringService = app(MonitoringService::class);

$status = $monitoringService->getServerStatus();
$processes = $monitoringService->getProcesses(10);
$services = $monitoringService->getServiceStatus(['nginx', 'mysql']);

use ServerManager\LaravelServerManager\Services\LogService;

$logService = app(LogService::class);

$logs = $logService->readLog('/var/log/nginx/error.log', 100);
$searchResults = $logService->searchLog('/var/log/syslog', 'error', 50);
$logFiles = $logService->getLogFiles('/var/log');
bash
php artisan vendor:publish --tag=config --provider="ServerManager\LaravelServerManager\ServerManagerServiceProvider"
bash
php artisan vendor:publish --tag=migrations --provider="ServerManager\LaravelServerManager\ServerManagerServiceProvider"
php artisan migrate
bash
php artisan vendor:publish --tag=views --provider="ServerManager\LaravelServerManager\ServerManagerServiceProvider"