3 namespace Friendica\Core\Console;
5 use Asika\SimpleConsole\Console;
8 use Friendica\Core\Install;
10 require_once 'mod/install.php';
11 require_once 'include/dba.php';
13 class AutomaticInstallation extends Console
15 protected function getHelp()
18 Installation - Install Friendica automatically
20 bin/console autoinstall [-h|--help|-?] [-v] [-a]
23 Installs Friendica with data based on the htconfig.php file
26 Not checking .htaccess/URL-Rewrite during CLI installation.
29 -h|--help|-? Show help information
30 -v Show more debug information.
31 -a All setup checks are required (except .htaccess)
35 protected function doExecute()
38 $this->out("Initializing setup...\n");
45 require_once 'htconfig.php';
47 Install::setInstallMode();
49 $this->out(" Complete!\n\n");
52 $this->out("Checking basic setup...\n");
55 $checkResults['basic'] = $this->runBasicChecks($a);
56 $errorMessage = $this->extractErrors($checkResults['basic']);
58 if ($errorMessage !== '') {
59 throw new \RuntimeException($errorMessage);
62 $this->out(" Complete!\n\n");
64 // Check database connection
65 $this->out("Checking database...\n");
67 $checkResults['db'] = array();
68 $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
69 $errorMessage = $this->extractErrors($checkResults['db']);
71 if ($errorMessage !== '') {
72 throw new \RuntimeException($errorMessage);
75 $this->out(" Complete!\n\n");
78 $this->out("Inserting data into database...\n");
80 $checkResults['data'] = Install::installDatabaseStructure();
82 if ($checkResults['data'] !== '') {
83 throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
86 $this->out(" Complete!\n\n");
89 $this->out("Saving config file...\n");
90 if (!copy('htconfig.php', '.htconfig.php')) {
91 throw new \RuntimeException("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n");
93 $this->out(" Complete!\n\n");
94 $this->out("\nInstallation is finished\n");
103 private function runBasicChecks($app)
107 Install::checkFunctions($checks);
108 Install::checkImagick($checks);
109 Install::checkHtConfig($checks);
110 Install::checkSmarty3($checks);
111 Install::checkKeys($checks);
113 if (!empty($app->config['php_path'])) {
114 Install::checkPHP($app->config['php_path'], $checks);
116 throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n");
119 $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
131 private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
134 'title' => 'MySQL Connection',
141 if (!dba::connect($db_host, $db_user, $db_pass, $db_data)) {
142 $result['status'] = false;
143 $result['help'] = 'Failed, please check your MySQL settings and credentials.';
150 * @param array $results
153 private function extractErrors($results)
156 $allChecksRequired = $this->getOption('a') !== null;
158 foreach ($results as $result) {
159 if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
160 $errorMessage .= "--------\n";
161 $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
165 return $errorMessage;