3 * @file mod/install.php
7 use Friendica\Core\Install;
8 use Friendica\Core\L10n;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\Util\Temporal;
13 $install_wizard_pass = 1;
15 function install_init(App $a) {
17 // $baseurl/install/testrwrite to test if rewite in .htaccess is working
18 if ($a->argc == 2 && $a->argv[1] == "testrewrite") {
23 // We overwrite current theme css, because during install we could not have a working mod_rewrite
24 // so we could not have a css at all. Here we set a static css file for the install procedure pages
26 $a->setConfigValue('system', 'value', '../install');
27 $a->theme['stylesheet'] = System::baseUrl()."/view/install/style.css";
29 Install::setInstallMode();
31 global $install_wizard_pass;
32 if (x($_POST, 'pass')) {
33 $install_wizard_pass = intval($_POST['pass']);
38 function install_post(App $a) {
39 global $install_wizard_pass;
41 switch($install_wizard_pass) {
45 break; // just in case return don't return :)
47 $urlpath = $a->get_path();
48 $dbhost = notags(trim($_POST['dbhost']));
49 $dbuser = notags(trim($_POST['dbuser']));
50 $dbpass = notags(trim($_POST['dbpass']));
51 $dbdata = notags(trim($_POST['dbdata']));
52 $phpath = notags(trim($_POST['phpath']));
54 require_once("include/dba.php");
55 if (!DBA::connect($dbhost, $dbuser, $dbpass, $dbdata)) {
56 $a->data['db_conn_failed'] = true;
62 $urlpath = $a->get_path();
63 $dbhost = notags(trim($_POST['dbhost']));
64 $dbuser = notags(trim($_POST['dbuser']));
65 $dbpass = notags(trim($_POST['dbpass']));
66 $dbdata = notags(trim($_POST['dbdata']));
67 $phpath = notags(trim($_POST['phpath']));
68 $timezone = notags(trim($_POST['timezone']));
69 $language = notags(trim($_POST['language']));
70 $adminmail = notags(trim($_POST['adminmail']));
73 DBA::connect($dbhost, $dbuser, $dbpass, $dbdata);
75 $errors = Install::createConfig($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail);
78 $a->data['db_failed'] = $errors;
82 $errors = Install::installDatabaseStructure();
85 $a->data['db_failed'] = $errors;
87 $a->data['db_installed'] = true;
95 function install_content(App $a) {
97 global $install_wizard_pass;
100 $install_title = L10n::t('Friendica Communications Server - Setup');
104 if (x($a->data, 'db_conn_failed')) {
105 $install_wizard_pass = 2;
106 $wizard_status = L10n::t('Could not connect to database.');
108 if (x($a->data, 'db_create_failed')) {
109 $install_wizard_pass = 2;
110 $wizard_status = L10n::t('Could not create table.');
113 $db_return_text = "";
114 if (x($a->data, 'db_installed')) {
115 $txt = '<p style="font-size: 130%;">';
116 $txt .= L10n::t('Your Friendica site database has been installed.') . EOL;
117 $db_return_text .= $txt;
120 if (x($a->data, 'db_failed')) {
121 $txt = L10n::t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
122 $txt .= L10n::t('Please see the file "INSTALL.txt".') . EOL ."<hr>";
123 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL;
124 $db_return_text .= $txt;
127 if (DBA::$connected) {
128 $r = q("SELECT COUNT(*) as `total` FROM `user`");
129 if (DBA::isResult($r) && $r[0]['total']) {
130 $tpl = get_markup_template('install.tpl');
131 return replace_macros($tpl, [
132 '$title' => $install_title,
134 '$status' => L10n::t('Database already in use.'),
140 if (x($a->data, 'txt') && strlen($a->data['txt'])) {
141 $db_return_text .= manual_config($a);
144 if ($db_return_text != "") {
145 $tpl = get_markup_template('install.tpl');
146 return replace_macros($tpl, [
147 '$title' => $install_title,
149 '$text' => $db_return_text . what_next(),
153 switch ($install_wizard_pass) {
154 case 1: { // System check
156 $phpath = defaults($_POST, 'phpath', 'php');
158 list($checks, $checkspassed) = Install::check($phpath);
160 $tpl = get_markup_template('install_checks.tpl');
161 $o .= replace_macros($tpl, [
162 '$title' => $install_title,
163 '$pass' => L10n::t('System check'),
164 '$checks' => $checks,
165 '$passed' => $checkspassed,
166 '$see_install' => L10n::t('Please see the file "INSTALL.txt".'),
167 '$next' => L10n::t('Next'),
168 '$reload' => L10n::t('Check again'),
169 '$phpath' => $phpath,
170 '$baseurl' => System::baseUrl(),
175 case 2: { // Database config
177 $dbhost = notags(trim(defaults($_POST, 'dbhost' , 'localhost')));
178 $dbuser = notags(trim(defaults($_POST, 'dbuser' , '' )));
179 $dbpass = notags(trim(defaults($_POST, 'dbpass' , '' )));
180 $dbdata = notags(trim(defaults($_POST, 'dbdata' , '' )));
181 $phpath = notags(trim(defaults($_POST, 'phpath' , '' )));
182 $adminmail = notags(trim(defaults($_POST, 'adminmail', '' )));
184 $tpl = get_markup_template('install_db.tpl');
185 $o .= replace_macros($tpl, [
186 '$title' => $install_title,
187 '$pass' => L10n::t('Database connection'),
188 '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
189 '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
190 '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
192 '$status' => $wizard_status,
194 '$dbhost' => ['dbhost', L10n::t('Database Server Name'), $dbhost, '', 'required'],
195 '$dbuser' => ['dbuser', L10n::t('Database Login Name'), $dbuser, '', 'required', 'autofocus'],
196 '$dbpass' => ['dbpass', L10n::t('Database Login Password'), $dbpass, L10n::t("For security reasons the password must not be empty"), 'required'],
197 '$dbdata' => ['dbdata', L10n::t('Database Name'), $dbdata, '', 'required'],
198 '$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'],
200 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
202 '$baseurl' => System::baseUrl(),
204 '$phpath' => $phpath,
206 '$submit' => L10n::t('Submit'),
210 case 3: { // Site settings
211 $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
212 $dbuser = notags(trim($_POST['dbuser']));
213 $dbpass = notags(trim($_POST['dbpass']));
214 $dbdata = notags(trim($_POST['dbdata']));
215 $phpath = notags(trim($_POST['phpath']));
217 $adminmail = notags(trim($_POST['adminmail']));
218 $timezone = ((x($_POST, 'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
219 /* Installed langs */
220 $lang_choices = L10n::getAvailableLanguages();
222 $tpl = get_markup_template('install_settings.tpl');
223 $o .= replace_macros($tpl, [
224 '$title' => $install_title,
225 '$pass' => L10n::t('Site settings'),
227 '$status' => $wizard_status,
229 '$dbhost' => $dbhost,
230 '$dbuser' => $dbuser,
231 '$dbpass' => $dbpass,
232 '$dbdata' => $dbdata,
233 '$phpath' => $phpath,
235 '$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'],
238 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
239 '$language' => ['language', L10n::t('System Language:'), 'en', L10n::t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices],
240 '$baseurl' => System::baseUrl(),
244 '$submit' => L10n::t('Submit'),
253 function manual_config(App $a) {
254 $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8');
255 $o = L10n::t('The database configuration file "config/local.ini.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.');
256 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
260 function load_database_rem($v, $i) {
262 if (strlen($l)>1 && ($l[0] == "-" || ($l[0] == "/" && $l[1] == "*"))) {
269 function what_next() {
270 $baseurl = System::baseUrl();
272 L10n::t('<h1>What next</h1>')
273 ."<p>".L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
274 .L10n::t('Please see the file "INSTALL.txt".')
276 .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)