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.

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