2 require_once "include/Photo.php";
4 $install_wizard_pass=1;
7 function install_init(App $a) {
9 // $baseurl/install/testrwrite to test if rewite in .htaccess is working
10 if ($a->argc == 2 && $a->argv[1] == "testrewrite") {
15 // We overwrite current theme css, because during install we could not have a working mod_rewrite
16 // so we could not have a css at all. Here we set a static css file for the install procedure pages
17 $a->config['system']['theme'] = "../install";
18 $a->theme['stylesheet'] = App::get_baseurl()."/view/install/style.css";
20 global $install_wizard_pass;
21 if (x($_POST, 'pass')) {
22 $install_wizard_pass = intval($_POST['pass']);
27 function install_post(App $a) {
28 global $install_wizard_pass, $db;
30 switch($install_wizard_pass) {
34 break; // just in case return don't return :)
36 $urlpath = $a->get_path();
37 $dbhost = notags(trim($_POST['dbhost']));
38 $dbuser = notags(trim($_POST['dbuser']));
39 $dbpass = notags(trim($_POST['dbpass']));
40 $dbdata = notags(trim($_POST['dbdata']));
41 $phpath = notags(trim($_POST['phpath']));
43 require_once("include/dba.php");
45 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
46 if (!$db->connected) {
47 $a->data['db_conn_failed'] = true;
53 $urlpath = $a->get_path();
54 $dbhost = notags(trim($_POST['dbhost']));
55 $dbuser = notags(trim($_POST['dbuser']));
56 $dbpass = notags(trim($_POST['dbpass']));
57 $dbdata = notags(trim($_POST['dbdata']));
58 $phpath = notags(trim($_POST['phpath']));
59 $timezone = notags(trim($_POST['timezone']));
60 $language = notags(trim($_POST['language']));
61 $adminmail = notags(trim($_POST['adminmail']));
65 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
67 $tpl = get_markup_template('htconfig.tpl');
68 $txt = replace_macros($tpl,array(
73 '$timezone' => $timezone,
74 '$language' => $language,
75 '$urlpath' => $urlpath,
77 '$adminmail' => $adminmail,
82 $result = file_put_contents('.htconfig.php', $txt);
84 $a->data['txt'] = $txt;
87 $errors = load_database($db);
91 $a->data['db_failed'] = $errors;
93 $a->data['db_installed'] = true;
101 function install_content(App $a) {
103 global $install_wizard_pass, $db;
106 $install_title = t('Friendica Communications Server - Setup');
110 if (x($a->data, 'db_conn_failed')) {
111 $install_wizard_pass = 2;
112 $wizard_status = t('Could not connect to database.');
114 if (x($a->data, 'db_create_failed')) {
115 $install_wizard_pass = 2;
116 $wizard_status = t('Could not create table.');
119 $db_return_text = "";
120 if (x($a->data, 'db_installed')) {
121 $txt = '<p style="font-size: 130%;">';
122 $txt .= t('Your Friendica site database has been installed.') . EOL;
123 $db_return_text .= $txt;
126 if (x($a->data, 'db_failed')) {
127 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
128 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>";
129 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL;
130 $db_return_text .= $txt;
133 if ($db && $db->connected) {
134 $r = q("SELECT COUNT(*) as `total` FROM `user`");
135 if (dbm::is_result($r) && $r[0]['total']) {
136 $tpl = get_markup_template('install.tpl');
137 return replace_macros($tpl, array(
138 '$title' => $install_title,
140 '$status' => t('Database already in use.'),
146 if (x($a->data, 'txt') && strlen($a->data['txt'])) {
147 $db_return_text .= manual_config($a);
150 if ($db_return_text != "") {
151 $tpl = get_markup_template('install.tpl');
152 return replace_macros($tpl, array(
153 '$title' => $install_title,
155 '$text' => $db_return_text . what_next(),
159 switch ($install_wizard_pass) {
160 case 1: { // System check
165 check_funcs($checks);
167 check_imagik($checks);
169 check_htconfig($checks);
171 check_smarty3($checks);
175 if (x($_POST, 'phpath')) {
176 $phpath = notags(trim($_POST['phpath']));
179 check_php($phpath, $checks);
181 check_htaccess($checks);
183 /// @TODO Maybe move this out?
184 function check_passed($v, $c) {
185 if ($c['required']) {
186 $v = $v && $c['status'];
190 $checkspassed = array_reduce($checks, "check_passed", true);
194 $tpl = get_markup_template('install_checks.tpl');
195 $o .= replace_macros($tpl, array(
196 '$title' => $install_title,
197 '$pass' => t('System check'),
198 '$checks' => $checks,
199 '$passed' => $checkspassed,
200 '$see_install' => t('Please see the file "INSTALL.txt".'),
201 '$next' => t('Next'),
202 '$reload' => t('Check again'),
203 '$phpath' => $phpath,
204 '$baseurl' => App::get_baseurl(),
209 case 2: { // Database config
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']));
218 $tpl = get_markup_template('install_db.tpl');
219 $o .= replace_macros($tpl, array(
220 '$title' => $install_title,
221 '$pass' => t('Database connection'),
222 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
223 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
224 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
226 '$status' => $wizard_status,
228 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
229 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
230 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, t("For security reasons the password must not be empty"), 'required'),
231 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
232 '$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'),
236 '$lbl_10' => t('Please select a default timezone for your website'),
238 '$baseurl' => App::get_baseurl(),
240 '$phpath' => $phpath,
242 '$submit' => t('Submit'),
247 case 3: { // Site settings
248 require_once('include/datetime.php');
249 $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
250 $dbuser = notags(trim($_POST['dbuser']));
251 $dbpass = notags(trim($_POST['dbpass']));
252 $dbdata = notags(trim($_POST['dbdata']));
253 $phpath = notags(trim($_POST['phpath']));
255 $adminmail = notags(trim($_POST['adminmail']));
256 $timezone = ((x($_POST, 'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
257 /* Installed langs */
258 $lang_choices = get_available_languages();
260 $tpl = get_markup_template('install_settings.tpl');
261 $o .= replace_macros($tpl, array(
262 '$title' => $install_title,
263 '$pass' => t('Site settings'),
265 '$status' => $wizard_status,
267 '$dbhost' => $dbhost,
268 '$dbuser' => $dbuser,
269 '$dbpass' => $dbpass,
270 '$dbdata' => $dbdata,
271 '$phpath' => $phpath,
273 '$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'),
276 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
277 '$language' => array('language', t('System Language:'), 'en', t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices),
278 '$baseurl' => App::get_baseurl(),
282 '$submit' => t('Submit'),
292 * checks : array passed to template
296 * help : string optional
298 function check_add(&$checks, $title, $status, $required, $help) {
302 'required' => $required,
307 function check_php(&$phpath, &$checks) {
308 $passed = $passed2 = $passed3 = false;
309 if (strlen($phpath)) {
310 $passed = file_exists($phpath);
312 $phpath = trim(shell_exec('which php'));
313 $passed = strlen($phpath);
317 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
318 $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;
320 $tpl = get_markup_template('field_input.tpl');
321 $help .= replace_macros($tpl, array(
322 '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
327 check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
331 $result = trim(shell_exec($cmd));
332 $passed2 = ( strpos($result, "(cli)") !== false);
333 list($result) = explode("\n", $result);
336 $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
337 $help .= t('Found PHP version: ')."<tt>$result</tt>";
339 check_add($checks, t('PHP cli binary'), $passed2, true, $help);
345 $cmd = "$phpath testargs.php $str";
346 $result = trim(shell_exec($cmd));
347 $passed3 = $result == $str;
350 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
351 $help .= t('This is required for message delivery to work.');
353 check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
359 function check_keys(&$checks) {
365 if (function_exists('openssl_pkey_new')) {
366 $res = openssl_pkey_new(array(
367 'digest_alg' => 'sha1',
368 'private_key_bits' => 4096,
369 'encrypt_key' => false
376 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
377 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
379 check_add($checks, t('Generate encryption keys'), $res, true, $help);
384 function check_funcs(&$checks) {
386 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
387 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
388 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
389 check_add($ck_funcs, t('PDO or MySQLi PHP module'), true, true, "");
390 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
391 check_add($ck_funcs, t('XML PHP module'), true, true, "");
392 check_add($ck_funcs, t('iconv module'), true, true, "");
394 if (function_exists('apache_get_modules')) {
395 if (! in_array('mod_rewrite',apache_get_modules())) {
396 check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
398 check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
402 if (! function_exists('curl_init')) {
403 $ck_funcs[0]['status'] = false;
404 $ck_funcs[0]['help'] = t('Error: libCURL PHP module required but not installed.');
406 if (! function_exists('imagecreatefromjpeg')) {
407 $ck_funcs[1]['status'] = false;
408 $ck_funcs[1]['help'] = t('Error: GD graphics PHP module with JPEG support required but not installed.');
410 if (! function_exists('openssl_public_encrypt')) {
411 $ck_funcs[2]['status'] = false;
412 $ck_funcs[2]['help'] = t('Error: openssl PHP module required but not installed.');
414 if (! function_exists('mysqli_connect') && !class_exists('pdo')) {
415 $ck_funcs[3]['status'] = false;
416 $ck_funcs[3]['help'] = t('Error: PDO or MySQLi PHP module required but not installed.');
418 if (! function_exists('mb_strlen')) {
419 $ck_funcs[4]['status'] = false;
420 $ck_funcs[4]['help'] = t('Error: mb_string PHP module required but not installed.');
422 if (! function_exists('iconv_strlen')) {
423 $ck_funcs[7]['status'] = false;
424 $ck_funcs[7]['help'] = t('Error: iconv PHP module required but not installed.');
427 $checks = array_merge($checks, $ck_funcs);
429 // check for XML DOM Documents being able to be generated
431 $xml = new DOMDocument();
432 } catch (Exception $e) {
433 $ck_funcs[6]['status'] = false;
434 $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.');
439 function check_htconfig(&$checks) {
442 if ((file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
443 (!file_exists('.htconfig.php') && !is_writable('.'))) {
446 $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;
447 $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;
448 $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;
449 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
452 check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
456 function check_smarty3(&$checks) {
459 if (!is_writable('view/smarty3')) {
462 $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
463 $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;
464 $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
465 $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;
468 check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
472 function check_htaccess(&$checks) {
475 if (function_exists('curl_init')) {
476 $test = fetch_url(App::get_baseurl()."/install/testrewrite");
479 $test = fetch_url(normalise_link(App::get_baseurl()."/install/testrewrite"));
484 $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
486 check_add($checks, t('Url rewrite is working'), $status, true, $help);
488 // cannot check modrewrite if libcurl is not installed
489 /// @TODO Maybe issue warning here?
493 function check_imagik(&$checks) {
497 if (class_exists('Imagick')) {
499 $supported = Photo::supportedTypes();
500 if (array_key_exists('image/gif', $supported)) {
504 if ($imagick == false) {
505 check_add($checks, t('ImageMagick PHP extension is not installed'), $imagick, false, "");
507 check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
509 check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
514 function manual_config(App $a) {
515 $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8');
516 $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.');
517 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
521 function load_database_rem($v, $i) {
523 if (strlen($l)>1 && ($l[0] == "-" || ($l[0] == "/" && $l[1] == "*"))) {
530 function load_database($db) {
532 require_once("include/dbstructure.php");
533 $errors = update_structure(false, true);
538 function what_next() {
539 $baseurl = App::get_baseurl();
541 t('<h1>What next</h1>')
542 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
543 .t('Please see the file "INSTALL.txt".')
545 .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.")