diff --git a/.env.example b/.env.example index 122a244f..8e459397 100644 --- a/.env.example +++ b/.env.example @@ -10,19 +10,50 @@ INSTANCE=0 # SSL_KEY_PATH=/path/to/key.pem # PHP Service Settings -VICHAN_MYSQL__HOST=db -VICHAN_MYSQL__USER=vichan -VICHAN_MYSQL__NAME=vichan -VICHAN_MYSQL__PASSWORD=vichan! +## Database settings +VICHAN_MYSQL_HOST=db +VICHAN_MYSQL_USER=vichan +VICHAN_MYSQL_NAME=vichan +VICHAN_MYSQL_PASSWORD=vichan! + +## Security VICHAN_SECURE_LOGIN_ONLY=0 -# Redis Settings -VICHAN_REDIS_HOST=redis -VICHAN_REDIS_PORT=6379 -VICHAN_REDIS_PASSWORD=redis! +## Cookies +VICHAN_COOKIES_MOD=mod + +## Flood Control +VICHAN_FLOOD_TIME=30 +VICHAN_FLOOD_TIME_IP=120 +VICHAN_FLOOD_TIME_SAME=3600 +VICHAN_MAX_BODY=1800 +VICHAN_REPLY_LIMIT=250 +VICHAN_MAX_LINKS=20 + +## Images +VICHAN_IMAGES_MAX_FILESIZE=10485760 +VICHAN_IMAGES_THUMB_WIDTH=250 +VICHAN_IMAGES_THUMB_HEIGHT=250 +VICHAN_IMAGES_MAX_WIDTH=10000 +VICHAN_IMAGES_MAX_HEIGHT=10000 + +## Display +VICHAN_DISPLAY_THREADS_PER_PAGE=10 +VICHAN_DISPLAY_MAX_PAGES=11 +VICHAN_DISPLAY_THREADS_PREVIEW=5 + +## Directories +VICHAN_DIRECTORIES_ROOT=/ + # Database Service (MariaDB) Settings MYSQL_DATABASE=vichan MYSQL_USER=vichan MYSQL_PASSWORD=vichan! -MYSQL_ROOT_PASSWORD=vichan!! \ No newline at end of file +MYSQL_ROOT_PASSWORD=vichan!! + + +# Redis +VICHAN_REDIS_HOST=redis +VICHAN_REDIS_PORT=6379 +VICHAN_REDIS_PASSWORD=redis! diff --git a/compose.yml b/compose.yml index 9ebe3ef3..852ea849 100644 --- a/compose.yml +++ b/compose.yml @@ -32,14 +32,38 @@ services: - ./docker/php/jit.ini:/usr/local/etc/php/conf.d/jit.ini - ./docker/php/php.ini:/usr/local/etc/php/php.ini environment: - VICHAN_MYSQL__HOST: ${VICHAN_MYSQL__HOST} - VICHAN_MYSQL__USER: ${VICHAN_MYSQL__USER} - VICHAN_MYSQL__NAME: ${VICHAN_MYSQL__NAME} - VICHAN_MYSQL__PASSWORD: ${VICHAN_MYSQL__PASSWORD} + # Database settings + VICHAN_MYSQL_HOST: ${VICHAN_MYSQL_HOST} + VICHAN_MYSQL_USER: ${VICHAN_MYSQL_USER} + VICHAN_MYSQL_NAME: ${VICHAN_MYSQL_NAME} + VICHAN_MYSQL_PASSWORD: ${VICHAN_MYSQL_PASSWORD} + # Security VICHAN_SECURE_LOGIN_ONLY: ${VICHAN_SECURE_LOGIN_ONLY} + # Redis settings VICHAN_REDIS_HOST: ${VICHAN_REDIS_HOST} VICHAN_REDIS_PORT: ${VICHAN_REDIS_PORT} VICHAN_REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD} + # Cookies + VICHAN_COOKIES_MOD: ${VICHAN_COOKIES_MOD} + # Flood Control + VICHAN_FLOOD_TIME: ${VICHAN_FLOOD_TIME} + VICHAN_FLOOD_TIME_IP: ${VICHAN_FLOOD_TIME_IP} + VICHAN_FLOOD_TIME_SAME: ${VICHAN_FLOOD_TIME_SAME} + VICHAN_MAX_BODY: ${VICHAN_MAX_BODY} + VICHAN_REPLY_LIMIT: ${VICHAN_REPLY_LIMIT} + VICHAN_MAX_LINKS: ${VICHAN_MAX_LINKS} + # Images + VICHAN_IMAGES_MAX_FILESIZE: ${VICHAN_IMAGES_MAX_FILESIZE} + VICHAN_IMAGES_THUMB_WIDTH: ${VICHAN_IMAGES_THUMB_WIDTH} + VICHAN_IMAGES_THUMB_HEIGHT: ${VICHAN_IMAGES_THUMB_HEIGHT} + VICHAN_IMAGES_MAX_WIDTH: ${VICHAN_IMAGES_MAX_WIDTH} + VICHAN_IMAGES_MAX_HEIGHT: ${VICHAN_IMAGES_MAX_HEIGHT} + # Display + VICHAN_DISPLAY_THREADS_PER_PAGE: ${VICHAN_DISPLAY_THREADS_PER_PAGE} + VICHAN_DISPLAY_MAX_PAGES: ${VICHAN_DISPLAY_MAX_PAGES} + VICHAN_DISPLAY_THREADS_PREVIEW: ${VICHAN_DISPLAY_THREADS_PREVIEW} + # Directories + VICHAN_DIRECTORIES_ROOT: ${VICHAN_DIRECTORIES_ROOT} depends_on: - db @@ -61,6 +85,8 @@ services: image: redis:latest container_name: vichan_redis restart: unless-stopped + environment: + REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD} volumes: - ./local-instances/${INSTANCE:-0}/redis:/data command: redis-server --requirepass ${VICHAN_REDIS_PASSWORD} diff --git a/docker/doc.md b/docker/doc.md index 051ae56e..c481757a 100644 --- a/docker/doc.md +++ b/docker/doc.md @@ -1,20 +1,63 @@ -The `php-fpm` process runs containerized. -The php application always uses `/var/www` as it's work directory and home folder, and if `/var/www` is bind mounted it -is necessary to adjust the path passed via FastCGI to `php-fpm` by changing the root directory to `/var/www`. -This can achieved in nginx by setting the `fastcgi_param SCRIPT_FILENAME` to `/var/www/$fastcgi_script_name;` +# Vichan Docker Setup -The default docker compose settings are intended for development and testing purposes. -The folder structure expected by compose is as follows +The `php-fpm` process runs containerized. +The PHP application always uses `/var/www` as its work directory and home folder. If `/var/www` is bind mounted, you must adjust the path passed via FastCGI to `php-fpm`. +To fix this: +1. **Adjust the root path**: Set `fastcgi_param SCRIPT_FILENAME` to `/var/www/$fastcgi_script_name;` in your nginx config. + +The default Docker Compose settings are meant for development and testing. + +Expected folder structure: ``` └── local-instances └── 1 - ├── mysql + ├── db └── www ``` -The vichan container is by itself much less rigid. +To run the app: +1. **Start all containers**: Run `docker compose up -d --build` at the root of vichan directory +2. **Rebuild just the PHP container**: Run `docker compose up -d --build php` (useful during development) -Use `docker compose up --build` to start the docker compose. -Use `docker compose up --build -d php` to rebuild just the vichan container while the compose is running. Useful for development. +--- + +## PHP File Size Limit + +To upload larger files, increase the default PHP file size limit (2MB). Since this setup uses Docker, follow these steps: + +1. **Open the config file**: Edit `./docker/php/php.ini` in your project directory. +2. **Add or update these lines** to increase the file size limit to 10MB: + ```ini + upload_max_filesize = 10M + post_max_size = 10M + ``` +3. **Restart your containers** to apply the changes: + ```bash + docker compose restart + ``` + +--- + +By default, PHP limits file uploads to **2MB** — so increasing this is often required when uploading images or documents. + +--- + +## Using the `.env` File + +Environment variables for the Docker Compose setup can be managed easily using a `.env` file. + +### Steps to Use It: +1. **Copy the example**: Start by copying `.env.example` to `.env` + ```bash + cp .env.example .env + ``` +2. **Edit `.env`**: Please make sure to change the default passwords for your setup. + +### What It Controls: +- Instance folder reference (e.g. `local-instances/0`) +- Database credentials +- Redis connection details +- Secure login +- Optional SSL certificate paths for nginx diff --git a/inc/config.php b/inc/config.php index 4f917f82..e7655634 100644 --- a/inc/config.php +++ b/inc/config.php @@ -137,44 +137,43 @@ * ==================== */ - /* - * On top of the static file caching system, you can enable the additional caching system which is - * designed to minimize request processing can significantly increase speed when posting or using - * the moderator interface. - * - * https://github.com/vichan-devel/vichan/wiki/cache - */ + // Determine if Redis is configured via environment variables + $redis_enabled = getenv('VICHAN_REDIS_HOST') !== false && getenv('VICHAN_REDIS_PORT') !== false; - // Uses a PHP array. MUST NOT be used in multiprocess environments. - $config['cache']['enabled'] = 'php'; - // The recommended in-memory method of caching. Requires the extension. Due to how APCu works, this should be - // disabled when you run tools from the cli. - // $config['cache']['enabled'] = 'apcu'; - // The Memcache server. Requires the memcached extension, with a final D. - // $config['cache']['enabled'] = 'memcached'; - // The Redis server. Requires the extension. - // $config['cache']['enabled'] = 'redis'; - // Use the local cache folder. Slower than native but available out of the box and compatible with multiprocess - // environments. You can mount a ram-based filesystem in the cache directory to improve performance. - // $config['cache']['enabled'] = 'fs'; - // Technically available, offers a no-op fake cache. Don't use this outside of testing or debugging. - // $config['cache']['enabled'] = 'none'; + // Configure cache + if ($redis_enabled) { + $config['cache']['enabled'] = 'redis'; + $config['cache']['redis'] = [ + 'host' => getenv('VICHAN_REDIS_HOST') ?: 'localhost', + 'port' => (int)(getenv('VICHAN_REDIS_PORT') ?: 6379), + 'password' => getenv('VICHAN_REDIS_PASSWORD') ?: '', + 'database' => 1, + ]; + } else { + $config['cache']['enabled'] = 'php'; + } - // Timeout for cached objects such as posts and HTML. + // Configure sessions to use Redis if enabled + if ($redis_enabled) { + $config['session']['enabled'] = 'redis'; + $config['session']['redis'] = [ + 'host' => getenv('VICHAN_REDIS_HOST') ?: 'localhost', + 'port' => (int)(getenv('VICHAN_REDIS_PORT') ?: 6379), + 'password' => getenv('VICHAN_REDIS_PASSWORD') ?: '', + 'database' => 1, + ]; + } + + // Cache timeout for cached objects $config['cache']['timeout'] = 60 * 60 * 48; // 48 hours - // Optional prefix if you're running multiple vichan instances on the same machine. + // Optional prefix for multiple vichan instances $config['cache']['prefix'] = ''; - // Memcached servers to use. Read more: http://www.php.net/manual/en/memcached.addservers.php - $config['cache']['memcached'] = array( - array('localhost', 11211) - ); - - // Redis server to use. Location, port, password, database id. - // Note that vichan may clear the database at times, so you may want to pick a database id just for - // vichan to use. - $config['cache']['redis'] = array('localhost', 6379, '', 1); + // Memcached servers (not used) + $config['cache']['memcached'] = [ + ['localhost', 11211] + ]; // EXPERIMENTAL: Should we cache configs? Warning: this changes board behaviour, i'd say, a lot. // If you have any lambdas/includes present in your config, you should move them to instance-functions.php diff --git a/install.php b/install.php index 02b40b1b..3c7bd3dd 100644 --- a/install.php +++ b/install.php @@ -916,30 +916,62 @@ if ($step == 0) { } elseif ($step == 2) { $page['title'] = 'Configuration'; $sg = new SaltGen(); - $config['cookies']['salt'] = $sg->generate(); + + // Initialize configuration with defaults and override with environment variables + $config['cookies'] = array( + 'mod' => getenv('VICHAN_COOKIES_MOD') !== false ? getenv('VICHAN_COOKIES_MOD') : 'mod', + 'salt' => $sg->generate(), + ); + + $config['flood_time'] = getenv('VICHAN_FLOOD_TIME') !== false ? (int)getenv('VICHAN_FLOOD_TIME') : 30; + $config['flood_time_ip'] = getenv('VICHAN_FLOOD_TIME_IP') !== false ? (int)getenv('VICHAN_FLOOD_TIME_IP') : 120; + $config['flood_time_same'] = getenv('VICHAN_FLOOD_TIME_SAME') !== false ? (int)getenv('VICHAN_FLOOD_TIME_SAME') : 3600; + $config['max_body'] = getenv('VICHAN_MAX_BODY') !== false ? (int)getenv('VICHAN_MAX_BODY') : 1800; + $config['reply_limit'] = getenv('VICHAN_REPLY_LIMIT') !== false ? (int)getenv('VICHAN_REPLY_LIMIT') : 250; + $config['max_links'] = getenv('VICHAN_MAX_LINKS') !== false ? (int)getenv('VICHAN_MAX_LINKS') : 20; + + $config['max_filesize'] = getenv('VICHAN_IMAGES_MAX_FILESIZE') !== false ? (int)getenv('VICHAN_IMAGES_MAX_FILESIZE') : 10485760; // This is 10MB + $config['thumb_width'] = getenv('VICHAN_IMAGES_THUMB_WIDTH') !== false ? (int)getenv('VICHAN_IMAGES_THUMB_WIDTH') : 250; + $config['thumb_height'] = getenv('VICHAN_IMAGES_THUMB_HEIGHT') !== false ? (int)getenv('VICHAN_IMAGES_THUMB_HEIGHT') : 250; + $config['max_width'] = getenv('VICHAN_IMAGES_MAX_WIDTH') !== false ? (int)getenv('VICHAN_IMAGES_MAX_WIDTH') : 10000; + $config['max_height'] = getenv('VICHAN_IMAGES_MAX_HEIGHT') !== false ? (int)getenv('VICHAN_IMAGES_MAX_HEIGHT') : 10000; + + $config['threads_per_page'] = getenv('VICHAN_DISPLAY_THREADS_PER_PAGE') !== false ? (int)getenv('VICHAN_DISPLAY_THREADS_PER_PAGE') : 10; + $config['max_pages'] = getenv('VICHAN_DISPLAY_MAX_PAGES') !== false ? (int)getenv('VICHAN_DISPLAY_MAX_PAGES') : 11; + $config['threads_preview'] = getenv('VICHAN_DISPLAY_THREADS_PREVIEW') !== false ? (int)getenv('VICHAN_DISPLAY_THREADS_PREVIEW') : 5; + + $config['root'] = getenv('VICHAN_DIRECTORIES_ROOT') !== false ? getenv('VICHAN_DIRECTORIES_ROOT') : '/'; + $config['secure_trip_salt'] = $sg->generate(); $config['secure_password_salt'] = $sg->generate(); // Set database configuration from Docker environment variables, leave empty if not found $config['db'] = array( 'type' => 'mysql', // Default, required for MySQL - 'server' => getenv('VICHAN_MYSQL__HOST') !== false ? getenv('VICHAN_MYSQL__HOST') : '', - 'database' => getenv('VICHAN_MYSQL__NAME') !== false ? getenv('VICHAN_MYSQL__NAME') : '', - 'user' => getenv('VICHAN_MYSQL__USER') !== false ? getenv('VICHAN_MYSQL__USER') : '', - 'password' => getenv('VICHAN_MYSQL__PASSWORD') !== false ? getenv('VICHAN_MYSQL__PASSWORD') : '', + 'server' => getenv('VICHAN_MYSQL_HOST') !== false ? getenv('VICHAN_MYSQL_HOST') : '', + 'database' => getenv('VICHAN_MYSQL_NAME') !== false ? getenv('VICHAN_MYSQL_NAME') : '', + 'user' => getenv('VICHAN_MYSQL_USER') !== false ? getenv('VICHAN_MYSQL_USER') : '', + 'password' => getenv('VICHAN_MYSQL_PASSWORD') !== false ? getenv('VICHAN_MYSQL_PASSWORD') : '', ); - - // Append secure_login_only to $_SESSION['more'] if VICHAN_SECURE_LOGIN_ONLY is set from Docker environment variables + + // Append secure_login_only to $_SESSION['more'] if VICHAN_SECURE_LOGIN_ONLY is set if (getenv('VICHAN_SECURE_LOGIN_ONLY') !== false) { $secure_login_only = (int)getenv('VICHAN_SECURE_LOGIN_ONLY'); $_SESSION['more'] .= "\n\$config['cookies']['secure_login_only'] = $secure_login_only;"; } - + + // Configuration notice at the top + $page['body'] = '

