| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -4,20 +4,27 @@ namespace App\Commands; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use Illuminate\Console\Scheduling\Schedule; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use LaravelZero\Framework\Commands\Command; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use Illuminate\Support\Facades\File; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Facades\Install; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use Log; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					class InstallPhpFpmCommand extends Command | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 *  Install php-fpm | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					class PhpFpmInstallCommand extends Command | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    const FILE_PREFIX = '/etc/php'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    const FILE_SUFFIX = '/fpm/pool.d/www.conf'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // packages to install
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    const PACKAGES = 'php-mysql php-pear php-gd php-common php-curl php-json php-mbstring php-xml php-zip php-bcmath'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * The signature of the command. | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @var string | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    protected $signature = 'php-fpm:install'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    protected $signature = 'php-fpm:install {--user=}'; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * The description of the command. | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -33,19 +40,52 @@ class InstallPhpFpmCommand extends Command | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public function handle() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        $this->info('Install PHP FPM'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        $this->info('Php-fpm installing...'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        exec('apt update 2>&1', $output); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        exec('apt install -y php-fpm '.self::PACKAGES.' 2>&1', $output); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        $this->line(implode("\n", Install::filterAptMessages($output))); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // scan for all versions
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        foreach(scandir(self::FILE_PREFIX) as $directory) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            // get path to www.conf
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $file = self::FILE_PREFIX.'/'.$directory.self::FILE_SUFFIX; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        exec('apt update 2>&1'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        exec('apt install -y php-fpm php-curl php-mysql php-pear php-dev php-gd 2>&1'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (file_exists($file)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (Install::isReady('nginx')) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                // get user
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                $user = $this->option('user'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            // get status of nginx
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            exec('nginx -v 2>&1', $output); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $status = "$output[0] installed"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if ($user) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    $output = []; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    $this->info('Php-fpm change user...'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    exec('sed -i "s/user = www-data/user = '.$user.'/g" '.$file, $output); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    exec('sed -i "s/group = www-data/group = '.$user.'/g" '.$file, $output); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    exec('sed -i "s/listen.owner = www-data/listen.owner = '.$user.'/g" '.$file, $output); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    exec('sed -i "s/listen.group = www-data/listen.group = '.$user.'/g" '.$file, $output); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    $this->line(implode("\n", $output)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                $output = []; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                $this->info('Php-fpm change mode...'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                exec('sed -i "s/;listen.mode = 0660/listen.mode = 0660/g" '.$file, $output); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                $this->line(implode("\n", $output)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $this->info($status); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            Log::info($status); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // check if nginx is ready and installed
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (Install::isReady('php-fpm')) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $this->info('Php-fpm installing...Success! \o/'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $this->error('Failed! Please check log-file!'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} |