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.

95 lines
2.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
  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. * @author Björn Hase, Tentakelfabrik
  10. * @license http://opensource.org/licenses/MIT The MIT License
  11. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
  12. *
  13. */
  14. class PhpFpmInstallCommand extends Command
  15. {
  16. const FILE_PREFIX = '/etc/php';
  17. const FILE_SUFFIX = '/fpm/pool.d/www.conf';
  18. // packages to install
  19. const PACKAGES = 'php-mysql php-pear php-gd php-common php-curl php-json php-mbstring php-xml php-zip php-bcmath';
  20. /**
  21. * The signature of the command.
  22. *
  23. * @var string
  24. */
  25. protected $signature = 'php-fpm:install {--user=}';
  26. /**
  27. * The description of the command.
  28. *
  29. * @var string
  30. */
  31. protected $description = 'Install php-fpm';
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. $this->info('Php-fpm installing...');
  40. exec('apt update 2>&1', $output);
  41. exec('apt install -y php-fpm '.self::PACKAGES.' 2>&1', $output);
  42. // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
  43. $this->line(implode("\n", Install::filterAptMessages($output)));
  44. // scan for all versions
  45. foreach(scandir(self::FILE_PREFIX) as $directory) {
  46. // get path to www.conf
  47. $file = self::FILE_PREFIX.'/'.$directory.self::FILE_SUFFIX;
  48. if (file_exists($file)) {
  49. // get user
  50. $user = $this->option('user');
  51. if ($user) {
  52. $output = [];
  53. $this->info('Php-fpm change user...');
  54. exec('sed -i "s/user = www-data/user = '.$user.'/g" '.$file, $output);
  55. exec('sed -i "s/group = www-data/group = '.$user.'/g" '.$file, $output);
  56. exec('sed -i "s/listen.owner = www-data/listen.owner = '.$user.'/g" '.$file, $output);
  57. exec('sed -i "s/listen.group = www-data/listen.group = '.$user.'/g" '.$file, $output);
  58. $this->line(implode("\n", $output));
  59. }
  60. $output = [];
  61. $this->info('Php-fpm change mode...');
  62. exec('sed -i "s/;listen.mode = 0660/listen.mode = 0660/g" '.$file, $output);
  63. $this->line(implode("\n", $output));
  64. }
  65. }
  66. // check if nginx is ready and installed
  67. if (Install::isReady('php-fpm')) {
  68. $this->info('Php-fpm installing...Success! \o/');
  69. } else {
  70. $this->error('Failed! Please check log-file!');
  71. }
  72. }
  73. }