Filebrowser is a file manager that is free and open source. It provides all the functionalities expected from any file manager such as copying, moving, deleting, and renaming files and directories. Moreover, it provides an authentication and authorization system where you can manage users and their roles. Based on the official Filebrowser GitHub repository, it was built using Go which is a very secure and high-performance programming language.
In this guide, I will show you how to install Filebrowser on Ubuntu and serve it with Nginx.
Prerequisites
For this guide, we need to have curl
installed. If not, then follow the instructions below.
You can simply check if it’s installed using this command.
curl --version
If you get an output showing the curl version, skip to the next step. If, however, you get an error run the next two commands.
We will start by updating the server packages information using this command:
sudo apt update
And then use this command to install it.
sudo apt install curl
Download & Install File Browser
Execute the following command to download and auto-install FileBrowser
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
To verify that it is installed, try executing this command:
filebrowser version
If the message shows you the version, then you are all good.
Configure Filebrowser to Run as a Service
To make it easier to start and stop Filebrowser, we need to create a system configuration so that it can run as a service in the background.
Create the filebrowser.service
which tells the OS how to start the service. Use the following command.
sudo nano /etc/systemd/system/filebrowser.service
And copy the following content then paste it inside it.
[Unit]
Description=File browser: %I
After=network.target
[Service]
User=www-data
Group=www-data
ExecStart=/usr/local/bin/filebrowser -c /etc/filebrowser/default.json
[Install]
WantedBy=multi-user.target
Save and Exit by clicking CTRL+X
, Y
then Enter
.
In the above file, we supplied the /etc/filebrowser/default.json
to the file browser when the service started. But this file does not exist so let’s create it.
Create File Browser Configuration Files
First, let’s create the file browser configuration directory /etc/filebrowser/
sudo mkdir /etc/filebrowser
Next, Create the default.json file
sudo nano /etc/filebrowser/default.json
Copy the following JSON to the file:
{
"port": 8080,
"baseURL": "",
"address": "",
"log": "stdout",
"database": "/etc/filebrowser/filebrowser.db",
"root": "/path/to/your/files"
}
Save and exit
Note: Replace /path/to/your/files
with the root of the directory that you want the file browser to start from as its root directory.
Now, you want to create the filebrowser.db
file. Run the following command:
filebrowser -d /etc/filebrowser/filebrowser.db
Note that this will run the file browser you can just exit it by clicking CTRL+C.
Set correct permissions for the database.
sudo chown -R www-data:www-data /etc/filebrowser/filebrowser.db
Start the File browser as a Service
First, you execute the following command to make the file browser start at system boot, so you do not have to start it every time you reboot the server.
sudo systemctl enable filebrowser
Now you can start it simply by running this command from anywhere.
sudo service filebrowser start
Or
sudo systemctl start filebrowser
Verify that it is running by executing the following command.
sudo service filebrowser status
Or
sudo systemctl status filebrowser
You should see something like this.
● filebrowser.service - File browser:
Loaded: loaded (/etc/systemd/system/filebrowser.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-04-05 17:58:12 UTC; 9min ago
Main PID: 21246 (filebrowser)
Tasks: 5 (limit: 2338)
Memory: 1.8M
CGroup: /system.slice/filebrowser.service
└─21246 /usr/local/bin/filebrowser -c /etc/filebrowser/default.json
Apr 05 17:58:12 lemp42onubuntu2004-c-4-8gib-fra1-01 systemd[1]: Started File browser: .
Apr 05 17:58:12 lemp42onubuntu2004-c-4-8gib-fra1-01 filebrowser[21246]: 2023/04/05 17:58:12 Using config file: /etc/filebrowser/default.json
Apr 05 17:58:12 lemp42onubuntu2004-c-4-8gib-fra1-01 filebrowser[21246]: 2023/04/05 17:58:12 Listening on [::]:8080
Apr 05 17:58:15 lemp42onubuntu2004-c-4-8gib-fra1-01 filebrowser[21246]: 2023/04/05 17:58:15 /api/renew: 401 127.0.0.1 <nil>
Apr 05 18:00:34 lemp42onubuntu2004-c-4-8gib-fra1-01 filebrowser[21246]: 2023/04/05 18:00:34 /api/renew: 401 127.0.0.1 <nil>
Install and Setup Nginx
If you already have Nginx installed, skip this step. Install Nginx using the following command.
sudo apt install nginx
Next, remove the default Nginx Configuration to prevent any conflict:
sudo rm /etc/nginx/sites-available/default
sudo rm /etc/nginx/sites-enabled/default
Create a new Nginx configuration file. I like to name my configuration file with the domain name.
Assuming I will host the file browser at my subdomain files.codinginsideout.com
sudo nano /etc/nginx/sites-available/files.codinginsideout.com
Paste the following code in the nano editor.
server {
listen [::]:80;
listen 80;
# TODO: replace files.codinginsideout.com with your domain/subdomain
server_name files.codinginsideout.com;
client_max_body_size 48M;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
You can set client_max_body_size
to any value you want. It will limit the max file size you can upload to the server.
Save the file and exit.
You need to enable your Nginx configuration file by creating a symbolic link on the /etc/nginx/sites-enabled
directory.
sudo ln -s /etc/nginx/sites-available/files.codinginsideout.com /etc/nginx/sites-enabled/files.codinginsideout.com
Finally, check your nginx configuration files.
sudo nginx -t
You should see something like this.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If so restart nginx.
sudo service nginx restart
Great work so far! You can now visit your subdomain/domain to access the file browser. It will ask you to login in. These are the default credentials.
user: admin pass: admin
Secure your Connection to the File Browser
This step is optional but highly recommended. Now you can only access your file browser with HTTP which is not secure and is vulnerable to a man-in-the-middle attack.
Let’s enable HTTPS using Let’s Encrypt It which is completely free!
Let’s first install certbot which will help us manage our Let’s Encrypt It SSL certificate.
sudo apt install certbot python3-certbot-nginx
Now run the following command and you’re good to go.
sudo certbot --nginx --redirect --no-eff-email --agree-tos -m [email protected] -d files.codinginsideout.com
Replace files.codinginsideout.com
with your domain/subdomain and [email protected]
with your email
Conclusion
We have installed the Filebrowser and we learned how to start it as a service and how to serve it using Nginx reverse proxy on Ubuntu
In case you face any issues, please let me know in the comments and I will be glad to help.
Thank you so much it worked like charm!
thank you very much