This commit is contained in:
Saeed Vaziry
2024-03-24 09:56:34 +01:00
committed by GitHub
parent 884f18db63
commit 4d051330d6
1055 changed files with 14493 additions and 20278 deletions

View File

@ -0,0 +1,88 @@
<?php
namespace App\SSH\Services\PHP;
use App\Exceptions\SSHCommandError;
use App\Models\Service;
use App\SSH\HasScripts;
use App\SSH\Services\ServiceInterface;
use Illuminate\Support\Str;
class PHP implements ServiceInterface
{
use HasScripts;
protected Service $service;
public function __construct(Service $service)
{
$this->service = $service;
}
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
);
}
public function uninstall(): void
{
$this->service->server->ssh()->exec(
$this->getScript('uninstall-php.sh', [
'version' => $this->service->version,
]),
'uninstall-php-'.$this->service->version
);
}
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
{
return $this->service->server->ssh()->exec(
$this->getScript('get-php-ini.sh', [
'version' => $this->service->version,
])
);
}
}

View File

@ -0,0 +1,11 @@
if ! sudo rm /usr/bin/php; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ln -s /usr/bin/php__version__ /usr/bin/php; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Default php is: "
php -v

View File

@ -0,0 +1,3 @@
if ! cat /etc/php/__version__/cli/php.ini; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,7 @@
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer

View File

@ -0,0 +1,5 @@
sudo apt-get install -y php__version__-__name__
sudo service php__version__-fpm restart
php__version__ -m

View File

@ -0,0 +1,15 @@
sudo add-apt-repository ppa:ondrej/php -y
sudo DEBIAN_FRONTEND=noninteractive apt-get update
if ! sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php__version__ php__version__-fpm php__version__-mbstring php__version__-mysql php__version__-gd php__version__-xml php__version__-curl php__version__-gettext php__version__-zip php__version__-bcmath php__version__-soap php__version__-redis php__version__-sqlite3 php__version__-tokenizer php__version__-pgsql php__version__-pdo; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo sed -i 's/www-data/__user__/g' /etc/php/__version__/fpm/pool.d/www.conf; then
echo 'VITO_SSH_ERROR' && exit 1
fi
sudo service php__version__-fpm enable
sudo service php__version__-fpm start

View File

@ -0,0 +1,5 @@
sudo service php__version__-fpm stop
if ! sudo DEBIAN_FRONTEND=noninteractive apt-get remove -y php__version__ php__version__-fpm php__version__-mbstring php__version__-mysql php__version__-mcrypt php__version__-gd php__version__-xml php__version__-curl php__version__-gettext php__version__-zip php__version__-bcmath php__version__-soap php__version__-redis php__version__-sqlite3; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,11 @@
if ! sudo sed -i 's,^__variable__ =.*$,__variable__ = __value__,' /etc/php/__version__/cli/php.ini; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo sed -i 's,^__variable__ =.*$,__variable__ = __value__,' /etc/php/__version__/fpm/php.ini; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service php__version__-fpm restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi