PhyrePanel-mirror/web/app/Installers/Server/Applications/PythonInstaller.php

54 lines
2 KiB
PHP
Raw Normal View History

2024-04-22 11:14:05 +00:00
<?php
namespace App\Installers\Server\Applications;
class PythonInstaller
{
public $pythonVersions = [];
public $logFilePath = '/var/log/phyre/python-installer.log';
public function setPythonVersions($versions)
{
$this->pythonVersions = $versions;
}
public function setLogFilePath($path)
{
$this->logFilePath = $path;
}
public function install()
{
$commands = [];
2024-05-14 22:30:35 +00:00
$commands[] = 'export DEBIAN_FRONTEND=noninteractive';
2024-04-22 11:14:05 +00:00
foreach ($this->pythonVersions as $pythonVersion) {
2024-05-14 22:30:35 +00:00
$commands[] = 'apt-get install -yq python' . $pythonVersion;
$commands[] = 'apt-get install -yq python' . $pythonVersion . '-dev';
$commands[] = 'apt-get install -yq python' . $pythonVersion . '-venv';
$commands[] = 'apt-get install -yq python' . $pythonVersion . '-setuptools';
$commands[] = 'apt-get install -yq python' . $pythonVersion . '-wheel';
2024-04-22 11:14:05 +00:00
}
2024-05-14 12:33:21 +00:00
// Install Apache Passenger
$commands[] = 'curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null';
$commands[] = "sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger jammy main > /etc/apt/sources.list.d/passenger.list'";
$commands[] = 'apt-get update';
2024-05-14 22:30:35 +00:00
$commands[] = 'sudo apt-get install -yq libapache2-mod-passenger';
2024-05-14 12:33:21 +00:00
$commands[] = 'sudo a2enmod passenger';
$commands[] = 'sudo service apache2 restart';
2024-04-22 11:14:05 +00:00
$shellFileContent = '';
foreach ($commands as $command) {
$shellFileContent .= $command . PHP_EOL;
}
$shellFileContent .= 'echo "All packages installed successfully!"' . PHP_EOL;
$shellFileContent .= 'echo "DONE!"' . PHP_EOL;
$shellFileContent .= 'rm -f /tmp/python-installer.sh';
file_put_contents('/tmp/python-installer.sh', $shellFileContent);
shell_exec('bash /tmp/python-installer.sh >> ' . $this->logFilePath . ' &');
}
}