3 namespace Friendica\Module;
6 use Friendica\BaseModule;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Renderer;
10 use Friendica\Util\Strings;
11 use Friendica\Util\Temporal;
13 class Install extends BaseModule
16 * Step one - System check
18 const SYSTEM_CHECK = 1;
20 * Step two - Database configuration
22 const DATABASE_CONFIG = 2;
24 * Step three - Adapat site settings
26 const SITE_SETTINGS = 3;
28 * Step four - All steps finished
33 * @var int The current step of the wizard
35 private static $currentWizardStep;
38 * @var Core\Installer The installer
40 private static $installer;
42 public static function init()
46 if (!$a->getMode()->isInstall()) {
47 Core\System::httpExit(403);
50 // route: install/testrwrite
51 // $baseurl/install/testrwrite to test if rewrite in .htaccess is working
52 if ($a->getArgumentValue(1, '') == 'testrewrite') {
53 // Status Code 204 means that it worked without content
54 Core\System::httpExit(204);
57 // We overwrite current theme css, because during install we may not have a working mod_rewrite
58 // so we may not have a css at all. Here we set a static css file for the install procedure pages
59 Renderer::$theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css';
61 self::$installer = new Core\Installer();
62 self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK);
65 public static function post()
69 switch (self::$currentWizardStep) {
70 case self::SYSTEM_CHECK:
71 case self::DATABASE_CONFIG:
72 // Nothing to do in these steps
75 case self::SITE_SETTINGS:
76 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
77 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '')));
78 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '')));
79 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '')));
81 // If we cannot connect to the database, return to the previous step
82 if (!self::$installer->checkDB($a->getBasePath(), $a->getConfigCache(), $a->getProfiler(), $dbhost, $dbuser, $dbpass, $dbdata)) {
83 self::$currentWizardStep = self::DATABASE_CONFIG;
89 $urlpath = $a->getURLPath();
90 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
91 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '')));
92 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '')));
93 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '')));
94 $timezone = Strings::escapeTags(trim(defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ)));
95 $language = Strings::escapeTags(trim(defaults($_POST, 'language', Core\Installer::DEFAULT_LANG)));
96 $adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '')));
98 // If we cannot connect to the database, return to the Database config wizard
99 if (!self::$installer->checkDB($a->getBasePath(), $a->getConfigCache(), $a->getProfiler(), $dbhost, $dbuser, $dbpass, $dbdata)) {
100 self::$currentWizardStep = self::DATABASE_CONFIG;
104 $phpath = self::$installer->getPHPPath();
106 if (!self::$installer->createConfig($phpath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $a->getBasePath())) {
110 self::$installer->installDatabase($a->getBasePath());
116 public static function content()
122 $install_title = L10n::t('Friendica Communications Server - Setup');
124 switch (self::$currentWizardStep) {
125 case self::SYSTEM_CHECK:
126 $phppath = defaults($_POST, 'phpath', null);
128 $status = self::$installer->checkEnvironment($a->getBaseURL(), $phppath);
130 $tpl = Renderer::getMarkupTemplate('install_checks.tpl');
131 $output .= Renderer::replaceMacros($tpl, [
132 '$title' => $install_title,
133 '$pass' => L10n::t('System check'),
134 '$checks' => self::$installer->getChecks(),
135 '$passed' => $status,
136 '$see_install' => L10n::t('Please see the file "INSTALL.txt".'),
137 '$next' => L10n::t('Next'),
138 '$reload' => L10n::t('Check again'),
139 '$phpath' => $phppath,
140 '$baseurl' => $a->getBaseURL()
144 case self::DATABASE_CONFIG:
145 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost' , Core\Installer::DEFAULT_HOST)));
146 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser' , '' )));
147 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass' , '' )));
148 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata' , '' )));
149 $phpath = Strings::escapeTags(trim(defaults($_POST, 'phpath' , '' )));
150 $adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '' )));
152 $tpl = Renderer::getMarkupTemplate('install_db.tpl');
153 $output .= Renderer::replaceMacros($tpl, [
154 '$title' => $install_title,
155 '$pass' => L10n::t('Database connection'),
156 '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
157 '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
158 '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
159 'checks' => self::$installer->getChecks(),
160 '$dbhost' => ['dbhost',
161 L10n::t('Database Server Name'),
165 '$dbuser' => ['dbuser',
166 L10n::t('Database Login Name'),
171 '$dbpass' => ['dbpass',
172 L10n::t('Database Login Password'),
174 L10n::t("For security reasons the password must not be empty"),
176 '$dbdata' => ['dbdata',
177 L10n::t('Database Name'),
181 '$adminmail' => ['adminmail',
182 L10n::t('Site administrator email address'),
184 L10n::t('Your account email address must match this in order to use the web admin panel.'),
188 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
189 '$baseurl' => $a->getBaseURL(),
190 '$phpath' => $phpath,
191 '$submit' => L10n::t('Submit')
195 case self::SITE_SETTINGS:
196 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
197 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '' )));
198 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '' )));
199 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '' )));
200 $phpath = Strings::escapeTags(trim(defaults($_POST, 'phpath', '' )));
202 $adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '')));
204 $timezone = defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ);
205 /* Installed langs */
206 $lang_choices = L10n::getAvailableLanguages();
208 $tpl = Renderer::getMarkupTemplate('install_settings.tpl');
209 $output .= Renderer::replaceMacros($tpl, [
210 '$title' => $install_title,
211 '$checks' => self::$installer->getChecks(),
212 '$pass' => L10n::t('Site settings'),
213 '$dbhost' => $dbhost,
214 '$dbuser' => $dbuser,
215 '$dbpass' => $dbpass,
216 '$dbdata' => $dbdata,
217 '$phpath' => $phpath,
218 '$adminmail' => ['adminmail', L10n::t('Site administrator email address'), $adminmail, L10n::t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'],
219 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
220 '$language' => ['language',
221 L10n::t('System Language:'),
222 Core\Installer::DEFAULT_LANG,
223 L10n::t('Set the default language for your Friendica installation interface and to send emails.'),
225 '$baseurl' => $a->getBaseURL(),
226 '$submit' => L10n::t('Submit')
231 $db_return_text = "";
233 if (count(self::$installer->getChecks()) == 0) {
234 $txt = '<p style="font-size: 130%;">';
235 $txt .= L10n::t('Your Friendica site database has been installed.') . EOL;
236 $db_return_text .= $txt;
239 $tpl = Renderer::getMarkupTemplate('install_finished.tpl');
240 $output .= Renderer::replaceMacros($tpl, [
241 '$title' => $install_title,
242 '$checks' => self::$installer->getChecks(),
243 '$pass' => L10n::t('Installation finished'),
244 '$text' => $db_return_text . self::whatNext($a),
254 * Creates the text for the next steps
256 * @param App $a The global App
258 * @return string The text for the next steps
259 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
261 private static function whatNext($a)
263 $baseurl = $a->getBaseUrl();
265 L10n::t('<h1>What next</h1>')
266 . "<p>".L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
267 . L10n::t('Please see the file "INSTALL.txt".')
269 . L10n::t('Go to your new Friendica node <a href="%s/register">registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.', $baseurl)