From b1b8c23d93af2bb2ee3069ca9e87273a2675d546 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Tue, 19 Aug 2025 18:48:22 +0300 Subject: [PATCH] feat(installer): Add web server config guidance post-installation (#2086) * feat(installer): Add web server config guidance post-installation * Update install.php * Update install.php * Update install.php * Update install.php * Update install.php --- install.php | 61 ++++++++++++++++++++++++++++++++++++---------- install/Caddyfile | 2 +- install/nginx.conf | 6 ++--- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/install.php b/install.php index 327c0fb5d..5db769511 100644 --- a/install.php +++ b/install.php @@ -297,26 +297,43 @@ if (!empty($DB_HOST) && !empty($DB_DATABASE) && !empty($DB_USERNAME)) { // Autofill host in robots.txt $robots_txt_file = BB_ROOT . 'robots.txt'; - if (isset($TP_HOST) && is_file($robots_txt_file)) { + if (isset($TP_HOST) && is_file($robots_txt_file) && is_writable($robots_txt_file)) { $content = file_get_contents($robots_txt_file); $content = str_replace('example.com', $TP_HOST, $content); file_put_contents($robots_txt_file, $content); } - if (isset($APP_ENV) && $APP_ENV === 'local') { - if (!is_file(BB_ROOT . 'library/config.local.php')) { - if (copy(BB_ROOT . 'library/config.php', BB_ROOT . 'library/config.local.php')) { - out('- Local configuration file created!', 'success'); + // Suggest configuration files based on selected web server + out("--- Web Server configuration ---\n", 'info'); + echo "Which web server are you using? (nginx / caddy / apache): "; + $webserver = mb_strtolower(trim(readline())); + $install_dir = 'install' . DIRECTORY_SEPARATOR; + + switch ($webserver) { + case 'nginx': + $config_path = BB_ROOT . $install_dir . 'nginx.conf'; + if (is_file($config_path)) { + out("- Nginx configuration file: $config_path", 'success'); } else { - out('- Cannot create library/config.local.php file. You can create it manually, just copy config.php and rename it to config.local.php', 'warning'); + out("- Nginx config not found: $config_path", 'warning'); + out('- You can find an example in the documentation', 'info'); } - } - } else { - if (rename(__FILE__, __FILE__ . '_' . hash('xxh128', time()))) { - out("- Installation file renamed!", 'success'); - } else { - out('- Cannot rename installation file (' . __FILE__ . '). Please, rename it manually for security reasons', 'warning'); - } + break; + + case 'caddy': + $config_path = BB_ROOT . $install_dir . 'Caddyfile'; + if (is_file($config_path)) { + out("- Caddy configuration file: $config_path", 'success'); + } else { + out("- Caddy config not found: $config_path", 'warning'); + out('- You can find an example in the documentation', 'info'); + } + break; + } + if (in_array($webserver, ['nginx', 'caddy'])) { + out("- Note: These configuration files include settings specific to TorrentPier,\nsuch as URL rewriting, security headers, and PHP handling", 'info'); + out('- Adapt them to your environment and web server setup', 'info'); + sleep(3); } // Cleanup... @@ -337,5 +354,23 @@ if (!empty($DB_HOST) && !empty($DB_DATABASE) && !empty($DB_USERNAME)) { } } + if (isset($APP_ENV) && $APP_ENV === 'local') { + if (!is_file(BB_ROOT . 'library/config.local.php')) { + echo "\n"; + if (copy(BB_ROOT . 'library/config.php', BB_ROOT . 'library/config.local.php')) { + out('- Local configuration file created!', 'success'); + } else { + out('- Cannot create library/config.local.php file. You can create it manually, just copy config.php and rename it to config.local.php', 'warning'); + } + } + } else { + echo "\n"; + if (rename(__FILE__, __FILE__ . '_' . hash('xxh128', time()))) { + out("- Installation file renamed!", 'success'); + } else { + out('- Cannot rename installation file (' . __FILE__ . '). Please, rename it manually for security reasons', 'warning'); + } + } + out("\n- Voila! Good luck & have fun!", 'success'); } diff --git a/install/Caddyfile b/install/Caddyfile index 683d69994..43c8f8aa2 100644 --- a/install/Caddyfile +++ b/install/Caddyfile @@ -1,7 +1,7 @@ # Example Caddy configuration for TorrentPier example.com { - root * /path/to/root + root * /path/to/www encode gzip zstd php_fastcgi unix//run/php/php-fpm.sock try_files {path} {path}/ /index.php?{query} diff --git a/install/nginx.conf b/install/nginx.conf index 49a407ba4..66889cb2a 100644 --- a/install/nginx.conf +++ b/install/nginx.conf @@ -1,9 +1,9 @@ # Example nginx configuration for TorrentPier server { - listen 80; # port - server_name example.com; # your domain - root /path/to/root; # folder with TorrentPier installed + listen 80; + server_name example.com; + root /path/to/www; index index.php; charset utf-8;