X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FInstall.php;h=ec33ef9634d77c0440dc74a4aac4b7111f263435;hb=8789aedf6b9c68ba6d71d3dd2e285aed3e052ac4;hp=791377fc8e66c0683c7e7c48b50dfb83303d7fcf;hpb=346697d771e2656b4bcd12a5e84045710e9b2b55;p=friendica.git diff --git a/src/Core/Install.php b/src/Core/Install.php index 791377fc8e..ec33ef9634 100644 --- a/src/Core/Install.php +++ b/src/Core/Install.php @@ -5,6 +5,7 @@ namespace Friendica\Core; use Friendica\BaseObject; +use Friendica\App; use Friendica\Database\DBStructure; use Friendica\Object\Image; use Friendica\Util\Network; @@ -13,19 +14,35 @@ use Exception; use DOMDocument; /** - * @brief Contains the class with install relevant stuff * + * Contains methods for installation purpose of Friendica */ class Install extends BaseObject { - public static function check($phpath) + /** + * Sets the install-mode for further methods + */ + public static function setInstallMode() + { + self::getApp()->mode = App::MODE_INSTALL; + } + + /** + * Checks the current installation environment. There are optional and mandatory checks. + * + * @param string $phpath Optional path to the PHP binary (Default is 'php') + * + * @return array First element is a list of all checks and their results, + * the second element is a list of passed checks + */ + public static function check($phpath = 'php') { $checks = []; self::checkFunctions($checks); - self::checkImagik($checks); + self::checkImagick($checks); - self::checkHtConfig($checks); + self::checkLocalIni($checks); self::checkSmarty3($checks); @@ -37,7 +54,7 @@ class Install extends BaseObject $checkspassed = array_reduce($checks, function ($v, $c) { - if ($c['require']) { + if (!empty($c['require'])) { $v = $v && $c['status']; } return $v; @@ -47,9 +64,25 @@ class Install extends BaseObject return array($checks, $checkspassed); } - public static function install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail, $rino = 1) + /** + * Executes the installation of Friendica in the given environment. + * - Creates `config/local.ini.php` + * - Installs Database Structure + * + * @param string $urlpath Path based on the URL of Friendica (e.g. '/friendica') + * @param string $dbhost Hostname/IP of the Friendica Database + * @param string $dbuser Username of the Database connection credentials + * @param string $dbpass Password of the Database connection credentials + * @param string $dbdata Name of the Database + * @param string $phpath Path to the PHP-Binary (e.g. 'php' or '/usr/bin/php') + * @param string $timezone Timezone of the Friendica Installaton (e.g. 'Europe/Berlin') + * @param string $language 2-letter ISO 639-1 code (eg. 'en') + * @param string $adminmail Mail-Adress of the administrator + * @param int $rino Rino-enabled (1 = true, 0 = false) + */ + public static function install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail) { - $tpl = get_markup_template('htconfig.tpl'); + $tpl = get_markup_template('local.ini.tpl'); $txt = replace_macros($tpl,[ '$dbhost' => $dbhost, '$dbuser' => $dbuser, @@ -60,16 +93,14 @@ class Install extends BaseObject '$urlpath' => $urlpath, '$phpath' => $phpath, '$adminmail' => $adminmail, - '$rino' => $rino ]); - - $result = file_put_contents('config/.htconfig.php', $txt); + $result = file_put_contents('config/local.ini.php', $txt); if (! $result) { self::getApp()->data['txt'] = $txt; } - $errors = self::loadDatabase(); + $errors = self::installDatabaseStructure(); if ($errors) { self::getApp()->data['db_failed'] = $errors; @@ -79,22 +110,40 @@ class Install extends BaseObject } /** - * checks : array passed to template - * title : string - * status : boolean - * required : boolean - * help : string optional + * Adds new checks to the array $checks + * + * @param array $checks The list of all checks (by-ref parameter!) + * @param string $title The title of the current check + * @param bool $status 1 = check passed, 0 = check not passed + * @param bool $required 1 = check is mandatory, 0 = check is optional + * @param string $help A help-string for the current check + * @param string $error_msg Optional. A error message, if the current check failed */ - private static function addCheck(&$checks, $title, $status, $required, $help) { + private static function addCheck(&$checks, $title, $status, $required, $help, $error_msg = "") + { $checks[] = [ 'title' => $title, 'status' => $status, 'required' => $required, - 'help' => $help, + 'help' => $help, + 'error_msg' => $error_msg, ]; } - private static function checkPHP(&$phpath, &$checks) { + /** + * PHP Check + * + * Checks the PHP environment. + * + * - Checks if a PHP binary is available + * - Checks if it is the CLI version + * - Checks if "register_argc_argv" is enabled + * + * @param string $phpath Optional. The Path to the PHP-Binary + * @param array $checks The list of all checks (by-ref parameter!) + */ + public static function checkPHP(&$phpath, &$checks) + { $passed = $passed2 = $passed3 = false; if (strlen($phpath)) { $passed = file_exists($phpath); @@ -104,7 +153,7 @@ class Install extends BaseObject } $help = ""; if (!$passed) { - $help .= L10n::t('Could not find a command line version of PHP in the web server PATH.'). EOL; + $help .= L10n::t('Could not find a command line version of PHP in the web server PATH.') . EOL; $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 'Setup the worker'") . EOL; $help .= EOL . EOL; $tpl = get_markup_template('field_input.tpl'); @@ -119,17 +168,16 @@ class Install extends BaseObject if ($passed) { $cmd = "$phpath -v"; $result = trim(shell_exec($cmd)); - $passed2 = ( strpos($result, "(cli)") !== false); + $passed2 = (strpos($result, "(cli)") !== false); list($result) = explode("\n", $result); $help = ""; if (!$passed2) { - $help .= L10n::t("PHP executable is not the php cli binary \x28could be cgi-fgci version\x29"). EOL; - $help .= L10n::t('Found PHP version: ')."$result"; + $help .= L10n::t("PHP executable is not the php cli binary \x28could be cgi-fgci version\x29") . EOL; + $help .= L10n::t('Found PHP version: ') . "$result"; } self::addCheck($checks, L10n::t('PHP cli binary'), $passed2, true, $help); } - if ($passed2) { $str = autoname(8); $cmd = "$phpath testargs.php $str"; @@ -137,41 +185,60 @@ class Install extends BaseObject $passed3 = $result == $str; $help = ""; if (!$passed3) { - $help .= L10n::t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL; + $help .= L10n::t('The command line version of PHP on your system does not have "register_argc_argv" enabled.') . EOL; $help .= L10n::t('This is required for message delivery to work.'); } self::addCheck($checks, L10n::t('PHP register_argc_argv'), $passed3, true, $help); } - - } - private static function checkKeys(&$checks) { - + /** + * OpenSSL Check + * + * Checks the OpenSSL Environment + * + * - Checks, if the command "openssl_pkey_new" is available + * + * @param array $checks The list of all checks (by-ref parameter!) + */ + public static function checkKeys(&$checks) + { $help = ''; - $res = false; if (function_exists('openssl_pkey_new')) { $res = openssl_pkey_new([ - 'digest_alg' => 'sha1', + 'digest_alg' => 'sha1', 'private_key_bits' => 4096, - 'encrypt_key' => false + 'encrypt_key' => false ]); } // Get private key - - if (! $res) { - $help .= L10n::t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL; + if (!$res) { + $help .= L10n::t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys') . EOL; $help .= L10n::t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".'); } self::addCheck($checks, L10n::t('Generate encryption keys'), $res, true, $help); - } - - private static function checkFunctions(&$checks) { + /** + * PHP functions Check + * + * Checks the following PHP functions + * - libCurl + * - GD Graphics + * - OpenSSL + * - PDO or MySQLi + * - mb_string + * - XML + * - iconv + * - POSIX + * + * @param array $checks The list of all checks (by-ref parameter!) + */ + public static function checkFunctions(&$checks) + { $ck_funcs = []; self::addCheck($ck_funcs, L10n::t('libCurl PHP module'), true, true, ""); self::addCheck($ck_funcs, L10n::t('GD graphics PHP module'), true, true, ""); @@ -190,35 +257,35 @@ class Install extends BaseObject } } - if (! function_exists('curl_init')) { + if (!function_exists('curl_init')) { $ck_funcs[0]['status'] = false; $ck_funcs[0]['help'] = L10n::t('Error: libCURL PHP module required but not installed.'); } - if (! function_exists('imagecreatefromjpeg')) { + if (!function_exists('imagecreatefromjpeg')) { $ck_funcs[1]['status'] = false; $ck_funcs[1]['help'] = L10n::t('Error: GD graphics PHP module with JPEG support required but not installed.'); } - if (! function_exists('openssl_public_encrypt')) { + if (!function_exists('openssl_public_encrypt')) { $ck_funcs[2]['status'] = false; $ck_funcs[2]['help'] = L10n::t('Error: openssl PHP module required but not installed.'); } - if (! function_exists('mysqli_connect') && !class_exists('pdo')) { + if (!function_exists('mysqli_connect') && !class_exists('pdo')) { $ck_funcs[3]['status'] = false; $ck_funcs[3]['help'] = L10n::t('Error: PDO or MySQLi PHP module required but not installed.'); } - if (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', PDO::getAvailableDrivers())) { + if (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', \PDO::getAvailableDrivers())) { $ck_funcs[3]['status'] = false; $ck_funcs[3]['help'] = L10n::t('Error: The MySQL driver for PDO is not installed.'); } - if (! function_exists('mb_strlen')) { + if (!function_exists('mb_strlen')) { $ck_funcs[4]['status'] = false; $ck_funcs[4]['help'] = L10n::t('Error: mb_string PHP module required but not installed.'); } - if (! function_exists('iconv_strlen')) { + if (!function_exists('iconv_strlen')) { $ck_funcs[6]['status'] = false; $ck_funcs[6]['help'] = L10n::t('Error: iconv PHP module required but not installed.'); } - if (! function_exists('posix_kill')) { + if (!function_exists('posix_kill')) { $ck_funcs[7]['status'] = false; $ck_funcs[7]['help'] = L10n::t('Error: POSIX PHP module required but not installed.'); } @@ -234,62 +301,98 @@ class Install extends BaseObject } } - - private static function checkHtConfig(&$checks) { + /** + * "config/local.ini.php" - Check + * + * Checks if it's possible to create the "config/local.ini.php" + * + * @param array $checks The list of all checks (by-ref parameter!) + */ + public static function checkLocalIni(&$checks) + { $status = true; $help = ""; - if ((file_exists('config/.htconfig.php') && !is_writable('.htconfig.php')) || - (!file_exists('config/.htconfig.php') && !is_writable('.'))) { + if ((file_exists('config/local.ini.php') && !is_writable('config/local.ini.php')) || + (!file_exists('config/local.ini.php') && !is_writable('.'))) { $status = false; - $help = L10n::t('The web installer needs to be able to create a file called ".htconfig.php" in the "config/" folder of your web server and it is unable to do so.') .EOL; - $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; - $help .= L10n::t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Friendica "config/" folder.').EOL; - $help .= L10n::t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL; + $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; + $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; + $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; + $help .= L10n::t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.') . EOL; } - self::addCheck($checks, L10n::t('config/.htconfig.php is writable'), $status, false, $help); + self::addCheck($checks, L10n::t('config/local.ini.php is writable'), $status, false, $help); } - private static function checkSmarty3(&$checks) { + /** + * Smarty3 Template Check + * + * Checks, if the directory of Smarty3 is writable + * + * @param array $checks The list of all checks (by-ref parameter!) + */ + public static function checkSmarty3(&$checks) + { $status = true; $help = ""; if (!is_writable('view/smarty3')) { $status = false; - $help = L10n::t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL; - $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; - $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; - $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; + $help = L10n::t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') . EOL; + $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; + $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; + $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; } self::addCheck($checks, L10n::t('view/smarty3 is writable'), $status, true, $help); - } - private static function checkHtAccess(&$checks) { + /** + * ".htaccess" - Check + * + * Checks, if "url_rewrite" is enabled in the ".htaccess" file + * + * @param array $checks The list of all checks (by-ref parameter!) + */ + public static function checkHtAccess(&$checks) + { $status = true; $help = ""; + $error_msg = ""; if (function_exists('curl_init')) { - $test = Network::fetchUrl(System::baseUrl()."/install/testrewrite"); + $test = Network::fetchUrlFull(System::baseUrl() . "/install/testrewrite"); - if ($test != "ok") { - $test = Network::fetchUrl(normalise_link(System::baseUrl()."/install/testrewrite")); + $url = normalise_link(System::baseUrl() . "/install/testrewrite"); + if ($test['body'] != "ok") { + $test = Network::fetchUrlFull($url); } - if ($test != "ok") { + if ($test['body'] != "ok") { $status = false; $help = L10n::t('Url rewrite in .htaccess is not working. Check your server configuration.'); + $error_msg = []; + $error_msg['head'] = L10n::t('Error message from Curl when fetching'); + $error_msg['url'] = $test['redirect_url']; + $error_msg['msg'] = defaults($test, 'error', ''); } - self::addCheck($checks, L10n::t('Url rewrite is working'), $status, true, $help); + self::addCheck($checks, L10n::t('Url rewrite is working'), $status, true, $help, $error_msg); } else { // cannot check modrewrite if libcurl is not installed /// @TODO Maybe issue warning here? } } - private static function checkImagik(&$checks) { + /** + * Imagick Check + * + * Checks, if the imagick module is available + * + * @param array $checks The list of all checks (by-ref parameter!) + */ + public static function checkImagick(&$checks) + { $imagick = false; $gif = false; @@ -310,9 +413,15 @@ class Install extends BaseObject } } - private static function loadDatabase() { + /** + * Installs the Database structure + * + * @return string A possible error + */ + public static function installDatabaseStructure() + { $errors = DBStructure::update(false, true, true); return $errors; } -} \ No newline at end of file +}