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
This commit is contained in:
Roman Kelesidis 2025-08-19 18:48:22 +03:00 committed by GitHub
commit b1b8c23d93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 52 additions and 17 deletions

View file

@ -297,26 +297,43 @@ if (!empty($DB_HOST) && !empty($DB_DATABASE) && !empty($DB_USERNAME)) {
// Autofill host in robots.txt // Autofill host in robots.txt
$robots_txt_file = BB_ROOT . '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 = file_get_contents($robots_txt_file);
$content = str_replace('example.com', $TP_HOST, $content); $content = str_replace('example.com', $TP_HOST, $content);
file_put_contents($robots_txt_file, $content); file_put_contents($robots_txt_file, $content);
} }
if (isset($APP_ENV) && $APP_ENV === 'local') { // Suggest configuration files based on selected web server
if (!is_file(BB_ROOT . 'library/config.local.php')) { out("--- Web Server configuration ---\n", 'info');
if (copy(BB_ROOT . 'library/config.php', BB_ROOT . 'library/config.local.php')) { echo "Which web server are you using? (nginx / caddy / apache): ";
out('- Local configuration file created!', 'success'); $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 { } 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');
} }
} break;
} else {
if (rename(__FILE__, __FILE__ . '_' . hash('xxh128', time()))) { case 'caddy':
out("- Installation file renamed!", 'success'); $config_path = BB_ROOT . $install_dir . 'Caddyfile';
} else { if (is_file($config_path)) {
out('- Cannot rename installation file (' . __FILE__ . '). Please, rename it manually for security reasons', 'warning'); 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... // 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'); out("\n- Voila! Good luck & have fun!", 'success');
} }

View file

@ -1,7 +1,7 @@
# Example Caddy configuration for TorrentPier # Example Caddy configuration for TorrentPier
example.com { example.com {
root * /path/to/root root * /path/to/www
encode gzip zstd encode gzip zstd
php_fastcgi unix//run/php/php-fpm.sock php_fastcgi unix//run/php/php-fpm.sock
try_files {path} {path}/ /index.php?{query} try_files {path} {path}/ /index.php?{query}

View file

@ -1,9 +1,9 @@
# Example nginx configuration for TorrentPier # Example nginx configuration for TorrentPier
server { server {
listen 80; # port listen 80;
server_name example.com; # your domain server_name example.com;
root /path/to/root; # folder with TorrentPier installed root /path/to/www;
index index.php; index index.php;
charset utf-8; charset utf-8;