WordpressSetup.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Hestia\WebApp\Installers;
  3. use Hestia\System\Util;
  4. class WordpressSetup extends BaseSetup {
  5. protected $appname = 'wordpress';
  6. protected $config = [
  7. 'form' => [
  8. //'protocol' => [
  9. // 'type' => 'select',
  10. // 'options' => ['http','https'],
  11. //],
  12. 'site_name' => ['type'=>'text', 'value'=>'WordPress Blog'],
  13. 'site_description' => ['value'=>'Another WordPress site'],
  14. 'wordpress_account_username' => ['value'=>'wpadmin'],
  15. 'wordpress_account_email' => 'text',
  16. 'wordpress_account_password' => 'password',
  17. ],
  18. 'database' => true,
  19. 'resources' => [
  20. 'archive' => [ 'src' => 'https://wordpress.org/latest.tar.gz' ],
  21. ],
  22. ];
  23. public function install(array $options = null)
  24. {
  25. parent::install($options);
  26. $this->appcontext->runUser('v-open-fs-file',[$this->getDocRoot("wp-config-sample.php")], $result);
  27. $distconfig = preg_replace( [
  28. '/database_name_here/', '/username_here/', '/password_here/'
  29. ], [
  30. $this->appcontext->user() . '_' . $options['database_name'],
  31. $this->appcontext->user() . '_' . $options['database_user'],
  32. $options['database_password']
  33. ],
  34. $result->text);
  35. while (strpos($distconfig, 'put your unique phrase here') !== false) {
  36. $distconfig = preg_replace( '/put your unique phrase here/', Util::generate_string(64), $distconfig, 1);
  37. }
  38. $tmp_configpath = $this->saveTempFile($distconfig);
  39. if(!$this->appcontext->runUser('v-move-fs-file',[$tmp_configpath, $this->getDocRoot("wp-config.php")], $result)) {
  40. throw new \Exception("Error installing config file in: " . $tmp_configpath . " to:" . $this->getDocRoot("wp-config.php") . $result->text );
  41. }
  42. exec("/usr/bin/curl --location --post301 --insecure --resolve ".$this->domain.":80:".$this->appcontext->getWebDomainIp($this->domain)." "
  43. . escapeshellarg("http://".$this->domain."/wp-admin/install.php?step=2")
  44. . " -d " . escapeshellarg(
  45. "weblog_title=" . rawurlencode($options['site_name'])
  46. . "&user_name=" . rawurlencode($options['wordpress_account_username'])
  47. . "&admin_password=" . rawurlencode($options['wordpress_account_password'])
  48. . "&admin_password2=". rawurlencode($options['wordpress_account_password'])
  49. . "&admin_email=" . rawurlencode($options['wordpress_account_email'])), $output, $return_var);
  50. return ($return_var === 0);
  51. }
  52. }