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.

91 lines
2.5 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
  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. use App\Facades\Install;
  6. /**
  7. * Install php-fpm
  8. *
  9. *
  10. */
  11. class PhpFpmInstallCommand extends Command
  12. {
  13. const FILE_PREFIX = '/etc/php';
  14. const FILE_SUFFIX = '/fpm/pool.d/www.conf';
  15. // packages to install
  16. const PACKAGES = 'php-mysql php-pear php-gd php-common php-curl php-json php-mbstring php-xml php-zip php-bcmath';
  17. /**
  18. * The signature of the command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'php-fpm:install {--user=}';
  23. /**
  24. * The description of the command.
  25. *
  26. * @var string
  27. */
  28. protected $description = 'Install php-fpm';
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $this->info('Php-fpm installing...');
  37. exec('apt update 2>&1', $output);
  38. exec('apt install -y php-fpm '.self::PACKAGES.' 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. // scan for all versions
  42. foreach(scandir(self::FILE_PREFIX) as $directory) {
  43. // get path to www.conf
  44. $file = self::FILE_PREFIX.'/'.$directory.self::FILE_SUFFIX;
  45. if (file_exists($file)) {
  46. // get user
  47. $user = $this->option('user');
  48. if ($user) {
  49. $output = [];
  50. $this->info('Php-fpm change user...');
  51. exec('sed -i "s/user = www-data/user = '.$user.'/g" '.$file, $output);
  52. exec('sed -i "s/group = www-data/group = '.$user.'/g" '.$file, $output);
  53. exec('sed -i "s/listen.owner = www-data/listen.owner = '.$user.'/g" '.$file, $output);
  54. exec('sed -i "s/listen.group = www-data/listen.group = '.$user.'/g" '.$file, $output);
  55. $this->line(implode("\n", $output));
  56. }
  57. $output = [];
  58. $this->info('Php-fpm change mode...');
  59. exec('sed -i "s/;listen.mode = 0660/listen.mode = 0660/g" '.$file, $output);
  60. $this->line(implode("\n", $output));
  61. }
  62. }
  63. // check if nginx is ready and installed
  64. if (Install::isReady('php-fpm')) {
  65. $this->info('Php-fpm installing...Success! \o/');
  66. } else {
  67. $this->error('Failed! Please check log-file!');
  68. }
  69. }
  70. }