3 <title
>Tiny Tiny RSS
- Installer
</title
>
4 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
5 <link rel
="stylesheet" type
="text/css" href
="../css/default.css">
6 <style type
="text/css">
7 textarea
{ font
-size
: 12px
; }
10 <body
class="claro ttrss_utility">
14 // could be needed because of existing config.php
15 function define_default($param, $value) {
19 function make_password($length = 8) {
22 $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
26 while ($i < $length) {
27 $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
29 if (!strstr($password, $char)) {
38 function sanity_check($db_type) {
41 if (version_compare(PHP_VERSION
, '5.6.0', '<')) {
42 array_push($errors, "PHP version 5.6.0 or newer required. You're using " . PHP_VERSION
. ".");
45 if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
46 array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL.");
49 if (!function_exists("json_encode")) {
50 array_push($errors, "PHP support for JSON is required, but was not found.");
53 if (!class_exists("PDO")) {
54 array_push($errors, "PHP support for PDO is required but was not found.");
57 if (!function_exists("mb_strlen")) {
58 array_push($errors, "PHP support for mbstring functions is required but was not found.");
61 if (!function_exists("hash")) {
62 array_push($errors, "PHP support for hash() function is required but was not found.");
65 if (!function_exists("iconv")) {
66 array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
69 if (ini_get("safe_mode")) {
70 array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss.");
73 if (!class_exists("DOMDocument")) {
74 array_push($errors, "PHP support for DOMDocument is required, but was not found.");
80 function print_error($msg) {
81 print "<div class='alert alert-error'>$msg</div>";
84 function print_notice($msg) {
85 print "<div class=\"alert alert-info\">$msg</div>";
88 function pdo_connect($host, $user, $pass, $db, $type, $port = false) {
90 $db_port = $port ?
';port=' . $port : '';
91 $db_host = $host ?
';host=' . $host : '';
94 $pdo = new PDO($type . ':dbname=' . $db . $db_host . $db_port,
99 } catch (Exception
$e) {
100 print "<div class='alert alert-danger'>" . $e->getMessage() . "</div>";
105 function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
106 $DB_PORT, $SELF_URL_PATH) {
108 $data = explode("\n", file_get_contents("../config.php-dist"));
114 foreach ($data as $line) {
115 if (preg_match("/define\('DB_TYPE'/", $line)) {
116 $rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n";
117 } else if (preg_match("/define\('DB_HOST'/", $line)) {
118 $rv .= "\tdefine('DB_HOST', '$DB_HOST');\n";
119 } else if (preg_match("/define\('DB_USER'/", $line)) {
120 $rv .= "\tdefine('DB_USER', '$DB_USER');\n";
121 } else if (preg_match("/define\('DB_NAME'/", $line)) {
122 $rv .= "\tdefine('DB_NAME', '$DB_NAME');\n";
123 } else if (preg_match("/define\('DB_PASS'/", $line)) {
124 $rv .= "\tdefine('DB_PASS', '$DB_PASS');\n";
125 } else if (preg_match("/define\('DB_PORT'/", $line)) {
126 $rv .= "\tdefine('DB_PORT', '$DB_PORT');\n";
127 } else if (preg_match("/define\('SELF_URL_PATH'/", $line)) {
128 $rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n";
129 } else if (!$finished) {
133 if (preg_match("/\?\>/", $line)) {
141 function is_server_https() {
142 return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) ||
(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https');
145 function make_self_url_path() {
146 $url_path = (is_server_https() ?
'https://' : 'http://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH
);
153 <div
class="floatingLogo"><img src
="../images/logo_small.png"></div
>
155 <h1
>Tiny Tiny RSS Installer
</h1
>
157 <div
class='content'>
161 if (file_exists("../config.php")) {
162 require "../config.php";
164 if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) {
165 print_error("Error: config.php already exists in tt-rss directory; aborting.");
170 @$op = $_REQUEST['op'];
172 @$DB_HOST = strip_tags($_POST['DB_HOST']);
173 @$DB_TYPE = strip_tags($_POST['DB_TYPE']);
174 @$DB_USER = strip_tags($_POST['DB_USER']);
175 @$DB_NAME = strip_tags($_POST['DB_NAME']);
176 @$DB_PASS = strip_tags($_POST['DB_PASS']);
177 @$DB_PORT = strip_tags($_POST['DB_PORT']);
178 @$SELF_URL_PATH = strip_tags($_POST['SELF_URL_PATH']);
180 if (!$SELF_URL_PATH) {
181 $SELF_URL_PATH = preg_replace("/\/install\/$/", "/", make_self_url_path());
185 <form action
="" method
="post">
186 <input type
="hidden" name
="op" value
="testconfig">
188 <h2
>Database settings
</h2
>
191 $issel_pgsql = $DB_TYPE == "pgsql" ?
"selected" : "";
192 $issel_mysql = $DB_TYPE == "mysql" ?
"selected" : "";
196 <label
>Database type
</label
>
197 <select name
="DB_TYPE">
198 <option
<?php
echo $issel_pgsql ?
> value
="pgsql">PostgreSQL
</option
>
199 <option
<?php
echo $issel_mysql ?
> value
="mysql">MySQL
</option
>
204 <label
>Username
</label
>
205 <input
class="input input-text" required name
="DB_USER" size
="20" value
="<?php echo $DB_USER ?>"/>
209 <label
>Password
</label
>
210 <input
class="input input-text" name
="DB_PASS" size
="20" type
="password" value
="<?php echo $DB_PASS ?>"/>
214 <label
>Database name
</label
>
215 <input
class="input input-text" required name
="DB_NAME" size
="20" value
="<?php echo $DB_NAME ?>"/>
219 <label
>Host name
</label
>
220 <input
class="input input-text" name
="DB_HOST" size
="20" value
="<?php echo $DB_HOST ?>"/>
221 <span
class="hint">If needed
</span
>
226 <input
class="input input-text" name
="DB_PORT" type
="number" size
="20" value
="<?php echo $DB_PORT ?>"/>
227 <span
class="hint">Usually
3306 for MySQL
or 5432 for PostgreSQL
</span
>
230 <h2
>Other settings
</h2
>
232 <p
>This should be set to the location your Tiny Tiny RSS will be available on
.</p
>
235 <label
>Tiny Tiny RSS URL
</label
>
236 <input
class="input input-text" type
="url" name
="SELF_URL_PATH" placeholder
="<?php echo $SELF_URL_PATH; ?>" size
="60" value
="<?php echo $SELF_URL_PATH ?>"/>
240 <p
><input type
="submit" value
="Test configuration"></p
>
244 <?php
if ($op == 'testconfig') { ?
>
246 <h2
>Checking configuration
</h2
>
249 $errors = sanity_check($DB_TYPE);
251 if (count($errors) > 0) {
252 print "<p>Some configuration tests failed. Please correct them before continuing.</p>";
256 foreach ($errors as $error) {
257 print "<li style='color : red'>$error</li>";
267 if (!function_exists("curl_init")) {
268 array_push($notices, "It is highly recommended to enable support for CURL in PHP.");
271 if (function_exists("curl_init") && ini_get("open_basedir")) {
272 array_push($notices, "CURL and open_basedir combination breaks support for HTTP redirects. See the FAQ for more information.");
275 if (!function_exists("idn_to_ascii")) {
276 array_push($notices, "PHP support for Internationalization Functions is required to handle Internationalized Domain Names.");
279 if ($DB_TYPE == "mysql" && !function_exists("mysqli_connect")) {
280 array_push($notices, "PHP extension for MySQL (mysqli) is missing. This may prevent legacy plugins from working.");
283 if ($DB_TYPE == "pgsql" && !function_exists("pg_connect")) {
284 array_push($notices, "PHP extension for PostgreSQL is missing. This may prevent legacy plugins from working.");
287 if (count($notices) > 0) {
288 print_notice("Configuration check succeeded with minor problems:");
292 foreach ($notices as $notice) {
293 print "<li>$notice</li>";
298 print_notice("Configuration check succeeded.");
303 <h2
>Checking database
</h2
>
306 $pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
309 print_error("Unable to connect to database using specified parameters.");
313 print_notice("Database test succeeded."); ?
>
315 <h2
>Initialize database
</h2
>
317 <p
>Before you can start using tt
-rss
, database needs to be initialized
. Click on the button below to
do that now
.</p
>
320 $res = $pdo->query("SELECT true FROM ttrss_feeds");
322 if ($res && $res->fetch()) {
323 print_error("Some tt-rss data already exists in this database. If you continue with database initialization your current data will be lost.");
324 $need_confirm = true;
326 $need_confirm = false;
332 <input type
="hidden" name
="op" value
="installschema">
334 <input type
="hidden" name
="DB_USER" value
="<?php echo $DB_USER ?>"/>
335 <input type
="hidden" name
="DB_PASS" value
="<?php echo $DB_PASS ?>"/>
336 <input type
="hidden" name
="DB_NAME" value
="<?php echo $DB_NAME ?>"/>
337 <input type
="hidden" name
="DB_HOST" value
="<?php echo $DB_HOST ?>"/>
338 <input type
="hidden" name
="DB_PORT" value
="<?php echo $DB_PORT ?>"/>
339 <input type
="hidden" name
="DB_TYPE" value
="<?php echo $DB_TYPE ?>"/>
340 <input type
="hidden" name
="SELF_URL_PATH" value
="<?php echo $SELF_URL_PATH ?>"/>
342 <?php
if ($need_confirm) { ?
>
343 <p
><input onclick
="return confirm('Please read the warning above. Continue?')" type
="submit" value
="Initialize database" style
="color : red"></p
>
345 <p
><input type
="submit" value
="Initialize database" style
="color : red"></p
>
351 <input type
="hidden" name
="DB_USER" value
="<?php echo $DB_USER ?>"/>
352 <input type
="hidden" name
="DB_PASS" value
="<?php echo $DB_PASS ?>"/>
353 <input type
="hidden" name
="DB_NAME" value
="<?php echo $DB_NAME ?>"/>
354 <input type
="hidden" name
="DB_HOST" value
="<?php echo $DB_HOST ?>"/>
355 <input type
="hidden" name
="DB_PORT" value
="<?php echo $DB_PORT ?>"/>
356 <input type
="hidden" name
="DB_TYPE" value
="<?php echo $DB_TYPE ?>"/>
357 <input type
="hidden" name
="SELF_URL_PATH" value
="<?php echo $SELF_URL_PATH ?>"/>
359 <input type
="hidden" name
="op" value
="skipschema">
360 <p
><input type
="submit" value
="Skip initialization"></p
>
367 } else if ($op == 'installschema' ||
$op == 'skipschema') {
369 $pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
372 print_error("Unable to connect to database using specified parameters.");
376 if ($op == 'installschema') {
378 print "<h2>Initializing database...</h2>";
380 $lines = explode(";", preg_replace("/[\r\n]/", "",
381 file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql")));
383 foreach ($lines as $line) {
384 if (strpos($line, "--") !== 0 && $line) {
385 $res = $pdo->query($line);
388 print_notice("Query: $line");
389 print_error("Error: " . implode(", ", $this->pdo
->errorInfo()));
394 print_notice("Database initialization completed.");
397 print_notice("Database initialization skipped.");
400 print "<h2>Generated configuration file</h2>";
402 print "<p>Copy following text and save as <code>config.php</code> in tt-rss main directory. It is suggested to read through the file to the end in case you need any options changed fom default values.</p>";
404 print "<p>After copying the file, you will be able to login with default username and password combination: <code>admin</code> and <code>password</code>. Don't forget to change the password immediately!</p>"; ?
>
406 <form action
="" method
="post">
407 <input type
="hidden" name
="op" value
="saveconfig">
408 <input type
="hidden" name
="DB_USER" value
="<?php echo $DB_USER ?>"/>
409 <input type
="hidden" name
="DB_PASS" value
="<?php echo $DB_PASS ?>"/>
410 <input type
="hidden" name
="DB_NAME" value
="<?php echo $DB_NAME ?>"/>
411 <input type
="hidden" name
="DB_HOST" value
="<?php echo $DB_HOST ?>"/>
412 <input type
="hidden" name
="DB_PORT" value
="<?php echo $DB_PORT ?>"/>
413 <input type
="hidden" name
="DB_TYPE" value
="<?php echo $DB_TYPE ?>"/>
414 <input type
="hidden" name
="SELF_URL_PATH" value
="<?php echo $SELF_URL_PATH ?>"/>
415 <?php
print "<textarea cols=\"80\" rows=\"20\">";
416 echo make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
417 $DB_PORT, $SELF_URL_PATH);
418 print "</textarea>"; ?
>
420 <?php
if (is_writable("..")) { ?
>
421 <p
>We can also
try saving the file automatically now
.</p
>
423 <p
><input type
="submit" value
="Save configuration"></p
>
426 print_error("Unfortunately, parent directory is not writable, so we're unable to save config.php automatically.");
429 print_notice("You can generate the file again by changing the form above.");
431 } else if ($op == "saveconfig") {
433 print "<h2>Saving configuration file to parent directory...</h2>";
435 if (!file_exists("../config.php")) {
437 $fp = fopen("../config.php", "w");
440 $written = fwrite($fp, make_config($DB_TYPE, $DB_HOST,
441 $DB_USER, $DB_NAME, $DB_PASS,
442 $DB_PORT, $SELF_URL_PATH));
445 print_notice("Successfully saved config.php. You can try <a href=\"..\">loading tt-rss now</a>.");
448 print_notice("Unable to write into config.php in tt-rss directory.");
453 print_error("Unable to open config.php in tt-rss directory for writing.");
456 print_error("config.php already present in tt-rss directory, refusing to overwrite.");