5 require_once "include/Photo.php";
7 $install_wizard_pass = 1;
9 function install_init(App $a) {
11 // $baseurl/install/testrwrite to test if rewite in .htaccess is working
12 if ($a->argc == 2 && $a->argv[1] == "testrewrite") {
17 // We overwrite current theme css, because during install we could not have a working mod_rewrite
18 // so we could not have a css at all. Here we set a static css file for the install procedure pages
19 $a->config['system']['theme'] = "../install";
20 $a->theme['stylesheet'] = App::get_baseurl()."/view/install/style.css";
22 global $install_wizard_pass;
23 if (x($_POST, 'pass')) {
24 $install_wizard_pass = intval($_POST['pass']);
29 function install_post(App $a) {
30 global $install_wizard_pass, $db;
32 switch($install_wizard_pass) {
36 break; // just in case return don't return :)
38 $urlpath = $a->get_path();
39 $dbhost = notags(trim($_POST['dbhost']));
40 $dbuser = notags(trim($_POST['dbuser']));
41 $dbpass = notags(trim($_POST['dbpass']));
42 $dbdata = notags(trim($_POST['dbdata']));
43 $phpath = notags(trim($_POST['phpath']));
45 require_once("include/dba.php");
47 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
48 if (!$db->connected) {
49 $a->data['db_conn_failed'] = true;
55 $urlpath = $a->get_path();
56 $dbhost = notags(trim($_POST['dbhost']));
57 $dbuser = notags(trim($_POST['dbuser']));
58 $dbpass = notags(trim($_POST['dbpass']));
59 $dbdata = notags(trim($_POST['dbdata']));
60 $phpath = notags(trim($_POST['phpath']));
61 $timezone = notags(trim($_POST['timezone']));
62 $language = notags(trim($_POST['language']));
63 $adminmail = notags(trim($_POST['adminmail']));
67 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
69 $tpl = get_markup_template('htconfig.tpl');
70 $txt = replace_macros($tpl,array(
75 '$timezone' => $timezone,
76 '$language' => $language,
77 '$urlpath' => $urlpath,
79 '$adminmail' => $adminmail,
84 $result = file_put_contents('.htconfig.php', $txt);
86 $a->data['txt'] = $txt;
89 $errors = load_database($db);
93 $a->data['db_failed'] = $errors;
95 $a->data['db_installed'] = true;
103 function install_content(App $a) {
105 global $install_wizard_pass, $db;
108 $install_title = t('Friendica Communications Server - Setup');
112 if (x($a->data, 'db_conn_failed')) {
113 $install_wizard_pass = 2;
114 $wizard_status = t('Could not connect to database.');
116 if (x($a->data, 'db_create_failed')) {
117 $install_wizard_pass = 2;
118 $wizard_status = t('Could not create table.');
121 $db_return_text = "";
122 if (x($a->data, 'db_installed')) {
123 $txt = '<p style="font-size: 130%;">';
124 $txt .= t('Your Friendica site database has been installed.') . EOL;
125 $db_return_text .= $txt;
128 if (x($a->data, 'db_failed')) {
129 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
130 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>";
131 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL;
132 $db_return_text .= $txt;
135 if ($db && $db->connected) {
136 $r = q("SELECT COUNT(*) as `total` FROM `user`");
137 if (dbm::is_result($r) && $r[0]['total']) {
138 $tpl = get_markup_template('install.tpl');
139 return replace_macros($tpl, array(
140 '$title' => $install_title,
142 '$status' => t('Database already in use.'),
148 if (x($a->data, 'txt') && strlen($a->data['txt'])) {
149 $db_return_text .= manual_config($a);
152 if ($db_return_text != "") {
153 $tpl = get_markup_template('install.tpl');
154 return replace_macros($tpl, array(
155 '$title' => $install_title,
157 '$text' => $db_return_text . what_next(),
161 switch ($install_wizard_pass) {
162 case 1: { // System check
167 check_funcs($checks);
169 check_imagik($checks);
171 check_htconfig($checks);
173 check_smarty3($checks);
177 if (x($_POST, 'phpath')) {
178 $phpath = notags(trim($_POST['phpath']));
181 check_php($phpath, $checks);
183 check_htaccess($checks);
185 /// @TODO Maybe move this out?
186 function check_passed($v, $c) {
187 if ($c['required']) {
188 $v = $v && $c['status'];
192 $checkspassed = array_reduce($checks, "check_passed", true);
196 $tpl = get_markup_template('install_checks.tpl');
197 $o .= replace_macros($tpl, array(
198 '$title' => $install_title,
199 '$pass' => t('System check'),
200 '$checks' => $checks,
201 '$passed' => $checkspassed,
202 '$see_install' => t('Please see the file "INSTALL.txt".'),
203 '$next' => t('Next'),
204 '$reload' => t('Check again'),
205 '$phpath' => $phpath,
206 '$baseurl' => App::get_baseurl(),
211 case 2: { // Database config
213 $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
214 $dbuser = notags(trim($_POST['dbuser']));
215 $dbpass = notags(trim($_POST['dbpass']));
216 $dbdata = notags(trim($_POST['dbdata']));
217 $phpath = notags(trim($_POST['phpath']));
220 $tpl = get_markup_template('install_db.tpl');
221 $o .= replace_macros($tpl, array(
222 '$title' => $install_title,
223 '$pass' => t('Database connection'),
224 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
225 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
226 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
228 '$status' => $wizard_status,
230 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
231 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
232 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, t("For security reasons the password must not be empty"), 'required'),
233 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
234 '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'),
238 '$lbl_10' => t('Please select a default timezone for your website'),
240 '$baseurl' => App::get_baseurl(),
242 '$phpath' => $phpath,
244 '$submit' => t('Submit'),
249 case 3: { // Site settings
250 require_once('include/datetime.php');
251 $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
252 $dbuser = notags(trim($_POST['dbuser']));
253 $dbpass = notags(trim($_POST['dbpass']));
254 $dbdata = notags(trim($_POST['dbdata']));
255 $phpath = notags(trim($_POST['phpath']));
257 $adminmail = notags(trim($_POST['adminmail']));
258 $timezone = ((x($_POST, 'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
259 /* Installed langs */
260 $lang_choices = get_available_languages();
262 $tpl = get_markup_template('install_settings.tpl');
263 $o .= replace_macros($tpl, array(
264 '$title' => $install_title,
265 '$pass' => t('Site settings'),
267 '$status' => $wizard_status,
269 '$dbhost' => $dbhost,
270 '$dbuser' => $dbuser,
271 '$dbpass' => $dbpass,
272 '$dbdata' => $dbdata,
273 '$phpath' => $phpath,
275 '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'),
278 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
279 '$language' => array('language', t('System Language:'), 'en', t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices),
280 '$baseurl' => App::get_baseurl(),
284 '$submit' => t('Submit'),
294 * checks : array passed to template
298 * help : string optional
300 function check_add(&$checks, $title, $status, $required, $help) {
304 'required' => $required,
309 function check_php(&$phpath, &$checks) {
310 $passed = $passed2 = $passed3 = false;
311 if (strlen($phpath)) {
312 $passed = file_exists($phpath);
314 $phpath = trim(shell_exec('which php'));
315 $passed = strlen($phpath);
319 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
320 $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run the background processing. See <a href='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-poller'>'Setup the poller'</a>") . EOL;
322 $tpl = get_markup_template('field_input.tpl');
323 $help .= replace_macros($tpl, array(
324 '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
329 check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
333 $result = trim(shell_exec($cmd));
334 $passed2 = ( strpos($result, "(cli)") !== false);
335 list($result) = explode("\n", $result);
338 $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
339 $help .= t('Found PHP version: ')."<tt>$result</tt>";
341 check_add($checks, t('PHP cli binary'), $passed2, true, $help);
347 $cmd = "$phpath testargs.php $str";
348 $result = trim(shell_exec($cmd));
349 $passed3 = $result == $str;
352 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
353 $help .= t('This is required for message delivery to work.');
355 check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
361 function check_keys(&$checks) {
367 if (function_exists('openssl_pkey_new')) {
368 $res = openssl_pkey_new(array(
369 'digest_alg' => 'sha1',
370 'private_key_bits' => 4096,
371 'encrypt_key' => false
378 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
379 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
381 check_add($checks, t('Generate encryption keys'), $res, true, $help);
386 function check_funcs(&$checks) {
388 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
389 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
390 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
391 check_add($ck_funcs, t('PDO or MySQLi PHP module'), true, true, "");
392 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
393 check_add($ck_funcs, t('XML PHP module'), true, true, "");
394 check_add($ck_funcs, t('iconv module'), true, true, "");
396 if (function_exists('apache_get_modules')) {
397 if (! in_array('mod_rewrite',apache_get_modules())) {
398 check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
400 check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
404 if (! function_exists('curl_init')) {
405 $ck_funcs[0]['status'] = false;
406 $ck_funcs[0]['help'] = t('Error: libCURL PHP module required but not installed.');
408 if (! function_exists('imagecreatefromjpeg')) {
409 $ck_funcs[1]['status'] = false;
410 $ck_funcs[1]['help'] = t('Error: GD graphics PHP module with JPEG support required but not installed.');
412 if (! function_exists('openssl_public_encrypt')) {
413 $ck_funcs[2]['status'] = false;
414 $ck_funcs[2]['help'] = t('Error: openssl PHP module required but not installed.');
416 if (! function_exists('mysqli_connect') && !class_exists('pdo')) {
417 $ck_funcs[3]['status'] = false;
418 $ck_funcs[3]['help'] = t('Error: PDO or MySQLi PHP module required but not installed.');
420 if (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', PDO::getAvailableDrivers())) {
421 $ck_funcs[3]['status'] = false;
422 $ck_funcs[3]['help'] = t('Error: The MySQL driver for PDO is not installed.');
424 if (! function_exists('mb_strlen')) {
425 $ck_funcs[4]['status'] = false;
426 $ck_funcs[4]['help'] = t('Error: mb_string PHP module required but not installed.');
428 if (! function_exists('iconv_strlen')) {
429 $ck_funcs[7]['status'] = false;
430 $ck_funcs[7]['help'] = t('Error: iconv PHP module required but not installed.');
433 $checks = array_merge($checks, $ck_funcs);
435 // check for XML DOM Documents being able to be generated
437 $xml = new DOMDocument();
438 } catch (Exception $e) {
439 $ck_funcs[6]['status'] = false;
440 $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.');
445 function check_htconfig(&$checks) {
448 if ((file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
449 (!file_exists('.htconfig.php') && !is_writable('.'))) {
452 $help = t('The web installer needs to be able to create a file called ".htconfig.php" in the top folder of your web server and it is unable to do so.') .EOL;
453 $help .= t('This is most often a permission setting, as the web server may not be able to write files in your folder - even if you can.').EOL;
454 $help .= t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Friendica top folder.').EOL;
455 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
458 check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
462 function check_smarty3(&$checks) {
465 if (!is_writable('view/smarty3')) {
468 $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
469 $help .= t('In order to store these compiled templates, the web server needs to have write access to the directory view/smarty3/ under the Friendica top level folder.').EOL;
470 $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
471 $help .= t('Note: as a security measure, you should give the web server write access to view/smarty3/ only--not the template files (.tpl) that it contains.').EOL;
474 check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
478 function check_htaccess(&$checks) {
481 if (function_exists('curl_init')) {
482 $test = fetch_url(App::get_baseurl()."/install/testrewrite");
485 $test = fetch_url(normalise_link(App::get_baseurl()."/install/testrewrite"));
490 $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
492 check_add($checks, t('Url rewrite is working'), $status, true, $help);
494 // cannot check modrewrite if libcurl is not installed
495 /// @TODO Maybe issue warning here?
499 function check_imagik(&$checks) {
503 if (class_exists('Imagick')) {
505 $supported = Photo::supportedTypes();
506 if (array_key_exists('image/gif', $supported)) {
510 if ($imagick == false) {
511 check_add($checks, t('ImageMagick PHP extension is not installed'), $imagick, false, "");
513 check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
515 check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
520 function manual_config(App $a) {
521 $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8');
522 $o = t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.');
523 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
527 function load_database_rem($v, $i) {
529 if (strlen($l)>1 && ($l[0] == "-" || ($l[0] == "/" && $l[1] == "*"))) {
536 function load_database($db) {
538 require_once("include/dbstructure.php");
539 $errors = update_structure(false, true);
544 function what_next() {
545 $baseurl = App::get_baseurl();
547 t('<h1>What next</h1>')
548 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
549 .t('Please see the file "INSTALL.txt".')
551 .t("Go to your new Friendica node <a href='$baseurl/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.")