mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 07:22:34 +00:00
Merge (#127)
This commit is contained in:
88
app/SSH/Services/PHP/PHP.php
Normal file
88
app/SSH/Services/PHP/PHP.php
Normal 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,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
11
app/SSH/Services/PHP/scripts/change-default-php.sh
Executable file
11
app/SSH/Services/PHP/scripts/change-default-php.sh
Executable 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
|
3
app/SSH/Services/PHP/scripts/get-php-ini.sh
Normal file
3
app/SSH/Services/PHP/scripts/get-php-ini.sh
Normal file
@ -0,0 +1,3 @@
|
||||
if ! cat /etc/php/__version__/cli/php.ini; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
7
app/SSH/Services/PHP/scripts/install-composer.sh
Executable file
7
app/SSH/Services/PHP/scripts/install-composer.sh
Executable 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
|
5
app/SSH/Services/PHP/scripts/install-php-extension.sh
Normal file
5
app/SSH/Services/PHP/scripts/install-php-extension.sh
Normal file
@ -0,0 +1,5 @@
|
||||
sudo apt-get install -y php__version__-__name__
|
||||
|
||||
sudo service php__version__-fpm restart
|
||||
|
||||
php__version__ -m
|
15
app/SSH/Services/PHP/scripts/install-php.sh
Executable file
15
app/SSH/Services/PHP/scripts/install-php.sh
Executable 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
|
5
app/SSH/Services/PHP/scripts/uninstall-php.sh
Executable file
5
app/SSH/Services/PHP/scripts/uninstall-php.sh
Executable 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
|
11
app/SSH/Services/PHP/scripts/update-php-settings.sh
Normal file
11
app/SSH/Services/PHP/scripts/update-php-settings.sh
Normal 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
|
Reference in New Issue
Block a user