From 98d90e131ded624c552102dd450a21e6a67aecf1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 25 Nov 2018 01:44:09 -0500 Subject: [PATCH] Update install to generate config/local.config.php --- .travis.yml | 2 +- INSTALL.txt | 29 +++--- bin/dev/vagrant_provision.sh | 3 +- src/App/Mode.php | 5 +- src/Core/Console/AutomaticInstallation.php | 18 ++-- src/Core/Installer.php | 22 ++--- tests/Util/VFSTrait.php | 6 +- tests/src/App/ModeTest.php | 6 +- .../AutomaticInstallationConsoleTest.php | 92 ++++++++++--------- tests/src/Core/InstallerTest.php | 6 +- util/local.config.vagrant.php | 41 +++++++++ view/templates/local.config.tpl | 35 +++++++ 12 files changed, 172 insertions(+), 93 deletions(-) create mode 100644 util/local.config.vagrant.php create mode 100644 view/templates/local.config.tpl diff --git a/.travis.yml b/.travis.yml index bb8b113112..f9f9acff19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ env: install: - composer install before_script: - - cp config/local-sample.ini.php config/local.ini.php + - cp config/local-sample.config.php config/local.config.php - mysql -e 'CREATE DATABASE IF NOT EXISTS test;' - mysql -utravis test < database.sql - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini diff --git a/INSTALL.txt b/INSTALL.txt index 2f0613fb7d..9d10e8aee6 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -114,7 +114,7 @@ password, database name). 4. If you know in advance that it will be impossible for the web server to write or create files in the config/ subfolder, create an empty file called -local.ini.php and make it writable by the web server. +local.config.php and make it writable by the web server. 5. Visit your website with a web browser and follow the instructions. Please note any error messages and correct these before continuing. @@ -128,9 +128,9 @@ so in the host name setting for the database. 6. *If* the automated installation fails for any reason, check the following: - - "config/local.ini.php" exists - If not, edit local-sample.ini.php and change system settings. Rename -to local.ini.php + - "config/local.config.php" exists + If not, edit local-sample.config.php and change system settings. Rename +to local.config.php - Database is populated. If not, import the contents of "database.sql" with phpmyadmin or mysql command line @@ -139,7 +139,7 @@ or mysql command line Registration errors should all be recoverable automatically. If you get any *critical* failure at this point, it generally indicates the database was not installed correctly. You might wish to move/rename -local.ini.php to another name and empty (called 'dropping') the database +local.config.php to another name and empty (called 'dropping') the database tables, so that you can start fresh. **************************************************************************** @@ -184,7 +184,7 @@ Bad things will happen. Let there be a hardware failure, a corrupted database or whatever you can think of. So once the installation of your Friendica node is done, you should make yoursef a backup plan. -The most important file is the `config/local.ini.php` file in the base directory. +The most important file is the `config/local.config.php` file in the base directory. As it stores all your data, you should also have a recent dump of your Friendica database at hand, should you have to recover your node. @@ -281,21 +281,21 @@ Windows). ##################################################################### -- If you are unable to write the file config/local.ini.php during installation +- If you are unable to write the file config/local.config.php during installation due to permissions issues: ##################################################################### create an empty file with that name and give it world-write permission. For Linux: -% touch config/local.ini.php -% chmod 664 config/local.ini.php +% touch config/local.config.php +% chmod 664 config/local.config.php Retry the installation. As soon as the database has been created, ******* this is important ********* -% chmod 644 config/local.ini.php +% chmod 644 config/local.config.php ##################################################################### - Some configurations with "suhosin" security are configured without @@ -334,11 +334,12 @@ After a while I noticed, that bin/worker.php calls further php script via proc_open. These scripts themselves also use proc_open and fail, because they are NOT called with -d suhosin.executor.func.blacklist=none. -So the simple solution is to put the correct parameters into config/local.ini.php: +So the simple solution is to put the correct parameters into config/local.config.php: -[config] -; Location of PHP command line processor -php_path = "/usr/bin/php -d suhosin.executor.func.blacklist=none -d suhosin.executor.eval.blacklist=none" + 'config' => [ + //Location of PHP command line processor + 'php_path' => '/usr/bin/php -d suhosin.executor.func.blacklist=none -d suhosin.executor.eval.blacklist=none', + ], This is obvious as soon as you notice that the friendica-cron uses proc_open to execute php-scripts that also use proc_open, but it took me quite some time to diff --git a/bin/dev/vagrant_provision.sh b/bin/dev/vagrant_provision.sh index ac093e7897..440a7b590c 100755 --- a/bin/dev/vagrant_provision.sh +++ b/bin/dev/vagrant_provision.sh @@ -86,8 +86,7 @@ cd /var/www php bin/composer.phar install # initial config file for friendica in vagrant -#cp /vagrant/util/htconfig.vagrant.php /vagrant/.htconfig.php -cp /vagrant/util/local.ini.vagrant.php /vagrant/config/local.ini.php +cp /vagrant/util/local.config.vagrant.php /vagrant/config/local.config.php # copy the .htaccess-dist file to .htaccess so that rewrite rules work cp /vagrant/.htaccess-dist /vagrant/.htaccess diff --git a/src/App/Mode.php b/src/App/Mode.php index d9f5cdbd4c..fdfb2ce6e0 100644 --- a/src/App/Mode.php +++ b/src/App/Mode.php @@ -52,8 +52,9 @@ class Mode $this->mode = 0; - if (!file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php') - && !file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) { + if (!file_exists($this->basepath . '/config/local.config.php') + && !file_exists($this->basepath . '/config/local.ini.php') + && !file_exists($this->basepath . '/.htconfig.php')) { return; } diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 294009ada0..150b7e52a7 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -23,7 +23,7 @@ Synopsis bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f] Description - Installs Friendica with data based on the local.ini.php file or environment variables + Installs Friendica with data based on the local.config.php file or environment variables Notes Not checking .htaccess/URL-Rewrite during CLI installation. @@ -32,7 +32,7 @@ Options -h|--help|-? Show help information -v Show more debug information. -a All setup checks are required (except .htaccess) - -f|--file prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables) + -f|--file prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables) -s|--savedb Save the DB credentials to the file (if environment variables is used) -H|--dbhost The host of the mysql/mariadb database (env MYSQL_HOST) -p|--dbport The port of the mysql/mariadb database (env MYSQL_PORT) @@ -58,11 +58,11 @@ Environment variables FRIENDICA_LANG The langauge of Friendica Examples - bin/console autoinstall -f 'input.ini.php - Installs Friendica with the prepared 'input.ini.php' file + bin/console autoinstall -f 'input.config.php + Installs Friendica with the prepared 'input.config.php' file bin/console autoinstall --savedb - Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file + Installs Friendica with environment variables and saves them to the 'config/local.config.php' file bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica Installs Friendica with a local mysql database with credentials @@ -96,11 +96,11 @@ HELP; $config_file = $this->getOption(['f', 'file']); if (!empty($config_file)) { - if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.ini.php') { + if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.config.php') { // Copy config file $this->out("Copying config file...\n"); - if (!copy($a->getBasePath() . DIRECTORY_SEPARATOR . $config_file, $a->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) { - throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $a->getBasePath() . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.ini.php' manually.\n"); + if (!copy($a->getBasePath() . DIRECTORY_SEPARATOR . $config_file, $a->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) { + throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $a->getBasePath() . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n"); } } @@ -175,7 +175,7 @@ HELP; Theme::install(Config::get('system', 'theme')); $this->out(" Complete\n\n"); } else { - $this->out(" Theme setting is empty. Please check the file 'config/local.ini.php'\n\n"); + $this->out(" Theme setting is empty. Please check the file 'config/local.config.php'\n\n"); } $this->out("\nInstallation is finished\n"); diff --git a/src/Core/Installer.php b/src/Core/Installer.php index f7190b2f89..b84bcd916e 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -123,7 +123,7 @@ class Installer /** * Executes the installation of Friendica in the given environment. - * - Creates `config/local.ini.php` + * - Creates `config/local.config.php` * - Installs Database Structure * * @param string $phppath Path to the PHP-Binary (optional, if not set e.g. 'php' or '/usr/bin/php') @@ -141,7 +141,7 @@ class Installer */ public function createConfig($phppath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $basepath) { - $tpl = Renderer::getMarkupTemplate('local.ini.tpl'); + $tpl = Renderer::getMarkupTemplate('local.config.tpl'); $txt = Renderer::replaceMacros($tpl, [ '$phpath' => $phppath, '$dbhost' => $dbhost, @@ -154,10 +154,10 @@ class Installer '$adminmail' => $adminmail, ]); - $result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php', $txt); + $result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php', $txt); if (!$result) { - $this->addCheck(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.'), false, false, htmlentities($txt, ENT_COMPAT, 'UTF-8')); + $this->addCheck(L10n::t('The database configuration file "config/local.config.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.'), false, false, htmlentities($txt, ENT_COMPAT, 'UTF-8')); } return $result; @@ -444,9 +444,9 @@ class Installer } /** - * "config/local.ini.php" - Check + * "config/local.config.php" - Check * - * Checks if it's possible to create the "config/local.ini.php" + * Checks if it's possible to create the "config/local.config.php" * * @return bool false if something required failed */ @@ -454,17 +454,17 @@ class Installer { $status = true; $help = ""; - if ((file_exists('config/local.ini.php') && !is_writable('config/local.ini.php')) || - (!file_exists('config/local.ini.php') && !is_writable('.'))) { + if ((file_exists('config/local.config.php') && !is_writable('config/local.config.php')) || + (!file_exists('config/local.config.php') && !is_writable('.'))) { $status = false; - $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('The web installer needs to be able to create a file called "local.config.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('At the end of this procedure, we will give you a text to save in a file named local.config.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; } - $this->addCheck(L10n::t('config/local.ini.php is writable'), $status, false, $help); + $this->addCheck(L10n::t('config/local.config.php is writable'), $status, false, $help); // Local INI File is not required return true; diff --git a/tests/Util/VFSTrait.php b/tests/Util/VFSTrait.php index 1edc25d424..50999b984d 100644 --- a/tests/Util/VFSTrait.php +++ b/tests/Util/VFSTrait.php @@ -27,9 +27,9 @@ trait VFSTrait // create a virtual directory and copy all needed files and folders to it $this->root = vfsStream::setup('friendica', null, $structure); - $this->setConfigFile('config.ini.php'); - $this->setConfigFile('settings.ini.php'); - $this->setConfigFile('local.ini.php'); + $this->setConfigFile('defaults.config.php'); + $this->setConfigFile('settings.config.php'); + $this->setConfigFile('local.config.php'); $this->setConfigFile('dbstructure.config.php'); } diff --git a/tests/src/App/ModeTest.php b/tests/src/App/ModeTest.php index cab953bdaf..d534e24ede 100644 --- a/tests/src/App/ModeTest.php +++ b/tests/src/App/ModeTest.php @@ -36,11 +36,11 @@ class ModeTest extends MockedTest { $mode = new Mode($this->root->url()); - $this->assertTrue($this->root->hasChild('config/local.ini.php')); + $this->assertTrue($this->root->hasChild('config/local.config.php')); - $this->delConfigFile('local.ini.php'); + $this->delConfigFile('local.config.php'); - $this->assertFalse($this->root->hasChild('config/local.ini.php')); + $this->assertFalse($this->root->hasChild('config/local.config.php')); $mode->determine(); diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index 957517f035..b70447a547 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -41,9 +41,9 @@ class AutomaticInstallationConsoleTest extends ConsoleTest { parent::setUp(); - if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')) { + if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')) { $this->root->getChild('config') - ->removeChild('local.ini.php'); + ->removeChild('local.config.php'); } $this->db_host = getenv('MYSQL_HOST'); @@ -58,7 +58,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest } /** - * Creates the arguments which is asserted to be passed to 'replaceMacros()' for creating the local.ini.php + * Creates the arguments which is asserted to be passed to 'replaceMacros()' for creating the local.config.php * * @param bool $withDb if true, DB will get saved too * @@ -184,51 +184,53 @@ FIN; $this->mockUpdate([false, true, true], null, 1); $config = << [ + 'hostname' => '', + 'username' => '', + 'password' => '', + 'database' => '', + 'charset' => 'utf8mb4', + ], + + // **************************************************************** + // The configuration below will be overruled by the admin panel. + // Changes made below will only have an effect if the database does + // not contain any configuration for the friendica system. + // **************************************************************** + + 'config' => [ + 'admin_email' => '', + 'sitename' => 'Friendica Social Network', + 'register_policy' => 'REGISTER_OPEN', + 'register_text' => '', + ], + 'system' => [ + 'default_timezone' => 'UTC', + 'language' => 'en', + ], +]; CONF; - vfsStream::newFile('prepared.ini.php') + vfsStream::newFile('prepared.config.php') ->at($this->root) ->setContent($config); $console = new AutomaticInstallation($this->consoleArgv); - $console->setOption('f', 'prepared.ini.php'); + $console->setOption('f', 'prepared.config.php'); $txt = $this->dumpExecute($console); $this->assertFinished($txt, false, true); - $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); + $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')); } /** @@ -241,7 +243,7 @@ CONF; $this->mockExistsTable('user', false, 1); $this->mockUpdate([false, true, true], null, 1); - $this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1); + $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(true), '', 1); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local')); @@ -267,7 +269,7 @@ CONF; $this->mockExistsTable('user', false, 1); $this->mockUpdate([false, true, true], null, 1); - $this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1); + $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(false), '', 1); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local')); @@ -292,7 +294,7 @@ CONF; $this->mockExistsTable('user', false, 1); $this->mockUpdate([false, true, true], null, 1); - $this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1); + $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(true), '', 1); $console = new AutomaticInstallation($this->consoleArgv); @@ -326,7 +328,7 @@ CONF; { $this->mockConnect(false, 1); - $this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1); + $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(false), '', 1); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local')); @@ -350,7 +352,7 @@ Synopsis bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f] Description - Installs Friendica with data based on the local.ini.php file or environment variables + Installs Friendica with data based on the local.config.php file or environment variables Notes Not checking .htaccess/URL-Rewrite during CLI installation. @@ -359,7 +361,7 @@ Options -h|--help|-? Show help information -v Show more debug information. -a All setup checks are required (except .htaccess) - -f|--file prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables) + -f|--file prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables) -s|--savedb Save the DB credentials to the file (if environment variables is used) -H|--dbhost The host of the mysql/mariadb database (env MYSQL_HOST) -p|--dbport The port of the mysql/mariadb database (env MYSQL_PORT) @@ -385,11 +387,11 @@ Environment variables FRIENDICA_LANG The langauge of Friendica Examples - bin/console autoinstall -f 'input.ini.php - Installs Friendica with the prepared 'input.ini.php' file + bin/console autoinstall -f 'input.config.php + Installs Friendica with the prepared 'input.config.php' file bin/console autoinstall --savedb - Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file + Installs Friendica with environment variables and saves them to the 'config/local.config.php' file bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica Installs Friendica with a local mysql database with credentials diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index ebbf5037d4..32a80a77e0 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -195,14 +195,14 @@ class InstallerTest extends MockedTest */ public function testCheckLocalIni() { - $this->assertTrue($this->root->hasChild('config/local.ini.php')); + $this->assertTrue($this->root->hasChild('config/local.config.php')); $install = new Installer(); $this->assertTrue($install->checkLocalIni()); - $this->delConfigFile('local.ini.php'); + $this->delConfigFile('local.config.php'); - $this->assertFalse($this->root->hasChild('config/local.ini.php')); + $this->assertFalse($this->root->hasChild('config/local.config.php')); $install = new Installer(); $this->assertTrue($install->checkLocalIni()); diff --git a/util/local.config.vagrant.php b/util/local.config.vagrant.php new file mode 100644 index 0000000000..fcac663c4d --- /dev/null +++ b/util/local.config.vagrant.php @@ -0,0 +1,41 @@ + [ + 'hostname' => 'localhost', + 'username' => 'mysqlusername', + 'password' => 'mysqlpassword', + 'database' => 'mysqldatabasename', + 'charset' => 'utf8mb4', + ], + + // **************************************************************** + // The configuration below will be overruled by the admin panel. + // Changes made below will only have an effect if the database does + // not contain any configuration for the friendica system. + // **************************************************************** + + 'config' => [ + 'admin_email' => 'admin@friendica.local', + 'sitename' => 'Friendica Social Network', + 'register_policy' => 'REGISTER_OPEN', + 'register_text' => '', + ], + 'system' => [ + 'default_timezone' => 'UTC', + 'language' => 'en', + ], +]; diff --git a/view/templates/local.config.tpl b/view/templates/local.config.tpl new file mode 100644 index 0000000000..5839e8c343 --- /dev/null +++ b/view/templates/local.config.tpl @@ -0,0 +1,35 @@ + [ + 'hostname' => '{{$dbhost}}', + 'username' => '{{$dbuser}}', + 'password' => '{{$dbpass}}', + 'database' => '{{$dbdata}}', + 'charset' => 'utf8mb4', + ], + + // **************************************************************** + // The configuration below will be overruled by the admin panel. + // Changes made below will only have an effect if the database does + // not contain any configuration for the friendica system. + // **************************************************************** + + 'config' => [ + 'php_path' => '{{$phpath}}', + 'admin_email' => '{{$adminmail}}', + 'sitename' => 'Friendica Social Network', + 'register_policy' => 'REGISTER_OPEN', + 'max_import_size' => 200000, + ], + 'system' => [ + 'urlpath' => '{{$urlpath}}', + 'default_timezone' => '{{$timezone}}', + 'language' => '{{$language}}', + ], +]; -- 2.39.5