3 namespace Friendica\Core\Console;
5 use Asika\SimpleConsole\Console;
8 use Friendica\Core\Install;
10 require_once 'mod/install.php';
12 class AutomaticInstallation extends Console
14 protected function getHelp()
17 Installation - Install Friendica automatically
19 bin/console autoinstall [-h|--help|-?] [-v] [-a]
22 Installs Friendica with data based on the htconfig.php file
25 Not checking .htaccess/URL-Rewrite during CLI installation.
28 -h|--help|-? Show help information
29 -v Show more debug information.
30 -a All setup checks are required (except .htaccess)
34 protected function doExecute()
37 $this->out("Initializing setup...\n");
44 require_once 'htconfig.php';
46 Install::setInstallMode();
48 $this->out(" Complete!\n\n");
51 $this->out("Checking basic setup...\n");
54 $checkResults['basic'] = $this->runBasicChecks($a);
55 $errorMessage = $this->extractErrors($checkResults['basic']);
57 if ($errorMessage !== '') {
58 throw new \RuntimeException($errorMessage);
61 $this->out(" Complete!\n\n");
63 // Check database connection
64 $this->out("Checking database...\n");
66 $checkResults['db'] = array();
67 $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
68 $errorMessage = $this->extractErrors($checkResults['db']);
70 if ($errorMessage !== '') {
71 throw new \RuntimeException($errorMessage);
74 $this->out(" Complete!\n\n");
77 $this->out("Inserting data into database...\n");
79 $checkResults['data'] = Install::loadDatabase();
81 if ($checkResults['data'] !== '') {
82 throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
85 $this->out(" Complete!\n\n");
88 $this->out("Saving config file...\n");
89 if (!copy('htconfig.php', '.htconfig.php')) {
90 throw new \RuntimeException("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n");
92 $this->out(" Complete!\n\n");
93 $this->out("\nInstallation is finished\n");
102 private function runBasicChecks($app)
106 Install::checkFunctions($checks);
107 Install::checkImagik($checks);
108 Install::checkHtConfig($checks);
109 Install::checkSmarty3($checks);
110 Install::checkKeys($checks);
112 if (!empty($app->config['php_path'])) {
113 Install::checkPHP($app->config['php_path'], $checks);
115 throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n");
118 $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
130 private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
133 'title' => 'MySQL Connection',
140 if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) {
141 $result['status'] = false;
142 $result['help'] = 'Failed, please check your MySQL settings and credentials.';
149 * @param array $results
152 private function extractErrors($results)
155 $allChecksRequired = $this->getOption('a') !== null;
157 foreach ($results as $result) {
158 if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
159 $errorMessage .= "--------\n";
160 $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
164 return $errorMessage;