<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
use App\Facades\Install;
|
|
use App\BladeFile;
|
|
|
|
use Log;
|
|
|
|
class NginxInstallCommand extends Command
|
|
{
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'nginx:install {--user=www-data}';
|
|
|
|
/**
|
|
* 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');
|
|
exec('apt install -y nginx 2>&1');
|
|
|
|
// copy snippets
|
|
exec('cp '.base_path().'/resources/nginx/snippets/*.conf /etc/nginx/snippets');
|
|
|
|
$configuration = [
|
|
'user' => $this->option('user'),
|
|
'env' => App::environment()
|
|
];
|
|
|
|
// get workers
|
|
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);
|
|
|
|
// check if nginx is ready and installed
|
|
if (Install::isReady('nginx')) {
|
|
|
|
// adding ufw to nginx
|
|
exec('ufw allow "Nginx Full"');
|
|
|
|
$this->info("Success!");
|
|
} else {
|
|
$this->error("failed");
|
|
}
|
|
}
|
|
}
|