Information

This page contains documentation about Uguu V1.7.2. 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
  • Certbot

Installation

Packages

We will 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 certbot 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

You will need a domain for the front page and uploading and a subdomain to serve this files. e.g SuperKawaiiihost.com and a.SuperKawaiiihost.com.

Use Letsencrypt to obain a SSL cert.

Paths

We are 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/uguu/dist
mkdir /var/www/db
mkdir /var/www/files
  • Uguu: /var/www/uguu
  • Uguu compiled: /var/www/uguu/dist
  • 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 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.

However this is not needed for a default installation.

If you want files to expire follow these steps:

chmod a+x /var/www/uguu/src/static/scripts/checkdb.sh
chmod a+x /var/www/uguu/src/static/scripts/checkfiles.sh

Edit /var/www/uguu/checkdb.sh and replace /path/to/db/uguu.sq3 with /var/www/db/uguu.sq3.

Edit /var/www/uguu/checkfiles.sh and replace /path/to/files/ with /var/www/uguu/files/.

Then add them to your crontab (crontab -e) as root, or as www-data!:

0,30 * * * * bash /var/www/uguu/src/static/scripts/checkfiles.sh
0,30 * * * * bash /var/www/uguu/src/static/scripts/checkdb.sh

Nginx example config

I 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;
    }
}

Subdomain serving 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;
  }

To redirect HTTP to HTTPS make a config for each domain like so:

server {
    listen           80;
    server_name      www.domain.com domain.com;
    return 301       https://domain.com$request_uri;
  }

If you are running everything from one domain use something like this:

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;
    }
  }

Also change client_max_body_size in nginx.conf to the the max file upload size, e.g 128M (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.

/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

Finishing up and troubleshooting

Navigate to your domain, if it all looks correct and works it's all good in the hood and you're done. However if something isn't working you can change the DEBUG flag to true in your config to get a bit more detailed errors, remember to set it back to false after you're done.

Blank page or 404/403 error

  • Check permissions, make sure www-data (Nginx) can read the directories and files in /var/www/.
  • Check your Nginx configuration and make sure they are correct.

Compilation errors

  • Did you install NodeJS?
  • Check for mistakes in config.json and the template .ejs files.
  • If you still can't compile try cloning the repo again and start fresh.
  • Something is wrong with the repo code, please open a issue!

"Server error"

This usually means something is wrong with the configuration, permission or PHP.

  • Check permissions, make sure www-data (Nginx/PHP-FPM) can read/write to the directories and files in /var/www/.
  • Make sure PHP-FPM is working, check the error log /var/log/php8.1-fpm.log.
  • Check includes/Core.namespace.php and make sure something isn't misspelled or a ' or ; is missing.

Empty response after uploading

  • Check permissions, make sure www-data (Nginx/PHP-FPM) can read/write to the directories and files in /var/www/.
  • Make sure PHP-FPM is working, check the error log /var/log/php8.1-fpm.log.
  • Make sure you created the /var/www/db/uguu.sq3 database and that it is populated.

"Filetype not allowed"

This means the filetype and/or MIME is blocked, check your BLOCKED_EXTENSIONS and BLOCKED_MIME.

"File too big"

This usually means you forgot change the Nginx and/or PHP configuration to allow bigger files, or the file is too big. :)

  • Check /etc/php/8.1/fpm/php.ini for the values post_max_size and upload_max_filesize.
  • Check /etc/nginx/nginx.conf for the value client_max_body_size.
  • Restart the Nginx and PHP-FPM service.

Files not getting deleted

  • Follow the steps under "Setup deletion scripts"
  • Run the crontab as root as this is probably a permission issue.
  • Set the right paths in the deletion scripts.

API

To upload using curl or make a tool you can post using:

  • curl -i -F files[]=@yourfile.jpeg https://uguu.se/upload.php (JSON Response)
  • curl -i -F files[]=@yourfile.jpeg https://uguu.se/upload.php?output=text (Text Response)
  • curl -i -F files[]=@yourfile.jpeg https://uguu.se/upload.php?output=csv (CSV Response)
  • curl -i -F files[]=@yourfile.jpeg https://uguu.se/upload.php?output=html (HTML Response)

Getting help

Open a issue ticket if something seems wrong with the code.

Hit me up at @nekunekus or email me at neku@pomf.se.

Credits

Uguu is based on Pomf which was written by Emma Lejack & Eric Johansson (nekunekus) and with help from the open source community.

License

Uguu is free software, and is released under the terms of the Expat license. See LICENSE.