<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
|
|
use App\Facades\Install;
|
|
use App\BladeFile;
|
|
|
|
/**
|
|
* Nginx install
|
|
*
|
|
*
|
|
*/
|
|
class NginxInstallCommand extends Command
|
|
{
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'nginx:install {--user=www-data} {--environment=production}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Install Nginx';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->info('Nginx installing...');
|
|
|
|
exec('apt update 2>&1', $output);
|
|
exec('apt install -y nginx 2>&1', $output);
|
|
|
|
// @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
|
|
$this->line(implode("\n", Install::filterAptMessages($output)));
|
|
|
|
// check if nginx is ready and installed
|
|
if (Install::isReady('nginx')) {
|
|
|
|
$this->info('Nginx create configuration...');
|
|
|
|
// copy snippets
|
|
exec('cp '.base_path().'/resources/nginx/snippets/*.conf /etc/nginx/snippets');
|
|
|
|
$configuration = [
|
|
'user' => $this->option('user'),
|
|
'environment' => $this->option('environment')
|
|
];
|
|
|
|
// get workers
|
|
$output = [];
|
|
|
|
exec('echo $(grep ^processor /proc/cpuinfo | wc -l)', $output);
|
|
$configuration['processes'] = $output[0];
|
|
|
|
// get connections
|
|
exec('echo $(ulimit -n)', $output);
|
|
$configuration['connections'] = $output[1];
|
|
|
|
$bladeFile = new BladeFile('/resources/nginx');
|
|
$bladeFile->put('nginx', '/etc/nginx/nginx.conf', $configuration);
|
|
|
|
// adding ufw to nginx
|
|
$output = [];
|
|
|
|
$this->info('Nginx adding ufw rules...');
|
|
exec('ufw allow "Nginx Full" 2>&1', $output);
|
|
$this->line(implode("\n", $output));
|
|
|
|
$this->info('Nginx installing...Success! \o/');
|
|
} else {
|
|
$this->error('Failed! Please check log-file!');
|
|
}
|
|
}
|
|
}
|