Skip to content

Uguu Configuration & Installation

Go Johansson (neku) edited this page Aug 2, 2023 · 37 revisions

Information

For submitting issues visit Uguu on Github.

This page contains documentation about Uguu V1.7.4. If you want instructions on how to install the Docker version of Uguu click here instead.

Requirements

Software

  • Debian 11 or newer
  • Nginx
  • PHP/PHP-FPM-8.1 or newer (if PHP8.1 is missing you can install it by following this this guide).
  • Git
  • SQLite3 (also supports MySQL & PostgreSQL)
  • NodeJS & NPM

Installation

Packages

Start off by installing the following packages:

apt-get install build-essential nginx-full php8.1-fpm php8.1 sqlite3 php8.1-sqlite3 \
php8.1-curl nodejs npm git php8.1-cli php8.1-lz4 \
php8.1-mcrypt php8.1-mysql php8.1-xdebug php8.1-zip \
php8.1-common php8.1-readline php8.1-bcmath php8.1-common php8.1-xml

Domain and SSL certificate

We will not cover how to obtain and setup a domain and certificate. However I'd recommend buying a domain on a website like Dynadot and get SSL certificates using Acme.sh.

Paths

Assuming you are using the following paths for various things, if they don't exist you should create them.

mkdir /var/www
mkdir /var/www/uguu
mkdir /var/www/db
mkdir /var/www/files
  • Uguu: /var/www/uguu
  • Uploaded files: /var/www/files
  • Database: /var/www/db

Download Uguu, setup the database and set permissions

