[ 'required', Rule::in(config('core.php_versions')), Rule::notIn([\App\Enums\PHP::NONE]), Rule::unique('services', 'version') ->where('type', 'php') ->where('server_id', $this->service->server_id), ], ]; } public function deletionRules(): array { return [ 'service' => [ function (string $attribute, mixed $value, Closure $fail) { $hasSite = $this->service->server->sites() ->where('php_version', $this->service->version) ->exists(); if ($hasSite) { $fail('Some sites are using this PHP version.'); } }, ], ]; } public function install(): void { $server = $this->service->server; $server->ssh()->exec( $this->getScript('install-php.sh', [ 'version' => $this->service->version, 'user' => $server->getSshUser(), ]), 'install-php-'.$this->service->version ); $this->installComposer(); $this->service->server->os()->cleanup(); } public function uninstall(): void { $this->service->server->ssh()->exec( $this->getScript('uninstall-php.sh', [ 'version' => $this->service->version, ]), 'uninstall-php-'.$this->service->version ); $this->service->server->os()->cleanup(); } public function setDefaultCli(): void { $this->service->server->ssh()->exec( $this->getScript('change-default-php.sh', [ 'version' => $this->service->version, ]), 'change-default-php' ); } /** * @throws SSHCommandError */ public function installExtension($name): void { $result = $this->service->server->ssh()->exec( $this->getScript('install-php-extension.sh', [ 'version' => $this->service->version, 'name' => $name, ]), 'install-php-extension-'.$name ); $result = Str::substr($result, strpos($result, '[PHP Modules]')); if (! Str::contains($result, $name)) { throw new SSHCommandError('Failed to install extension'); } } public function installComposer(): void { $this->service->server->ssh()->exec( $this->getScript('install-composer.sh'), 'install-composer' ); } public function getPHPIni(string $type): string { return $this->service->server->os()->readFile( sprintf('/etc/php/%s/%s/php.ini', $this->service->version, $type) ); } public function createFpmPool(string $user, string $version, $site_id): void { $this->service->server->ssh()->exec( $this->getScript('create-fpm-pool.sh', [ 'user' => $user, 'version' => $version, 'config' => $this->getScript('fpm-pool.conf', [ 'user' => $user, 'version' => $version, ]), ]), "create-{$version}fpm-pool-{$user}", $site_id ); } public function removeFpmPool(string $user, string $version, $site_id): void { $this->service->server->ssh()->exec( $this->getScript('remove-fpm-pool.sh', [ 'user' => $user, 'version' => $version, ]), "remove-{$version}fpm-pool-{$user}", $site_id ); } }