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)
32 -f prepared config file (e.g. ".htconfig.php" itself)
36 protected function doExecute()
39 $this->out("Initializing setup...\n");
47 $config_file = $this->getOption('f', 'htconfig.php');
49 $this->out("Using config $config_file...\n");
50 require_once $config_file;
52 Install::setInstallMode();
54 $this->out(" Complete!\n\n");
57 $this->out("Checking basic setup...\n");
60 $checkResults['basic'] = $this->runBasicChecks($a);
61 $errorMessage = $this->extractErrors($checkResults['basic']);
63 if ($errorMessage !== '') {
64 throw new \RuntimeException($errorMessage);
67 $this->out(" Complete!\n\n");
69 // Check database connection
70 $this->out("Checking database...\n");
72 $checkResults['db'] = array();
73 $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
74 $errorMessage = $this->extractErrors($checkResults['db']);
76 if ($errorMessage !== '') {
77 throw new \RuntimeException($errorMessage);
80 $this->out(" Complete!\n\n");
83 $this->out("Inserting data into database...\n");
85 $checkResults['data'] = Install::installDatabaseStructure();
87 if ($checkResults['data'] !== '') {
88 throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
91 $this->out(" Complete!\n\n");
94 $this->out("Saving config file...\n");
95 if ($config_file != '.htconfig.php' && !copy($config_file, '.htconfig.php')) {
96 throw new \RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '.htconfig.php' manually.\n");
98 $this->out(" Complete!\n\n");
99 $this->out("\nInstallation is finished\n");
108 private function runBasicChecks($app)
112 Install::checkFunctions($checks);
113 Install::checkImagick($checks);
114 Install::checkHtConfig($checks);
115 Install::checkSmarty3($checks);
116 Install::checkKeys($checks);
118 if (!empty($app->config['php_path'])) {
119 Install::checkPHP($app->config['php_path'], $checks);
121 throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n");
124 $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
136 private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
139 'title' => 'MySQL Connection',
146 if (!dba::connect($db_host, $db_user, $db_pass, $db_data)) {
147 $result['status'] = false;
148 $result['help'] = 'Failed, please check your MySQL settings and credentials.';
155 * @param array $results
158 private function extractErrors($results)
161 $allChecksRequired = $this->getOption('a') !== null;
163 foreach ($results as $result) {
164 if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
165 $errorMessage .= "--------\n";
166 $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
170 return $errorMessage;