Run this command to clone the Uguu Github and move the files to the correct folders, or do it yourself (I don't care).

cd /var/www/uguu/
git clone https://github.com/nokonoko/Uguu .

Now let's setup the database, run this command:

sqlite3 /var/www/db/uguu.sq3 -init /var/www/uguu/src/static/dbSchemas/sqlite_schema.sql ""

Then set the correct permissions so Nginx, PHP and SQLite can do their thing.

chown www-data:www-data /var/www/db
chown www-data:www-data /var/www/db/uguu.sq3
chown www-data:www-data /var/www/files
chmod -R 775 /var/www

Setup deletion scripts

These scripts checks the age of the files and in the database and deletes them if they are older then 24 hours. They however only work if you're using SQLite as the database, you may make your own scripts for MySQL/Postgres or look into using MySQL's event scheduler or a plugin for Postgres called pg_cron.

If you want to host files for longer you will need to edit hours=$((XXX*60)) replace XXX with hours in expire time, and datetime('now', '-XXX hours') replace XXX with hours in expire time.

If you want files to expire you will need to do the following:

  1. Make the scripts executable:
chmod a+x /var/www/uguu/src/static/scripts/checkdb.sh
chmod a+x /var/www/uguu/src/static/scripts/checkfiles.sh
  1. Edit /var/www/uguu/checkdb.sh and replace /path/to/db/uguu.sq3 with /var/www/db/uguu.sq3
  2. Edit /var/www/uguu/checkfiles.sh and replace /path/to/files/ with /var/www/uguu/files/
  3. Add the scripts to run via crontab (crontab -e) as root or www-data. Enter the following into crontab:
0,30 * * * * bash /var/www/uguu/src/static/scripts/checkfiles.sh
0,30 * * * * bash /var/www/uguu/src/static/scripts/checkdb.sh

Nginx example configuration

We won't cover settings everything up, here are some Nginx examples.

Main Domain

server {
    listen            443 ssl http2;
    server_name       www.yourdomain.com yourdomain.com;

    ssl on;
    ssl_certificate   /path/to/fullchain.pem;
    ssl_certificate_key /path/to/privkey.pem;
    ssl_protocols     TLSv1.2 TLSv1.3;
    ssl_ciphers       'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_ecdh_curve    secp384r1;  

    root              /path/to/uguu/dist/public/;
    autoindex         off;
    access_log        off;
    index index.html  index.php;  

    location ~* \.(css|js|jpg|jpeg|gif|png|ico|xml|eot|woff|woff2|ttf|svg|otf|x-icon|avif|webp|apng)$ {
      expires         30d;
    }

    gzip              on;
    gzip_min_length   1000;
    gzip_comp_level   6;
    gzip_proxied      any;
    gzip_types        text/css text/js text/javascript application/javascript application/x-javascript;

    location ~* \.php$ {
    fastcgi_pass     unix:/var/run/php/php8.1-fpm.sock;
    fastcgi_intercept_errors on;
    fastcgi_index    index.php;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    include          fastcgi_params;
    fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
server {
    listen           80;
    server_name      www.domain.com domain.com;
    return 301       https://domain.com$request_uri;
  }

Subdomain serving uploaded files (do not enable PHP here)

server {
    listen           443 ssl;
    server_name      www.subdomain.serveryourfiles.com subdomain.serveryourfiles.com;

    ssl              on;
    ssl_certificate  /path/to/fullchain.pem;
    ssl_certificate_key /path/to/privkey.pem;
    ssl_protocols    TLSv1.2 TLSv1.3;
    ssl_ciphers      'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_ecdh_curve   secp384r1;

    root             /var/www/files/;
    autoindex        off;
    access_log       off;
    index            index.html;
  }
server {
    listen           80;
    server_name      www.subdomain.serveryourfiles.com subdomain.serveryourfiles.com;
    return 301       https://subdomain.serveryourfiles.com$request_uri;
  }  

Serve everything off one domain (no subdomain for files)

server {
    listen           443 ssl;
    server_name      www.yourdomain.com yourdomain.com;
    ssl              on;
    ssl_certificate  /path/to/fullchain.pem;
    ssl_certificate_key /path/to/privkey.pem;
    ssl_protocols    TLSv1.2 TLSv1.3;
    ssl_ciphers      'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_ecdh_curve   secp384r1;

    root             /var/www/uguu/dist/public/;
    autoindex        off;
    access_log       off;
    index index.html index.php;

    location ~* \.(css|js|jpg|jpeg|gif|png|ico|xml|eot|woff|woff2|ttf|svg|otf|x-icon|avif|webp|apng)$ {
    expires          30d;
    }

    location ^~ /files/ {
     alias           /var/www/files/;
     index           index.html index.htm;
     autoindex       off;
     include         mime.types;
     types {
      text/plain     php;
    }
  }

    gzip             on;
    gzip_min_length  1000;
    gzip_comp_level  6;
    gzip_proxied     any;
    gzip_types       text/css text/js text/javascript application/javascript application/x-javascript;

    location ~* \.php$ {
    fastcgi_pass     unix:/var/run/php/php8.1-fpm.sock;
    fastcgi_intercept_errors on;
    fastcgi_index    index.php;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    include          fastcgi_params;
    fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
  }
server {
    listen           80;
    server_name      www.domain.com domain.com;
    return 301       https://domain.com$request_uri;
  }  

General Nginx configuration

You will need to increase client_max_body_size in nginx.conf to the max file upload size (e.g 128M which is the same as 128MB).

PHP-FPM Configuration

Edit /etc/php/8.1/fpm/php.ini and change the settings post_max_size, note that this value must be higher then upload_max_filesize. So for example 256M and 128M.

No further configuration should be needed for PHP unless you want to enable e.g OPCache. I will not cover that at this time.

Restarting services

Now we just need to restart some services in order to load the new configuration.

service nginx restart
service php8.1-fpm restart

Uguu Configuration and installation

Ejs Templates

You may edit the files inside src/templates to your liking.

config.json

This configuration file contains settings for the site, do not remove or move it.

It should be located at /var/www/uguu/src/config.json

  • pages what pages to compile from the templates.
  • DEBUG shows errors beyond the "servers error" message, should only be enabled for debugging and not in production.
  • max_upload_size default is 128, the max file size which an user can upload in MB. Be sure this matches the PHP/Nginx configuration.
  • expireTime e.g 24 (as in 24 hours), set this to match your expire time.
  • siteName the name of your site, e.g SuperKawaiiHost. This will appear in the browser title and on several places on the website. If you changed the expire time remember to change that here as well.
  • subTitle site subtitle.
  • DOMAIN the URL to your site e.g SuperKawaiiHost.com
  • FILE_DOMAIN the URL of the subdomain serving the uploaded files, e.g a.superkawaiihost.com.
  • abuseContact the email dedicated to receive abuse reports, this can be the same as infoContact if you want. Make sure it's a valid email or else you run the risk of getting into trouble from your server provider.
  • infoContact the email dedicated to receive general email from users.
  • ServerCountryLocation the country your server is located in, this is related to abuse/DMCA since it often depends on local laws.
  • SiteMetaInfo a description of your site, search engines show this data in searches for your site.
  • ToolsDesc some text added to the tools page to inform users about the need to modify the existing tools. You can change this to whatever you want.
  • donationBanner true/false depending if you want to compile the donation banner.
  • paypalUrl the URL to your Paypal donation page. This can be ignored if the donations banner isn't enabled, or if you don't want to enable that method of donating.
  • bitcoinAddress your BTC address for donations. This can be ignored if the donations banner isn't enabled. or if you don't want to enable that method of donating.
  • flattrUrl your Flattr donation URL. This can be ignored if the donations banner isn't enabled. or if you don't want to enable that method of donating.
  • kofiUrl your Ko-Fi donation URL. This can be ignored if the donations banner isn't enabled. or if you don't want to enable that method of donating.
  • malwareBanner true/false depending if you want to compile the malware banner.
  • DB_MODE set this to sqlite, mysql or pgsql depending on the database you're gonna use.
  • DB_PATH path to your database e.g /var/www/db/uguu.sq3 (SQLite), unix_socket=/var/run/mysqld/mysqld.sock;dbname=uguu (MySQL) or host=DBHOST;port=5432;dbname=uguu (Postgres)
  • DB_USER leave this as NULL if you are using SQLite.
  • DB_PASS leave this as NULL if you are using SQLite.
  • LOG_IP default is false seeing as Uguu is made to be privacy aware, if you want you can turn this on and the IP of the uploaded file will be stored in the database.
  • ANTI_DUPE default is false, if enabled a file already uploaded won't be uploaded again and instead the existing file url will be returned.
  • BLACKLIST_DB true/false depending if you want to activate file blacklist filtering.
  • FILTER_MODE default is true and recommended so extension and MIME blocking is active.
  • RATE_LIMIT true/false for upload rate limit.
  • RATE_LIMIT_TIMEOUT in seconds for rate limit timeout, e.g 60.
  • RATE_LIMIT_FILES max files allowed to be uploaded within that rate limit timeout, e.g 100.
  • FILES_ROOT the location where uploaded files are to be stored, change this to /var/www/files/.
  • FILES_RETRIES maximum number of tries to regenerate filename in case an existing one already exists, this is highly unlikely and even if it does 15 tries is more than enough.
  • NAME_LENGTH the length of the new filename, default is 8, this can be increased or decreased however setting too low makes it easier to brute force a list of uploaded files or increases the chances of the filename already existing in the database.
  • ID_CHARSET the characters that will be used to randomly generate a new filename, just leave this as it is.
  • BLOCKED_EXTENSIONS is a list of the blocked file extensions, these can not be uploaded. It's recommended to keep the defaults since they are commonly used by malicious actors to spread malware via file sharing services. You may remove or add extensions to this list.
  • BLOCKED_MIME this is a list of blocked MIME types, a MIME identifies what kind of format a file is since you can save an executable file as a .jpg, it's recommended that blocked extensions match MIME types. You may remove or add MIME types to this list.

Compilation

Now we just need to compile the files using our configuration, the output will be in /var/www/uguu/dist/

Simply run:

cd /var/www/uguu/
npm install
make
make install

Finish

Uguu should now be up and running!

Clone this wiki locally