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.

88 lines
2.4 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
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. * Install Nginx
  9. *
  10. * @author Björn Hase, Tentakelfabrik
  11. * @license http://opensource.org/licenses/MIT The MIT License
  12. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
  13. *
  14. */
  15. class NginxInstallCommand extends Command
  16. {
  17. /**
  18. * The signature of the command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'nginx:install {--user=www-data} {--environment=production}';
  23. /**
  24. * The description of the command.
  25. *
  26. * @var string
  27. */
  28. protected $description = 'Install Nginx';
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $this->info('Nginx installing...');
  37. exec('apt update 2>&1', $output);
  38. exec('apt install -y nginx 2>&1', $output);
  39. // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
  40. $this->line(implode("\n", Install::filterAptMessages($output)));
  41. // check if nginx is ready and installed
  42. if (Install::isReady('nginx')) {
  43. $this->info('Nginx create configuration...');
  44. // copy snippets
  45. exec('cp '.base_path().'/resources/nginx/snippets/*.conf /etc/nginx/snippets');
  46. $configuration = [
  47. 'user' => $this->option('user'),
  48. 'environment' => $this->option('environment')
  49. ];
  50. // get workers
  51. $output = [];
  52. exec('echo $(grep ^processor /proc/cpuinfo | wc -l)', $output);
  53. $configuration['processes'] = $output[0];
  54. // get connections
  55. exec('echo $(ulimit -n)', $output);
  56. $configuration['connections'] = $output[1];
  57. $bladeFile = new BladeFile('/resources/nginx');
  58. $bladeFile->put('nginx', '/etc/nginx/nginx.conf', $configuration);
  59. // adding ufw to nginx
  60. $output = [];
  61. $this->info('Nginx adding ufw rules...');
  62. exec('ufw allow "Nginx Full" 2>&1', $output);
  63. $this->line(implode("\n", $output));
  64. $this->info('Nginx installing...Success! \o/');
  65. } else {
  66. $this->error('Failed! Please check log-file!');
  67. }
  68. }
  69. }