3 namespace Friendica\Core\Console;
5 use Asika\SimpleConsole\Console;
6 use Friendica\BaseObject;
7 use Friendica\Core\Config;
8 use Friendica\Core\Installer;
9 use Friendica\Core\Theme;
12 class AutomaticInstallation extends Console
14 protected function getHelp()
17 Installation - Install Friendica automatically
19 bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f]
22 Installs Friendica with data based on the local.config.php file or environment variables
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)
31 -f|--file <config> prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables)
32 -s|--savedb Save the DB credentials to the file (if environment variables is used)
33 -H|--dbhost <host> The host of the mysql/mariadb database (env MYSQL_HOST)
34 -p|--dbport <port> The port of the mysql/mariadb database (env MYSQL_PORT)
35 -d|--dbdata <database> The name of the mysql/mariadb database (env MYSQL_DATABASE)
36 -U|--dbuser <username> The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME)
37 -P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
38 -u|--urlpath <url_path> The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH)
39 -b|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
40 -A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
41 -T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
42 -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
45 MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used)
46 MYSQL_PORT The port of the mysql/mariadb database
47 MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb)
48 MYSQL_PASSWORD The password of the mysql/mariadb database login
49 MYSQL_DATABASE The name of the mysql/mariadb database
50 FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica')
51 FRIENDICA_PHP_PATH The path of the PHP binary
52 FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access)
53 FRIENDICA_TZ The timezone of Friendica
54 FRIENDICA_LANG The langauge of Friendica
57 bin/console autoinstall -f 'input.config.php
58 Installs Friendica with the prepared 'input.config.php' file
60 bin/console autoinstall --savedb
61 Installs Friendica with environment variables and saves them to the 'config/local.config.php' file
63 bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica
64 Installs Friendica with a local mysql database with credentials
68 protected function doExecute()
71 $this->out("Initializing setup...\n");
73 $a = BaseObject::getApp();
75 $installer = new Installer();
77 $this->out(" Complete!\n\n");
80 $this->out("Checking environment...\n");
82 $installer->resetChecks();
84 if (!$this->runBasicChecks($installer)) {
85 $errorMessage = $this->extractErrors($installer->getChecks());
86 throw new RuntimeException($errorMessage);
89 $this->out(" Complete!\n\n");
91 // if a config file is set,
92 $config_file = $this->getOption(['f', 'file']);
94 if (!empty($config_file)) {
95 if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.config.php') {
97 $this->out("Copying config file...\n");
98 if (!copy($a->getBasePath() . DIRECTORY_SEPARATOR . $config_file, $a->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
99 throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $a->getBasePath() . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n");
103 $db_host = $a->getConfigCache()->get('database', 'hostname');
104 $db_user = $a->getConfigCache()->get('database', 'username');
105 $db_pass = $a->getConfigCache()->get('database', 'password');
106 $db_data = $a->getConfigCache()->get('database', 'database');
108 // Creating config file
109 $this->out("Creating config file...\n");
111 $save_db = $this->getOption(['s', 'savedb'], false);
113 $db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? getenv('MYSQL_HOST') : '');
114 $db_port = $this->getOption(['p', 'dbport'], ($save_db) ? getenv('MYSQL_PORT') : null);
115 $db_data = $this->getOption(['d', 'dbdata'], ($save_db) ? getenv('MYSQL_DATABASE') : '');
116 $db_user = $this->getOption(['U', 'dbuser'], ($save_db) ? getenv('MYSQL_USER') . getenv('MYSQL_USERNAME') : '');
117 $db_pass = $this->getOption(['P', 'dbpass'], ($save_db) ? getenv('MYSQL_PASSWORD') : '');
118 $url_path = $this->getOption(['u', 'urlpath'], !empty('FRIENDICA_URL_PATH') ? getenv('FRIENDICA_URL_PATH') : null);
119 $php_path = $this->getOption(['b', 'phppath'], !empty('FRIENDICA_PHP_PATH') ? getenv('FRIENDICA_PHP_PATH') : null);
120 $admin_mail = $this->getOption(['A', 'admin'], !empty('FRIENDICA_ADMIN_MAIL') ? getenv('FRIENDICA_ADMIN_MAIL') : '');
121 $tz = $this->getOption(['T', 'tz'], !empty('FRIENDICA_TZ') ? getenv('FRIENDICA_TZ') : '');
122 $lang = $this->getOption(['L', 'lang'], !empty('FRIENDICA_LANG') ? getenv('FRIENDICA_LANG') : '');
124 if (empty($php_path)) {
125 $php_path = $installer->getPHPPath();
128 $installer->createConfig(
131 (!empty($db_port) ? $db_host . ':' . $db_port : $db_host),
142 $this->out(" Complete!\n\n");
144 // Check database connection
145 $this->out("Checking database...\n");
147 $installer->resetChecks();
149 if (!$installer->checkDB($a->getBasePath(), $a->getConfigCache(), $a->getProfiler(), $db_host, $db_user, $db_pass, $db_data)) {
150 $errorMessage = $this->extractErrors($installer->getChecks());
151 throw new RuntimeException($errorMessage);
154 $this->out(" Complete!\n\n");
157 $this->out("Inserting data into database...\n");
159 $installer->resetChecks();
161 if (!$installer->installDatabase($a->getBasePath())) {
162 $errorMessage = $this->extractErrors($installer->getChecks());
163 throw new RuntimeException($errorMessage);
166 $this->out(" Complete!\n\n");
169 $this->out("Installing theme\n");
170 if (!empty(Config::get('system', 'theme'))) {
171 Theme::install(Config::get('system', 'theme'));
172 $this->out(" Complete\n\n");
174 $this->out(" Theme setting is empty. Please check the file 'config/local.config.php'\n\n");
177 $this->out("\nInstallation is finished\n");
183 * @param Installer $installer the Installer instance
185 * @return bool true if checks were successfully, otherwise false
186 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
188 private function runBasicChecks(Installer $installer)
192 $installer->resetChecks();
193 if (!$installer->checkFunctions()) {
196 if (!$installer->checkImagick()) {
199 if (!$installer->checkLocalIni()) {
202 if (!$installer->checkSmarty3()) {
205 if (!$installer->checkKeys()) {
210 if (!empty(Config::get('config', 'php_path'))) {
211 $php_path = Config::get('config', 'php_path');
214 if (!$installer->checkPHP($php_path, true)) {
218 $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
224 * @param array $results
227 private function extractErrors($results)
230 $allChecksRequired = $this->getOption('a') !== null;
232 foreach ($results as $result) {
233 if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
234 $errorMessage .= "--------\n";
235 $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
239 return $errorMessage;