JoomlaSetup.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Hestia\WebApp\Installers\Joomla;
  3. use Hestia\System\Util;
  4. use Hestia\WebApp\Installers\BaseSetup as BaseSetup;
  5. use function Hestiacp\quoteshellarg\quoteshellarg;
  6. class JoomlaSetup extends BaseSetup {
  7. protected $appInfo = [
  8. "name" => "Joomla",
  9. "group" => "cms",
  10. "enabled" => true,
  11. "version" => "latest",
  12. "thumbnail" => "joomla_thumb.png",
  13. ];
  14. protected $appname = "joomla";
  15. protected $config = [
  16. "form" => [
  17. "site_name" => [
  18. "type" => "text",
  19. "value" => "Joomla Site",
  20. "placeholder" => "Joomla Site",
  21. ],
  22. "admin_username" => [
  23. "type" => "text",
  24. "value" => "admin",
  25. "placeholder" => "Admin Username",
  26. ],
  27. "admin_password" => [
  28. "type" => "password",
  29. "value" => "",
  30. "placeholder" => "Admin Password",
  31. ],
  32. "admin_email" => [
  33. "type" => "text",
  34. "value" => "[email protected]",
  35. "placeholder" => "Admin Email",
  36. ],
  37. "install_directory" => [
  38. "type" => "text",
  39. "value" => "",
  40. "placeholder" => "/",
  41. ],
  42. ],
  43. "database" => true,
  44. "resources" => [
  45. "archive" => [
  46. "src" => "https://www.joomla.org/latest",
  47. ],
  48. ],
  49. "server" => [
  50. "nginx" => [
  51. "template" => "joomla",
  52. ],
  53. "php" => [
  54. "supported" => ["7.4", "8.0", "8.1", "8.2"],
  55. ],
  56. ],
  57. ];
  58. public function install(array $options = null): bool {
  59. $installDir =
  60. rtrim($this->getDocRoot(), "/") . "/" . ltrim($options["install_directory"] ?? "", "/");
  61. parent::setAppDirInstall($options["install_directory"] ?? "");
  62. parent::install($options);
  63. parent::setup($options);
  64. if (!is_dir($installDir)) {
  65. throw new \Exception("Installation directory does not exist: " . $installDir);
  66. }
  67. // Database credentials
  68. $dbHost = $options["database_host"];
  69. $dbName = $this->appcontext->user() . "_" . $options["database_name"];
  70. $dbUser = $this->appcontext->user() . "_" . $options["database_user"];
  71. $dbPass = $options["database_password"];
  72. // Site and admin credentials
  73. $siteName = $options["site_name"];
  74. $adminUsername = $options["admin_username"];
  75. $adminPassword = $options["admin_password"];
  76. $adminEmail = $options["admin_email"];
  77. // Initialize Joomla using the CLI
  78. $cliCmd = [
  79. "/usr/bin/php",
  80. quoteshellarg("$installDir/installation/joomla.php"),
  81. "install",
  82. "--site-name=" . quoteshellarg($siteName),
  83. "--admin-user=" . quoteshellarg($adminUsername),
  84. "--admin-username=" . quoteshellarg($adminUsername),
  85. "--admin-password=" . quoteshellarg($adminPassword),
  86. "--admin-email=" . quoteshellarg($adminEmail),
  87. "--db-user=" . quoteshellarg($dbUser),
  88. "--db-pass=" . quoteshellarg($dbPass),
  89. "--db-name=" . quoteshellarg($dbName),
  90. "--db-prefix=" . quoteshellarg(Util::generate_string(5, false) . "_"),
  91. "--db-host=" . quoteshellarg($dbHost),
  92. "--db-type=mysqli",
  93. ];
  94. $status = null;
  95. $this->appcontext->runUser("v-run-cli-cmd", $cliCmd, $status);
  96. if ($status->code !== 0) {
  97. throw new \Exception("Failed to install Joomla using CLI: " . $status->text);
  98. }
  99. return true;
  100. }
  101. }