### Development Setup for FileBrowser on Linux
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Sets up a development environment for FileBrowser on Linux by cloning the repository, installing dependencies, and building the project. Starts the development server for both backend and frontend.
```bash
git clone https://github.com/linuxforphp/filebrowser.git
cd filebrowser
cp configuration_sample.php configuration.php
chmod -R 775 private/
chmod -R 775 repository/
composer install --ignore-platform-reqs
npm install
npm run build
```
```bash
npm run serve
# visit http://localhost:8080
```
--------------------------------
### Manual Project Setup for Development
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/development.md
Steps to manually set up the project for development if Docker is not used. This includes cloning the repository, copying configuration, setting permissions, and installing dependencies.
```bash
git clone https://github.com/linuxforphp/filebrowser.git
cd filebrowser
cp configuration_sample.php configuration.php
chmod -R 775 private/
chmod -R 775 repository/
composer install --ignore-platform-reqs
npm install
npm run build
```
--------------------------------
### Clone and Install Dependencies (Docker)
Source: https://github.com/linuxforphp/filebrowser/blob/master/README.md
Clone the repository and install Composer dependencies. This is the initial setup step when using Docker for development.
```bash
git clone https://github.com/linuxforphp/filebrowser.git
cd filebrowser
composer install --ignore-platform-reqs
```
--------------------------------
### Start Development Container
Source: https://github.com/linuxforphp/filebrowser/blob/master/README.md
Starts the Docker container for development. Requires Docker and Linux for Composer to be installed.
```bash
vendor/bin/linuxforcomposer docker:run start
```
--------------------------------
### Install Replicate Adapter and Dropbox
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Install the Replicate adapter and a backend adapter (e.g., Dropbox) for simultaneous writing.
```bash
composer require league/flysystem-replicate-adapter
composer require spatie/flysystem-dropbox
```
--------------------------------
### Start Docker Container for Development
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/development.md
Use this command to start the development environment using Docker. Ensure Docker and Linux for Composer are installed.
```bash
git clone https://github.com/linuxforphp/filebrowser.git
cd filebrowser
composer install --ignore-platform-reqs
vendor/bin/linuxforcomposer docker:run start
```
--------------------------------
### Define a Route with Roles and Permissions
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/router.md
Example of defining a GET route for downloading files, specifying allowed user roles and permissions.
```php
[
'route' => [
'GET', '/download/{path_encoded}', '\Filebrowser\Controllers\DownloadController@download',
],
'roles' => [
'guest', 'user', 'admin',
],
'permissions' => [
'download',
],
]
```
--------------------------------
### Install Replicate Adapter
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Requires the league/flysystem-replicate-adapter package for seamless transitions between storage adapters.
```default
composer require league/flysystem-replicate-adapter
```
--------------------------------
### Dropbox Adapter Installation and Configuration
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Install the Dropbox adapter using composer. This sample configuration requires an authorization token and uses the Spatie Dropbox client.
```bash
composer require spatie/flysystem-dropbox
```
```php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [
'case_sensitive' => false,
],
'adapter' => function () {
$authorizationToken = '1234';
$client = new \Spatie\Dropbox\Client($authorizationToken);
return new \Spatie\FlysystemDropbox\DropboxAdapter($client);
},
],
],
],
```
--------------------------------
### Install SFTP Adapter
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Use this command to install the SFTP adapter for Flysystem.
```bash
composer require league/flysystem-sftp
```
--------------------------------
### Install Dropbox Adapter
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Use this command to install the Dropbox adapter for Flysystem.
```bash
composer require spatie/flysystem-dropbox
```
--------------------------------
### SFTP Adapter Installation and Configuration
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Install the SFTP adapter using composer. This configuration sample shows basic SFTP connection details. For advanced options like private key authentication, refer to the Flysystem documentation.
```bash
composer require league/flysystem-sftp
```
```php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
return new \League\Flysystem\Sftp\SftpAdapter([
'host' => 'example.com',
'port' => 22,
'username' => 'demo',
'password' => 'password',
'timeout' => 10,
]);
},
],
],
],
```
--------------------------------
### Controller Constructor with Dependency Injection
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/router.md
Example of a controller constructor demonstrating dependency injection for configuration, session, authentication, and filesystem.
```php
public function __construct(Config $config, Session $session, AuthInterface $auth, Filesystem $storage)
{
// ...
}
```
--------------------------------
### Install Azure Blob Storage Adapter
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Requires the league/flysystem-azure-blob-storage package for Azure Blob Storage integration.
```default
composer require league/flysystem-azure-blob-storage
```
--------------------------------
### Amazon S3 Adapter (v3) Installation and Configuration
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Install the Amazon S3 v3 adapter using composer. This configuration requires AWS credentials, region, version, and a bucket name. The S3Client is instantiated with these details.
```bash
composer require league/flysystem-aws-s3-v3
```
```php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
$client = new \Aws\S3\S3Client([
'credentials' => [
'key' => '123456',
'secret' => 'secret123456',
],
'region' => 'us-east-1',
'version' => 'latest',
]);
return new \League\Flysystem\AwsS3v3\AwsS3Adapter($client, 'my-bucket-name');
},
],
],
],
```
--------------------------------
### Install DigitalOcean Spaces Adapter
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Requires the league/flysystem-aws-s3-v3 package for DigitalOcean Spaces integration. This adapter is compatible with S3.
```default
composer require league/flysystem-aws-s3-v3
```
--------------------------------
### Ubuntu/Debian Quick Install for FileBrowser
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Installs FileBrowser on Ubuntu/Debian systems using apt and wget. Ensure to change the default password immediately after login.
```bash
apt update
apt install -y wget unzip php apache2 libapache2-mod-php php-zip
cd /var/www/
wget -O filebrowser_latest.zip https://filebrowser.linuxforphp.net/files/filebrowser_latest.zip
unzip filebrowser_latest.zip && rm filebrowser_latest.zip
chown -R www-data:www-data filebrowser/
chmod -R 775 filebrowser/
echo "
DocumentRoot /var/www/filebrowser/dist
" >> /etc/apache2/sites-available/filebrowser.conf
a2dissite 000-default.conf
a2ensite filebrowser.conf
systemctl restart apache2
```
--------------------------------
### Install Predis for Redis Session Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Installs the Predis library using Composer, which is required for Redis session handling.
```bash
composer require predis/predis
```
--------------------------------
### Controller Action with Route Parameters and Dependencies
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/router.md
Example of a controller action method that accepts a route parameter and injected dependencies like Request, Response, and StreamedResponse.
```php
public function download($path_encoded, Request $request, Response $response, StreamedResponse $streamedResponse)
{
// ...
}
```
--------------------------------
### Import Default Users via SQL
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/auth.md
SQL query to insert default user accounts into the 'users' table. Includes guest and admin user examples.
```sql
INSERT INTO `users` (`username`, `name`, `role`, `permissions`, `homedir`, `password`)
VALUES
('guest', 'Guest', 'guest', '', '/', ''),
('admin', 'Admin', 'admin', 'read|write|upload|download|batchdownload|zip', '/', '$2y$10$Nu35w4pteLfc7BDCIkDPkecjw8wsH8Y2GMfIewUbXLT7zzW6WOxwq');
```
--------------------------------
### Configure Replicate Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Configure the Replicate adapter to write to two backends simultaneously, useful for zero-downtime migrations. This example uses Dropbox and a local directory.
```php
// configuration.php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => ['case_sensitive' => false],
'adapter' => function () {
$client = new \Spatie\Dropbox\Client('YOUR_DROPBOX_TOKEN');
$source = new \Spatie\FlysystemDropbox\DropboxAdapter($client);
$replica = new \League\Flysystem\Adapter\Local(__DIR__.'/repository');
return new League\Flysystem\Replicate\ReplicateAdapter($source, $replica);
},
],
],
],
```
--------------------------------
### FTP Adapter Configuration
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Configure the FTP storage adapter. Ensure you consult the Flysystem documentation for specific setup requirements for FTP.
```php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
return new \League\Flysystem\Adapter\Ftp([
'host' => 'example.com',
'username' => 'demo',
'password' => 'password',
'port' => 21,
'timeout' => 10,
]);
},
],
],
],
```
--------------------------------
### Run PHP Unit Tests
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Execute PHP unit tests using the provided command. Ensure necessary extensions like xdebug, php-zip, and sqlite are installed.
```bash
# PHP unit tests (requires xdebug, php-zip, sqlite extensions)
vendor/bin/phpunit
```
--------------------------------
### Install FileBrowser on Ubuntu/Debian
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/installation.md
This script installs FileBrowser on a fresh Ubuntu 18.04 or Debian 10.3 server. It updates packages, downloads and extracts FileBrowser, sets permissions, and configures Apache.
```default
apt update
apt install -y wget unzip php apache2 libapache2-mod-php php-zip
cd /var/www/
wget -O filebrowser_latest.zip https://filebrowser.linuxforphp.net/files/filebrowser_latest.zip
unzip filebrowser_latest.zip && rm filebrowser_latest.zip
chown -R www-data:www-data filebrowser/
chmod -R 775 filebrowser/
echo "
DocumentRoot /var/www/filebrowser/dist
"
>> /etc/apache2/sites-available/filebrowser.conf
a2dissite 000-default.conf
a2ensite filebrowser.conf
systemctl restart apache2
exit
```
--------------------------------
### Example Custom Controller in PHP
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Implement custom controllers with dependencies injected automatically via PHP-DI type hints. Ensure the controller and its methods are correctly defined to handle requests and responses.
```php
// Example custom controller
namespace App\Controllers;
use Filebrowser\Config\Config;
use Filebrowser\Services\Auth\AuthInterface;
use Filebrowser\Services\Storage\Filesystem;
use Filebrowser\Kernel\Request;
use Filebrowser\Kernel\Response;
class MyController
{
public function __construct(
Config $config,
AuthInterface $auth,
Filesystem $storage
) {
// services injected automatically
}
public function handle(Request $request, Response $response)
{
$response->json(200, ['status' => 'ok']);
}
}
```
--------------------------------
### Configure Redis Session Handler
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/sessions.md
Sets up the session handler to use Redis. Requires the 'predis/predis' library to be installed via Composer. Adjust the connection URL for your Redis instance.
```php
'Filebrowser\Services\Session\SessionStorageInterface' => [
'handler' => '\Filebrowser\Services\Session\Adapters\SessionStorage',
'config' => [
'handler' => function () {
$predis = new \Predis\Client('tcp://127.0.0.1:6379');
$handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler($predis);
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler);
},
],
],
```
--------------------------------
### Configure Default JSON File Auth
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/auth.md
Use this configuration for a lightweight setup where user credentials are stored in a JSON file. Ensure the web server has write permissions to the specified file.
```php
'Filebrowser\Services\Auth\AuthInterface' => [
'handler' => '\Filebrowser\Services\Auth\Adapters\JsonFile',
'config' => [
'file' => __DIR__.'/private/users.json',
],
],
```
--------------------------------
### Login via REST API
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Example using curl to log in to the File Browser API. This returns a session cookie that must be used for subsequent authenticated requests.
```bash
# Login — returns session cookie
curl -c cookies.txt -X POST "http://example.com/?r=/login" \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin123"}'
```
--------------------------------
### Configure WordPress Authentication
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
PHP configuration for integrating with an existing WordPress installation for authentication. Set the path to your WordPress directory and define default permissions.
```php
'Filebrowser\Services\Auth\AuthInterface' => [
'handler' => '\Filebrowser\Services\Auth\Adapters\WPAuth',
'config' => [
'wp_dir' => '/var/www/my_wordpress_site/',
'permissions' => ['read', 'write', 'upload', 'download', 'batchdownload', 'zip'],
'private_repos' => false, // set true to give each WP user their own home folder
],
],
// Redirect logged-out users back to WordPress login
'frontend_config' => [
// ...
'guest_redirection' => 'http://example.com/wp-admin/',
],
```
--------------------------------
### Configure Tmpfs Service
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/tmpfs.md
Configure the Tmpfs service with a specific path, garbage collection probability, and expiration time. Ensure the path is accessible by all instances in a multi-node setup.
```php
'Filebrowser\Services\Tmpfs\TmpfsInterface' => [
'handler' => '\Filebrowser\Services\Tmpfs\Adapters\Tmpfs',
'config' => [
'path' => __DIR__.'/private/tmp/',
'gc_probability_perc' => 10,
'gc_older_than' => 60 * 60 * 24 * 2, // 2 days
],
],
```
--------------------------------
### Get User and CSRF Token via REST API
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Example using curl to retrieve the current user's information and the CSRF token from the File Browser API. The CSRF token is returned in the 'x-csrf-token' header and is required for write operations.
```bash
# Get current user + CSRF token
curl -b cookies.txt -v "http://example.com/?r=/getuser"
# x-csrf-token header in response must be sent back on all POST requests
```
--------------------------------
### Configure Replicate Adapter
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Sample configuration for the ReplicateAdapter, which takes a source and replica adapter. Read operations go to the source, while all changes are delegated to both.
```default
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [
'case_sensitive' => false,
],
'adapter' => function () {
$authorizationToken = '1234';
$client = new \Spatie\Dropbox\Client($authorizationToken);
$source = new \Spatie\FlysystemDropbox\DropboxAdapter($client);
$replica = new \League\Flysystem\Adapter\Local(__DIR__.'/repository');
return new League\Flysystem\Replicate\ReplicateAdapter($source, $replica);
},
],
],
],
```
--------------------------------
### Create New User
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Creates a new user with specified details including username, name, role, home directory, password, and permissions. Requires administrator privileges.
```bash
# Create a new user
curl -b cookies.txt -X POST "http://example.com/?r=/storeuser" \
-H "Content-Type: application/json" \
-H "x-csrf-token: TOKEN" \
-d '{
"username": "jdoe",
"name": "Jane Doe",
"role": "user",
"homedir": "/teams/marketing",
"password": "SecurePass1!",
"permissions": ["read", "upload", "download"]
}'
```
--------------------------------
### Run Tests and Static Analysis
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/development.md
Commands to execute unit tests, static analysis, and linting. Requires xdebug, php-zip, and sqlite PHP extensions for testing.
```bash
vendor/bin/phpunit
vendor/bin/phpstan analyse ./backend
npm run lint
npm run e2e
```
--------------------------------
### Default Local Disk Adapter Configuration
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Configure the default local filesystem adapter. The 'fastzip' option enables direct use of zip/unzip binaries for faster operations and better handling of special Unix files.
```php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
return new \League\Flysystem\Adapter\Local(
REPOSITORY_ROOT
);
},
],
'fastzip' => true // LOCAL ONLY! If true, it will override the \League\Flysystem\Adapter\Local adapter, and use the zip and unzip binaries directly.
],
],
```
--------------------------------
### Translate a String
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/translations/default.md
When translating, only modify the value on the right side of the colon. For example, to translate 'Close' to German, you would write 'Schliessen'.
```default
'Close': 'Schliessen',
```
--------------------------------
### Configure Logging with Monolog
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Sets up Monolog for logging, allowing multiple handlers to be stacked. The default is a file handler.
```php
// configuration.php
'Filebrowser\Services\Logger\LoggerInterface' => [
'handler' => '\Filebrowser\Services\Logger\Adapters\MonoLogger',
'config' => [
'monolog_handlers' => [
// File handler (default)
function () {
return new \Monolog\Handler\StreamHandler(
__DIR__.'/private/logs/app.log',
\Monolog\Logger::DEBUG
);
},
// Optional: add a Slack or email handler on top
// function () { return new \Monolog\Handler\SlackWebhookHandler(...); },
],
],
],
```
--------------------------------
### Get User API
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Retrieves the current user's information and a CSRF token for subsequent requests. The CSRF token is provided in the 'x-csrf-token' response header.
```APIDOC
## GET /getuser
### Description
Retrieves the current user's information and a CSRF token for subsequent requests. The CSRF token is provided in the 'x-csrf-token' response header.
### Method
GET
### Endpoint
/?r=/getuser
### Response
#### Success Response (200)
- **status** (string) - Indicates the success of the operation.
- **data** (object) - Contains user information.
- **role** (string) - The role of the user.
- **permissions** (array) - A list of permissions granted to the user.
### Headers
#### Response Headers
- **x-csrf-token** (string) - A token that must be sent in subsequent POST requests.
```
--------------------------------
### Configure Azure Blob Storage
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Sample configuration for Azure Blob Storage, including account name, key, and container name. The BlobRestProxy client is used to create the adapter.
```default
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
$accountName = 'your_storage_account_name';
$accountKey = '123456';
$containerName = 'my_container';
$client = \MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobService(
"DefaultEndpointsProtocol=https;AccountName=${accountName};AccountKey=${accountKey};"
);
return new \League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter($client, $containerName);
},
],
],
],
```
--------------------------------
### Configure Session Options (e.g., Cookie Lifetime)
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/sessions.md
Demonstrates how to pass options to the NativeSessionStorage constructor, such as extending the cookie lifetime to one year.
```php
'Filebrowser\Services\Session\SessionStorageInterface' => [
'handler' => '\Filebrowser\Services\Session\Adapters\SessionStorage',
'config' => [
'handler' => function () {
$handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler(
'mysql://root:password@localhost:3306/filebrowser'
);
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([
'cookie_lifetime' => 365 * 24 * 60 * 60, // one year
], $handler);
},
],
],
```
--------------------------------
### Compile and Hot Reload Application
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/development.md
Launches the backend on port 8081 and the frontend on port 8080 for development with hot reloading. Visit http://localhost:8080 in your browser.
```bash
npm run serve
```
--------------------------------
### Configure FTP Storage Adapter
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
PHP configuration for using an FTP server as the storage backend. Specify connection details such as host, username, password, port, and timeout.
```php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
return new \League\Flysystem\Adapter\Ftp([
'host' => 'example.com',
'username' => 'demo',
'password' => 'password',
'port' => 21,
'timeout' => 10,
]);
},
],
],
],
```
--------------------------------
### Configure Frontend Application Settings
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration_basic.md
Customize core application settings such as name, version, language, logo, upload limits, and file editing permissions. Ensure correct syntax to avoid application load failures.
```php
'frontend_config' => [
'app_name' => 'FileBrowser',
'app_version' => APP_VERSION,
'language' => 'english',
'logo' => 'https://linuxforphp.com/img/logo.svg',
'upload_max_size' => 100 * 1024 * 1024, // 100MB
'upload_chunk_size' => 1 * 1024 * 1024, // 1MB
'upload_simultaneous' => 3,
'default_archive_name' => 'archive.zip',
'editable' => ['.txt', '.css', '.js', '.ts', '.html', '.php', '.json', '.ini', '.cnf', '.conf', '.env', '.monthly', '.weekly', '.daily', '.hourly', '.minute', '.htaccess'],
'date_format' => 'YY/MM/DD hh:mm:ss', // see: https://momentjs.com/docs/#/displaying/format/
'guest_redirection' => '', // useful for external auth adapters
'search_simultaneous' => 5,
'filter_entries' => [],
]
```
--------------------------------
### Configure DigitalOcean Spaces Storage
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/storage.md
Sample configuration for DigitalOcean Spaces, specifying credentials, region, endpoint, and bucket name. The adapter is created using a factory function.
```default
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
$client = new \Aws\S3\S3Client([
'credentials' => [
'key' => '123456',
'secret' => 'secret123456',
],
'region' => 'us-east-1',
'version' => 'latest',
'endpoint' => 'https://nyc3.digitaloceanspaces.com',
]);
return new \League\Flysystem\AwsS3v3\AwsS3Adapter($client, 'my-bucket-name');
},
],
],
],
```
--------------------------------
### Batch Download Files
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Initiates a batch download, zipping selected items on the server-side. Items are specified in the request body.
```bash
# Start a batch download (zips selected items server-side)
curl -b cookies.txt "http://example.com/?r=/batchdownload" \
-H "x-csrf-token: TOKEN" \
-d 'items[0][name]=report.pdf&items[0][type]=file&items[1][name]=notes.txt&items[1][type]=file'
```
--------------------------------
### Configure Local Disk Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
PHP configuration for the default local disk storage adapter. The `fastzip` option enables native zip/unzip binaries for improved performance.
```php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
return new \League\Flysystem\Adapter\Local(REPOSITORY_ROOT);
},
],
'fastzip' => true, // LOCAL ONLY — uses zip/unzip binaries directly
],
],
```
--------------------------------
### Configure LDAP Auth
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/auth.md
Set up LDAP authentication by providing server details, bind credentials, base DN, and attribute mappings.
```php
'Filebrowser\Services\Auth\AuthInterface' => [
'handler' => '\Filebrowser\Services\Auth\Adapters\LDAP',
'config' => [
'private_repos' => false,
'ldap_server'=>'ldap://192.168.1.1',
'ldap_bindDN'=>'uid=ldapbinduser,cn=users,dc=ldap,dc=example,dc=com',
'ldap_bindPass'=>'ldapbinduser-password',
'ldap_baseDN'=>'cn=users,dc=ldap,dc=example,dc=com',
'ldap_filter'=>'(uid=*)', //ex: 'ldap_filter'=>'(&(uid=*)(memberOf=cn=administrators,cn=groups,dc=ldap,dc=example,dc=com))',
'ldap_attributes' => ["uid","cn","dn"],
'ldap_userFieldMapping'=> [
'username' =>'uid',
'name' =>'cn',
'userDN' =>'dn',
'default_permissions' => 'read|write|upload|download|batchdownload|zip',
'admin_usernames' =>['user1', 'user2'],
],
],
],
```
--------------------------------
### Configure Temporary File System Service
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Configures the temporary file system for assembling chunks and archives. Useful for multi-node deployments requiring shared storage. Includes settings for garbage collection.
```php
// configuration.php
'Filebrowser\Services\Tmpfs\TmpfsInterface' => [
'handler' => '\Filebrowser\Services\Tmpfs\Adapters\Tmpfs',
'config' => [
'path' => __DIR__.'/private/tmp/',
'gc_probability_perc' => 10, // 10% chance of GC per request
'gc_older_than' => 60 * 60 * 24 * 2, // clean up files older than 2 days
],
],
```
--------------------------------
### Run End-to-End Tests
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Initiate the end-to-end testing suite using Cypress via the npm script. This verifies the application's behavior from a user's perspective.
```bash
# End-to-end tests (Cypress)
npm run e2e
```
--------------------------------
### Configure SFTP Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Configure the SFTP adapter in your application's storage settings. Ensure all connection details are correct.
```php
// configuration.php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
return new \League\Flysystem\Sftp\SftpAdapter([
'host' => 'example.com',
'port' => 22,
'username' => 'demo',
'password' => 'password',
'timeout' => 10,
]);
},
],
],
],
```
--------------------------------
### Configure PDO Database Session Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Sets up File Browser to use PDO for database session storage. Ensure the database connection string is correct and the 'sessions' table exists.
```php
// configuration.php
'Filebrowser\Services\Session\SessionStorageInterface' => [
'handler' => '\Filebrowser\Services\Session\Adapters\SessionStorage',
'config' => [
'handler' => function () {
$handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler(
'mysql://root:password@localhost:3306/filebrowser'
);
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([
'cookie_lifetime' => 365 * 24 * 60 * 60, // one year
], $handler);
},
],
],
```
--------------------------------
### Configure Redis Session Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Sets up File Browser to use Redis for session storage. Ensure the Redis client connection details are correct.
```php
// configuration.php
'Filebrowser\Services\Session\SessionStorageInterface' => [
'handler' => '\Filebrowser\Services\Session\Adapters\SessionStorage',
'config' => [
'handler' => function () {
$predis = new \Predis\Client('tcp://127.0.0.1:6379');
$handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler($predis);
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler);
},
],
],
```
--------------------------------
### Configure Security (CSRF + IP Lists)
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Enables CSRF protection and configures IP allow/deny lists for enhanced security. Remember to randomize the 'csrf_key' in production.
```php
// configuration.php
'Filebrowser\Services\Security\Security' => [
'handler' => '\Filebrowser\Services\Security\Security',
'config' => [
'csrf_protection' => true,
'csrf_key' => 'RANDOMIZE_THIS_STRING', // must be randomized in production
'ip_allowlist' => [], // if non-empty, ONLY these IPs may access the app
'ip_denylist' => [
'172.16.1.2',
'172.16.3.4',
],
],
],
```
--------------------------------
### Configure Dropbox Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Configure the Dropbox adapter. Provide your Dropbox API token. The 'case_sensitive' option can be set in the config.
```php
// configuration.php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => ['case_sensitive' => false],
'adapter' => function () {
$client = new \Spatie\Dropbox\Client('YOUR_DROPBOX_TOKEN');
return new \Spatie\FlysystemDropbox\DropboxAdapter($client);
},
],
],
],
```
--------------------------------
### Configure MySQL Database Auth
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/auth.md
Update your configuration file to use the database authentication handler. Provide your MySQL connection details.
```php
'Filebrowser\Services\Auth\AuthInterface' => [
'handler' => '\Filebrowser\Services\Auth\Adapters\Database',
'config' => [
'driver' => 'mysqli',
'host' => 'localhost',
'username' => 'root',
'password' => 'password',
'database' => 'filebrowser',
],
],
```
--------------------------------
### FileBrowser Frontend Configuration
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Configures frontend settings for FileBrowser, including application name, version, language, upload limits, and date format. Adjust 'upload_max_size' and 'upload_chunk_size' based on server capabilities and user needs.
```php
// configuration.php
'frontend_config' => [
'app_name' => 'FileBrowser',
'app_version' => APP_VERSION,
'language' => 'english', // see Translations section for available locales
'logo' => 'https://linuxforphp.com/img/logo.svg',
'upload_max_size' => 100 * 1024 * 1024, // 100 MB per file
'upload_chunk_size' => 1 * 1024 * 1024, // 1 MB per chunk
'upload_simultaneous' => 3, // parallel chunk uploads
'default_archive_name' => 'archive.zip',
'editable' => ['.txt', '.css', '.js', '.ts', '.html', '.php', '.json', '.ini', '.env', '.htaccess'],
'date_format' => 'YY/MM/DD hh:mm:ss', // momentjs format
'guest_redirection' => '', // redirect logged-out users (e.g. WordPress login URL)
'search_simultaneous' => 5,
'filter_entries' => [], // hide specific file/folder names from listing
],
// Top-level options
'overwrite_on_upload' => false,
'timezone' => 'UTC',
'download_inline' => ['pdf'], // open in browser instead of downloading
```
--------------------------------
### Configure MySQL Authentication
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
PHP configuration for using MySQL as the authentication backend. Specify database connection details.
```php
'Filebrowser\Services\Auth\AuthInterface' => [
'handler' => '\Filebrowser\Services\Auth\Adapters\Database',
'config' => [
'driver' => 'mysqli',
'host' => 'localhost',
'username' => 'root',
'password' => 'password',
'database' => 'filebrowser',
],
],
```
--------------------------------
### Batch Download
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Initiates a batch download, zipping selected items server-side. Requires a CSRF token.
```APIDOC
## POST /batchdownload
### Description
Initiates a batch download, zipping selected items server-side.
### Method
POST
### Endpoint
http://example.com/?r=/batchdownload
### Headers
- x-csrf-token: TOKEN
### Request Body
- **items** (array) - Required - An array of objects, each specifying the name and type of item to include in the download.
- **name** (string) - Required - The name of the item.
- **type** (string) - Required - The type of the item (e.g., "file", "dir").
### Request Example
```bash
curl -b cookies.txt "http://example.com/?r=/batchdownload" \
-H "x-csrf-token: TOKEN" \
-d 'items[0][name]=report.pdf&items[0][type]=file&items[1][name]=notes.txt&items[1][type]=file'
```
```
--------------------------------
### Create New File or Folder
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Creates a new file or directory at the specified destination. Requires a CSRF token.
```APIDOC
## POST /createnew
### Description
Creates a new file or directory at the specified destination.
### Method
POST
### Endpoint
http://example.com/?r=/createnew
### Headers
- Content-Type: application/json
- x-csrf-token: TOKEN
### Request Body
- **type** (string) - Required - The type of item to create, either "file" or "dir".
- **name** (string) - Required - The name of the new file or folder.
- **destination** (string) - Required - The path to the directory where the new item will be created.
### Request Example
```bash
curl -b cookies.txt -X POST "http://example.com/?r=/createnew" \
-H "Content-Type: application/json" \
-H "x-csrf-token: TOKEN" \
-d '{"type": "file", "name": "notes.txt", "destination": "/documents"}'
```
```
--------------------------------
### Configure WordPress Auth
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/auth.md
Integrate FileBrowser with WordPress for authentication. Specify the WordPress directory and user permissions.
```php
'Filebrowser\Services\Auth\AuthInterface' => [
'handler' => '\Filebrowser\Services\Auth\Adapters\WPAuth',
'config' => [
'wp_dir' => '/var/www/my_wordpress_site/',
'permissions' => ['read', 'write', 'upload', 'download', 'batchdownload', 'zip'],
'private_repos' => false,
],
],
```
--------------------------------
### Create New File or Folder
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Creates a new file or folder within a specified destination directory. The 'type' parameter can be either 'file' or 'dir'.
```bash
# Create new file or folder
curl -b cookies.txt -X POST "http://example.com/?r=/createnew" \
-H "Content-Type: application/json" \
-H "x-csrf-token: TOKEN" \
-d '{"type": "file", "name": "notes.txt", "destination": "/documents"}'
# type can be "file" or "dir"
```
--------------------------------
### Configure File Session Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Sets up File Browser to use PHP's native file session handler. Configure the save path for session files.
```php
// configuration.php
'Filebrowser\Services\Session\SessionStorageInterface' => [
'handler' => '\Filebrowser\Services\Session\Adapters\SessionStorage',
'config' => [
'handler' => function () {
$save_path = null; // use system default, or set e.g. __DIR__.'/private/sessions'
$handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler($save_path);
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler);
},
],
],
```
--------------------------------
### Create User
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Creates a new user account. This endpoint is admin-only and requires a CSRF token.
```APIDOC
## POST /storeuser
### Description
Creates a new user account. This endpoint is admin-only.
### Method
POST
### Endpoint
http://example.com/?r=/storeuser
### Headers
- Content-Type: application/json
- x-csrf-token: TOKEN
### Request Body
- **username** (string) - Required - The username for the new account.
- **name** (string) - Required - The full name of the user.
- **role** (string) - Required - The role of the user (e.g., "user", "admin").
- **homedir** (string) - Required - The default home directory for the user.
- **password** (string) - Required - The password for the new account.
- **permissions** (array) - Optional - A list of permissions granted to the user.
### Request Example
```bash
curl -b cookies.txt -X POST "http://example.com/?r=/storeuser" \
-H "Content-Type: application/json" \
-H "x-csrf-token: TOKEN" \
-d '{
"username": "jdoe",
"name": "Jane Doe",
"role": "user",
"homedir": "/teams/marketing",
"password": "SecurePass1!",
"permissions": ["read", "upload", "download"]
}'
```
```
--------------------------------
### List All Users
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Retrieves a list of all users in the system. This endpoint is restricted to administrators.
```bash
# List all users
curl -b cookies.txt "http://example.com/?r=/listusers" \
-H "x-csrf-token: TOKEN"
```
--------------------------------
### Define Custom Routes in PHP
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Add new routes to `config/routes.optional.config.php` to define custom HTTP methods, paths, controller actions, roles, and permissions.
```php
// config/routes.optional.config.php
return [
[
'route' => [
'GET', '/download/{path_encoded}', '\Filebrowser\Controllers\DownloadController@download',
],
'roles' => [
'guest', 'user', 'admin',
],
'permissions' => [
'download',
],
],
// Add your own custom route:
[
'route' => [
'POST', '/myaction', '\App\Controllers\MyController@handle',
],
'roles' => ['admin'],
'permissions' => ['write'],
],
];
```
--------------------------------
### Configure DigitalOcean Spaces Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Configure the DigitalOcean Spaces adapter, which is S3-compatible. An endpoint override is required. Replace placeholders with your credentials and bucket name.
```php
// configuration.php — DO Spaces is S3-compatible; add endpoint override
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
$client = new \Aws\S3\S3Client([
'credentials' => [
'key' => 'YOUR_SPACES_KEY',
'secret' => 'YOUR_SPACES_SECRET',
],
'region' => 'us-east-1',
'version' => 'latest',
'endpoint' => 'https://nyc3.digitaloceanspaces.com',
]);
return new \League\Flysystem\AwsS3v3\AwsS3Adapter($client, 'my-bucket-name');
},
],
],
],
```
--------------------------------
### Configure Azure Blob Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Configure the Azure Blob Storage adapter. Replace placeholders with your storage account name, key, and container name. Ensure the connection string is correctly formatted.
```php
// configuration.php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
$accountName = 'your_storage_account_name';
$accountKey = 'YOUR_AZURE_KEY';
$containerName = 'my_container';
$client = \MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobService(
"DefaultEndpointsProtocol=https;AccountName={$accountName};AccountKey={$accountKey};"
);
return new \League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter($client, $containerName);
},
],
],
],
```
--------------------------------
### Create Users Table for Database Auth
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/auth.md
SQL query to create the 'users' table required for database authentication. This table stores user credentials and permissions.
```sql
CREATE TABLE `users` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`role` varchar(20) NOT NULL,
`permissions` varchar(200) NOT NULL,
`homedir` varchar(2000) NOT NULL,
`password` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `username` (`username`)
) CHARSET=utf8 COLLATE=utf8_bin;
```
--------------------------------
### Configure Default Logger Service
Source: https://github.com/linuxforphp/filebrowser/blob/master/docs/configuration/logging.md
This configuration sets up the default logger service to use Monolog and write logs to 'private/logs/app.log'. It specifies the handler and configuration for Monolog.
```php
'Filebrowser\Services\Logger\LoggerInterface' => [
'handler' => '\Filebrowser\Services\Logger\Adapters\MonoLogger',
'config' => [
'monolog_handlers' => [
function () {
return new \Monolog\Handler\StreamHandler(
__DIR__.'/private/logs/app.log',
\Monolog\Logger::DEBUG
);
},
],
],
],
```
--------------------------------
### List Directory Contents
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Lists the contents of a specified directory. The response includes details about files and subdirectories.
```bash
# List directory contents
curl -b cookies.txt -X POST "http://example.com/?r=/getdir" \
-H "Content-Type: application/json" \
-H "x-csrf-token: TOKEN" \
-d '{"dir": "/"}'
# Response: {"status":"success","data":[{"name":"documents","type":"dir","size":0,...}, ...]}
```
--------------------------------
### Lint Frontend Code
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Execute the frontend linting process using the npm script. This checks for code style and potential errors in the frontend codebase.
```bash
# Frontend lint
npm run lint
```
--------------------------------
### Perform PHP Static Analysis
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Run PHP static analysis on the backend code using PHPStan. This helps identify potential errors and improve code quality.
```bash
# PHP static analysis
vendor/bin/phpstan analyse ./backend
```
--------------------------------
### Configure Amazon S3 (v3) Storage
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Configure the Amazon S3 v3 adapter. Replace placeholders with your AWS credentials and bucket name. Ensure the 'version' is set to 'latest'.
```php
// configuration.php
'storage' => [
'driver' => [
'config' => [
'separator' => '/',
'config' => [],
'adapter' => function () {
$client = new \Aws\S3\S3Client([
'credentials' => [
'key' => 'YOUR_AWS_KEY',
'secret' => 'YOUR_AWS_SECRET',
],
'region' => 'us-east-1',
'version' => 'latest',
]);
return new \League\Flysystem\AwsS3v3\AwsS3Adapter($client, 'my-bucket-name');
},
],
],
],
```
--------------------------------
### List Users
Source: https://context7.com/linuxforphp/filebrowser/llms.txt
Lists all users on the system. This endpoint is admin-only and requires a CSRF token.
```APIDOC
## GET /listusers
### Description
Lists all users on the system. This endpoint is admin-only.
### Method
GET
### Endpoint
http://example.com/?r=/listusers
### Headers
- x-csrf-token: TOKEN
### Request Example
```bash
curl -b cookies.txt "http://example.com/?r=/listusers" \
-H "x-csrf-token: TOKEN"
```
```