PHP code example of tourze / server-application-bundle

1. Go to this page and download the library: Download tourze/server-application-bundle 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/ */

    

tourze / server-application-bundle example snippets


use ServerApplicationBundle\Entity\AppTemplate;

$template = new AppTemplate();
$template->setName('Web Server');
$template->setDescription('Nginx web server template');
$template->setImage('nginx:latest');

use ServerApplicationBundle\Entity\AppInstance;

$instance = new AppInstance();
$instance->setTemplate($template);
$instance->setName('production-web-server');
$instance->setNode($serverNode);

// Access the admin interface at /admin
// Manage templates, instances, logs, and configurations

use ServerApplicationBundle\Entity\AppExecutionStep;
use ServerApplicationBundle\Enum\ExecutionStepType;

$step = new AppExecutionStep();
$step->setTemplate($template);
$step->setSequence(1);
$step->setName('Install Dependencies');
$step->setType(ExecutionStepType::COMMAND);
$step->setContent('apt-get update && apt-get install -y nginx');
$step->setWorkingDirectory('/tmp');
$step->setUseSudo(true);
$step->setTimeout(300);
$step->setRetryCount(3);

use ServerApplicationBundle\Entity\AppPortConfiguration;
use ServerApplicationBundle\Enum\HealthCheckType;
use ServerApplicationBundle\Enum\ProtocolType;

$portConfig = new AppPortConfiguration();
$portConfig->setTemplate($template);
$portConfig->setPort(80);
$portConfig->setProtocol(ProtocolType::TCP);
$portConfig->setHealthCheckType(HealthCheckType::TCP_CONNECT);
$portConfig->setHealthCheckInterval(60);
$portConfig->setHealthCheckTimeout(5);
$portConfig->setHealthCheckRetries(3);

$template->setEnvironmentVariables([
    'NODE_ENV' => 'production',
    'PORT' => '8080',
    'DATABASE_URL' => 'mysql://user:pass@localhost/db'
]);

$instance->setEnvironmentVariables([
    'NODE_ENV' => 'production',
    'PORT' => '8080'
]);

use ServerApplicationBundle\Entity\AppLifecycleLog;
use ServerApplicationBundle\Enum\LifecycleActionType;
use ServerApplicationBundle\Enum\LogStatus;

$log = new AppLifecycleLog();
$log->setInstance($instance);
$log->setAction(LifecycleActionType::INSTALL);
$log->setStatus(LogStatus::SUCCESS);
$log->setMessage('Application installed successfully');
$log->setExecutionTime(45.2);