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.

97 lines
2.9 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
  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-intl 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. $output = [];
  41. exec('apt update 2>&1', $output);
  42. exec('apt install -y php-fpm '.self::PACKAGES.' 2>&1', $output);
  43. // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
  44. $this->line(implode("\n", Install::filterAptMessages($output)));
  45. // scan for all versions
  46. foreach(scandir(self::FILE_PREFIX) as $directory) {
  47. // get path to www.conf
  48. $file = self::FILE_PREFIX.'/'.$directory.self::FILE_SUFFIX;
  49. if (file_exists($file)) {
  50. // get user
  51. $user = $this->option('user');
  52. if ($user) {
  53. $this->info('Php-fpm change user...');
  54. system('sed -i "s/user = www-data/user = '.$user.'/g" '.$file);
  55. system('sed -i "s/group = www-data/group = '.$user.'/g" '.$file);
  56. system('sed -i "s/listen.owner = www-data/listen.owner = '.$user.'/g" '.$file);
  57. system('sed -i "s/listen.group = www-data/listen.group = '.$user.'/g" '.$file);
  58. }
  59. $this->info('Php-fpm change mode...');
  60. system('sed -i "s/;listen.mode = 0660/listen.mode = 0660/g" '.$file);
  61. // getting version and restart service
  62. $output = [];
  63. exec("systemctl --full --type service --all | awk '{print $1}' | egrep php.+?fpm.service", $output);
  64. foreach ($output as $line) {
  65. system('service '.str_replace('.service', '', $line).' restart');
  66. }
  67. }
  68. }
  69. // check if nginx is ready and installed
  70. if (Install::isReady('php-fpm')) {
  71. $this->info('Php-fpm installing...Success! \o/');
  72. } else {
  73. $this->error('Failed! Please check log-file!');
  74. }
  75. }
  76. }