3 * @file src/Core/Install.php
\r
5 namespace Friendica\Core;
\r
7 use Friendica\BaseObject;
\r
9 use Friendica\Database\DBStructure;
\r
10 use Friendica\Object\Image;
\r
11 use Friendica\Util\Network;
\r
17 * Contains methods for installation purpose of Friendica
\r
19 class Install extends BaseObject
\r
22 * Sets the install-mode for further methods
\r
24 public static function setInstallMode()
\r
26 self::getApp()->mode = App::MODE_INSTALL;
\r
30 * Checks the current installation environment. There are optional and mandatory checks.
\r
32 * @param string $phpath Optional path to the PHP binary (Default is 'php')
\r
34 * @return array First element is a list of all checks and their results,
\r
35 * the second element is a list of passed checks
\r
37 public static function check($phpath = 'php')
\r
41 self::checkFunctions($checks);
\r
43 self::checkImagick($checks);
\r
45 self::checkHtConfig($checks);
\r
47 self::checkSmarty3($checks);
\r
49 self::checkKeys($checks);
\r
51 self::checkPHP($phpath, $checks);
\r
53 self::checkHtAccess($checks);
\r
55 $checkspassed = array_reduce($checks,
\r
57 if (!empty($c['require'])) {
\r
58 $v = $v && $c['status'];
\r
64 return array($checks, $checkspassed);
\r
68 * Executes the installation of Friendica in the given environment.
\r
69 * - Creates `config/local.ini.php`
\r
70 * - Installs Database Structure
\r
72 * @param string $urlpath Path based on the URL of Friendica (e.g. '/friendica')
\r
73 * @param string $dbhost Hostname/IP of the Friendica Database
\r
74 * @param string $dbuser Username of the Database connection credentials
\r
75 * @param string $dbpass Password of the Database connection credentials
\r
76 * @param string $dbdata Name of the Database
\r
77 * @param string $phpath Path to the PHP-Binary (e.g. 'php' or '/usr/bin/php')
\r
78 * @param string $timezone Timezone of the Friendica Installaton (e.g. 'Europe/Berlin')
\r
79 * @param string $language 2-letter ISO 639-1 code (eg. 'en')
\r
80 * @param string $adminmail Mail-Adress of the administrator
\r
81 * @param int $rino Rino-enabled (1 = true, 0 = false)
\r
83 public static function install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail)
\r
85 $tpl = get_markup_template('local.ini.tpl');
\r
86 $txt = replace_macros($tpl,[
\r
87 '$dbhost' => $dbhost,
\r
88 '$dbuser' => $dbuser,
\r
89 '$dbpass' => $dbpass,
\r
90 '$dbdata' => $dbdata,
\r
91 '$timezone' => $timezone,
\r
92 '$language' => $language,
\r
93 '$urlpath' => $urlpath,
\r
94 '$phpath' => $phpath,
\r
95 '$adminmail' => $adminmail,
\r
98 $result = file_put_contents('config/local.ini.php', $txt);
\r
100 self::getApp()->data['txt'] = $txt;
\r
103 $errors = self::installDatabaseStructure();
\r
106 self::getApp()->data['db_failed'] = $errors;
\r
108 self::getApp()->data['db_installed'] = true;
\r
113 * Adds new checks to the array $checks
\r
115 * @param array $checks The list of all checks (by-ref parameter!)
\r
116 * @param string $title The title of the current check
\r
117 * @param bool $status 1 = check passed, 0 = check not passed
\r
118 * @param bool $required 1 = check is mandatory, 0 = check is optional
\r
119 * @param string $help A help-string for the current check
\r
120 * @param string $error_msg Optional. A error message, if the current check failed
\r
122 private static function addCheck(&$checks, $title, $status, $required, $help, $error_msg = "")
\r
126 'status' => $status,
\r
127 'required' => $required,
\r
129 'error_msg' => $error_msg,
\r
136 * Checks the PHP environment.
\r
138 * - Checks if a PHP binary is available
\r
139 * - Checks if it is the CLI version
\r
140 * - Checks if "register_argc_argv" is enabled
\r
142 * @param string $phpath Optional. The Path to the PHP-Binary
\r
143 * @param array $checks The list of all checks (by-ref parameter!)
\r
145 public static function checkPHP(&$phpath, &$checks)
\r
147 $passed = $passed2 = $passed3 = false;
\r
148 if (strlen($phpath)) {
\r
149 $passed = file_exists($phpath);
\r
151 $phpath = trim(shell_exec('which php'));
\r
152 $passed = strlen($phpath);
\r
156 $help .= L10n::t('Could not find a command line version of PHP in the web server PATH.') . EOL;
\r
157 $help .= L10n::t("If you don't have a command line version of PHP installed on your 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-worker'>'Setup the worker'</a>") . EOL;
\r
158 $help .= EOL . EOL;
\r
159 $tpl = get_markup_template('field_input.tpl');
\r
160 $help .= replace_macros($tpl, [
\r
161 '$field' => ['phpath', L10n::t('PHP executable path'), $phpath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')],
\r
166 self::addCheck($checks, L10n::t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
\r
169 $cmd = "$phpath -v";
\r
170 $result = trim(shell_exec($cmd));
\r
171 $passed2 = (strpos($result, "(cli)") !== false);
\r
172 list($result) = explode("\n", $result);
\r
175 $help .= L10n::t("PHP executable is not the php cli binary \x28could be cgi-fgci version\x29") . EOL;
\r
176 $help .= L10n::t('Found PHP version: ') . "<tt>$result</tt>";
\r
178 self::addCheck($checks, L10n::t('PHP cli binary'), $passed2, true, $help);
\r
182 $str = autoname(8);
\r
183 $cmd = "$phpath testargs.php $str";
\r
184 $result = trim(shell_exec($cmd));
\r
185 $passed3 = $result == $str;
\r
188 $help .= L10n::t('The command line version of PHP on your system does not have "register_argc_argv" enabled.') . EOL;
\r
189 $help .= L10n::t('This is required for message delivery to work.');
\r
191 self::addCheck($checks, L10n::t('PHP register_argc_argv'), $passed3, true, $help);
\r
198 * Checks the OpenSSL Environment
\r
200 * - Checks, if the command "openssl_pkey_new" is available
\r
202 * @param array $checks The list of all checks (by-ref parameter!)
\r
204 public static function checkKeys(&$checks)
\r
209 if (function_exists('openssl_pkey_new')) {
\r
210 $res = openssl_pkey_new([
\r
211 'digest_alg' => 'sha1',
\r
212 'private_key_bits' => 4096,
\r
213 'encrypt_key' => false
\r
219 $help .= L10n::t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys') . EOL;
\r
220 $help .= L10n::t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
\r
222 self::addCheck($checks, L10n::t('Generate encryption keys'), $res, true, $help);
\r
226 * PHP functions Check
\r
228 * Checks the following PHP functions
\r
238 * @param array $checks The list of all checks (by-ref parameter!)
\r
240 public static function checkFunctions(&$checks)
\r
243 self::addCheck($ck_funcs, L10n::t('libCurl PHP module'), true, true, "");
\r
244 self::addCheck($ck_funcs, L10n::t('GD graphics PHP module'), true, true, "");
\r
245 self::addCheck($ck_funcs, L10n::t('OpenSSL PHP module'), true, true, "");
\r
246 self::addCheck($ck_funcs, L10n::t('PDO or MySQLi PHP module'), true, true, "");
\r
247 self::addCheck($ck_funcs, L10n::t('mb_string PHP module'), true, true, "");
\r
248 self::addCheck($ck_funcs, L10n::t('XML PHP module'), true, true, "");
\r
249 self::addCheck($ck_funcs, L10n::t('iconv PHP module'), true, true, "");
\r
250 self::addCheck($ck_funcs, L10n::t('POSIX PHP module'), true, true, "");
\r
252 if (function_exists('apache_get_modules')) {
\r
253 if (! in_array('mod_rewrite',apache_get_modules())) {
\r
254 self::addCheck($ck_funcs, L10n::t('Apache mod_rewrite module'), false, true, L10n::t('Error: Apache webserver mod-rewrite module is required but not installed.'));
\r
256 self::addCheck($ck_funcs, L10n::t('Apache mod_rewrite module'), true, true, "");
\r
260 if (!function_exists('curl_init')) {
\r
261 $ck_funcs[0]['status'] = false;
\r
262 $ck_funcs[0]['help'] = L10n::t('Error: libCURL PHP module required but not installed.');
\r
264 if (!function_exists('imagecreatefromjpeg')) {
\r
265 $ck_funcs[1]['status'] = false;
\r
266 $ck_funcs[1]['help'] = L10n::t('Error: GD graphics PHP module with JPEG support required but not installed.');
\r
268 if (!function_exists('openssl_public_encrypt')) {
\r
269 $ck_funcs[2]['status'] = false;
\r
270 $ck_funcs[2]['help'] = L10n::t('Error: openssl PHP module required but not installed.');
\r
272 if (!function_exists('mysqli_connect') && !class_exists('pdo')) {
\r
273 $ck_funcs[3]['status'] = false;
\r
274 $ck_funcs[3]['help'] = L10n::t('Error: PDO or MySQLi PHP module required but not installed.');
\r
276 if (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', \PDO::getAvailableDrivers())) {
\r
277 $ck_funcs[3]['status'] = false;
\r
278 $ck_funcs[3]['help'] = L10n::t('Error: The MySQL driver for PDO is not installed.');
\r
280 if (!function_exists('mb_strlen')) {
\r
281 $ck_funcs[4]['status'] = false;
\r
282 $ck_funcs[4]['help'] = L10n::t('Error: mb_string PHP module required but not installed.');
\r
284 if (!function_exists('iconv_strlen')) {
\r
285 $ck_funcs[6]['status'] = false;
\r
286 $ck_funcs[6]['help'] = L10n::t('Error: iconv PHP module required but not installed.');
\r
288 if (!function_exists('posix_kill')) {
\r
289 $ck_funcs[7]['status'] = false;
\r
290 $ck_funcs[7]['help'] = L10n::t('Error: POSIX PHP module required but not installed.');
\r
293 $checks = array_merge($checks, $ck_funcs);
\r
295 // check for XML DOM Documents being able to be generated
\r
297 $xml = new DOMDocument();
\r
298 } catch (Exception $e) {
\r
299 $ck_funcs[5]['status'] = false;
\r
300 $ck_funcs[5]['help'] = L10n::t('Error, XML PHP module required but not installed.');
\r
305 * "config/local.ini.php" - Check
\r
307 * Checks if it's possible to create the "config/local.ini.php"
\r
309 * @param array $checks The list of all checks (by-ref parameter!)
\r
311 public static function checkHtConfig(&$checks)
\r
315 if ((file_exists('config/local.ini.php') && !is_writable('config/local.ini.php')) ||
\r
316 (!file_exists('config/local.ini.php') && !is_writable('.'))) {
\r
319 $help = L10n::t('The web installer needs to be able to create a file called "local.ini.php" in the "config" folder of your web server and it is unable to do so.') . EOL;
\r
320 $help .= L10n::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;
\r
321 $help .= L10n::t('At the end of this procedure, we will give you a text to save in a file named local.ini.php in your Friendica "config" folder.') . EOL;
\r
322 $help .= L10n::t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.') . EOL;
\r
325 self::addCheck($checks, L10n::t('config/local.ini.php is writable'), $status, false, $help);
\r
330 * Smarty3 Template Check
\r
332 * Checks, if the directory of Smarty3 is writable
\r
334 * @param array $checks The list of all checks (by-ref parameter!)
\r
336 public static function checkSmarty3(&$checks)
\r
340 if (!is_writable('view/smarty3')) {
\r
343 $help = L10n::t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') . EOL;
\r
344 $help .= L10n::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;
\r
345 $help .= L10n::t("Please ensure that the user that your web server runs as \x28e.g. www-data\x29 has write access to this folder.") . EOL;
\r
346 $help .= L10n::t("Note: as a security measure, you should give the web server write access to view/smarty3/ only--not the template files \x28.tpl\x29 that it contains.") . EOL;
\r
349 self::addCheck($checks, L10n::t('view/smarty3 is writable'), $status, true, $help);
\r
353 * ".htaccess" - Check
\r
355 * Checks, if "url_rewrite" is enabled in the ".htaccess" file
\r
357 * @param array $checks The list of all checks (by-ref parameter!)
\r
359 public static function checkHtAccess(&$checks)
\r
364 if (function_exists('curl_init')) {
\r
365 $test = Network::fetchUrlFull(System::baseUrl() . "/install/testrewrite");
\r
367 $url = normalise_link(System::baseUrl() . "/install/testrewrite");
\r
368 if ($test['body'] != "ok") {
\r
369 $test = Network::fetchUrlFull($url);
\r
372 if ($test['body'] != "ok") {
\r
374 $help = L10n::t('Url rewrite in .htaccess is not working. Check your server configuration.');
\r
376 $error_msg['head'] = L10n::t('Error message from Curl when fetching');
\r
377 $error_msg['url'] = $test['redirect_url'];
\r
378 $error_msg['msg'] = defaults($test, 'error', '');
\r
380 self::addCheck($checks, L10n::t('Url rewrite is working'), $status, true, $help, $error_msg);
\r
382 // cannot check modrewrite if libcurl is not installed
\r
383 /// @TODO Maybe issue warning here?
\r
390 * Checks, if the imagick module is available
\r
392 * @param array $checks The list of all checks (by-ref parameter!)
\r
394 public static function checkImagick(&$checks)
\r
399 if (class_exists('Imagick')) {
\r
401 $supported = Image::supportedTypes();
\r
402 if (array_key_exists('image/gif', $supported)) {
\r
406 if ($imagick == false) {
\r
407 self::addCheck($checks, L10n::t('ImageMagick PHP extension is not installed'), $imagick, false, "");
\r
409 self::addCheck($checks, L10n::t('ImageMagick PHP extension is installed'), $imagick, false, "");
\r
411 self::addCheck($checks, L10n::t('ImageMagick supports GIF'), $gif, false, "");
\r
417 * Installs the Database structure
\r
419 * @return string A possible error
\r
421 public static function installDatabaseStructure()
\r
423 $errors = DBStructure::update(false, true, true);
\r