OpenSource CLI-App to install and handle stuff related to Web-Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. use App\Facades\Install;
  6. use App\BladeFile;
  7. /**
  8. *
  9. *
  10. *
  11. */
  12. class NginxInstallCommand extends Command
  13. {
  14. /**
  15. * The signature of the command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'nginx:install {--user=www-data}';
  20. /**
  21. * The description of the command.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'Install Nginx';
  26. /**
  27. * Execute the console command.
  28. *
  29. * @return mixed
  30. */
  31. public function handle()
  32. {
  33. $this->info('Nginx installing...');
  34. exec('apt update 2>&1');
  35. exec('apt install -y nginx 2>&1');
  36. // check if nginx is ready and installed
  37. if (Install::isReady('nginx')) {
  38. // copy snippets
  39. exec('cp '.base_path().'/resources/nginx/snippets/*.conf /etc/nginx/snippets');
  40. $configuration = [
  41. 'user' => $this->option('user'),
  42. 'env' => App::environment()
  43. ];
  44. // get workers
  45. exec('echo $(grep ^processor /proc/cpuinfo | wc -l)', $output);
  46. $configuration['processes'] = $output[0];
  47. // get connections
  48. exec('echo $(ulimit -n)', $output);
  49. $configuration['connections'] = $output[1];
  50. $bladeFile = new BladeFile('/resources/nginx');
  51. $bladeFile->put('nginx', '/etc/nginx/nginx.conf', $configuration);
  52. // adding ufw to nginx
  53. exec('ufw allow "Nginx Full"');
  54. $this->info('Success! \o/');
  55. } else {
  56. $this->error('Failed! /o\\');
  57. }
  58. }
  59. }