Configuration Note

' . + '

The following settings can still be configured later. For more customization options, check the Vichan configuration wiki.

'; + + // Append the configuration form + $page['body'] .= Element('installer/config.html', array( + 'config' => $config, + 'more' => $_SESSION['more'], + )); + echo Element('page.html', array( - 'body' => Element('installer/config.html', array( - 'config' => $config, - 'more' => $_SESSION['more'], - )), + 'body' => $page['body'], 'title' => 'Configuration', 'config' => $config )); @@ -1014,14 +1046,18 @@ if ($step == 0) { } $page['title'] = 'Installation complete'; - $page['body'] = '

Thank you for installing vichan. Please report any bugs you discover. How do I edit the config files?

'; + $page['body'] = '

Thank you for using vichan. Please report any bugs you discover.

' . + '

If you are new to vichan, please check out the documentation.

'; - // notice and button + // Admin panel notice $page['body'] .= '

Next Steps

' . - '

You can now log in to the admin panel at /mod.php using the default credentials: Username: admin, Password: password.

' . + '

You can now log in to the admin panel at /mod.php using the default credentials:

' . + '

Username: admin

' . + '

Password: password

' . '

Important: For security, please change the administrator password immediately after logging in.

' . '

'; + if (!empty($sql_errors)) { $page['body'] .= '

SQL errors

SQL errors were encountered when trying to install the database. This may be the result of using a database which is already occupied with a vichan installation; if so, you can probably ignore this.

The errors encountered were:

' . '

Warning: Ignoring errors is not recommended and may cause installation issues.

' . @@ -1042,18 +1078,18 @@ if ($step == 0) { echo Element('page.html', $page); } elseif ($step == 5) { $page['title'] = 'Installation complete'; - $page['body'] = '

Thank you for installing vichan. Please report any bugs you discover.

'; + $page['body'] = '

Thank you for using vichan. Please report any bugs you discover.

' . + '

If you are new to vichan, please check out the documentation.

'; - // onboarding notice and button to mod.php + // Admin panel notice $page['body'] .= '

Next Steps

' . '

You can now log in to the admin panel at /mod.php using the default credentials:

' . - '
    ' . - '
  • Username: admin
  • ' . - '
  • Password: password
  • ' . - '
' . + '

Username: admin

' . + '

Password: password

' . '

Important: For security, please change the administrator password immediately after logging in.

' . '

'; + $boards = listBoards(); foreach ($boards as &$_board) { setupBoard($_board); diff --git a/templates/installer/config.html b/templates/installer/config.html index c2ca6ec6..09111c34 100644 --- a/templates/installer/config.html +++ b/templates/installer/config.html @@ -15,9 +15,6 @@ - -

The following is all later configurable. For more options, edit your configuration files after installing.

-
Cookies @@ -52,34 +49,35 @@