PrivateBin – Your Self-Hosted Pastebin Instance

PrivateBin Logo

A Pastebin is a quick and handy way to share logs, debug output, etc. They are usually used in support situations. There are quite a number of public pastebin services out there, with the most known being pastebin.com. But they all have one issue, privacy. You have to trust the hoster with your data. And logs can reveal a lot of information.

Wouldn’t it be nice to host such a service yourself? PrivateBin to the rescue!

This article will showcase how easy it is to host your own PrivateBin instance. Some assumptions are being made here of course, such as that you have a server to run your PrivateBin instance, your own domain to go with and are confident to get SSL certificates to work because it’s 2022 and there is no reason not to have your website not running with HTTPS.

Requirements

To run PrivateBin you need PHP installed. According to the official documentation of PrivateBin, PHP 7.0 at least, but again, it’s 2022, so best go with a more recent version here. I recommend using PHP 8.1, you can have a quick read-up here on how to install PHP 8.1 on Debian-based systems such as your Raspberry Pi for example.

Furthermore, you need some PHP extensions, such as:

  • GD extension
  • zlib extension

Also, you need some disk space or a database supported by PDO.

Install PrivateBin

The installation process is pretty straightforward.

Download the latest release from the release archive (It’s the link labelled “Source Code (…)”) and extract it in the folder you want to install your PrivateBin instance. For example /var/www/privatebin/. Make sure the files and folders are owned by the `www-data` user so that your webserver can read and write there.

Configure PrivateBin

An example configuration is provided in cfg/conf.sample.php which you can cop to cfg/conf.php. The file’s content is well documented and explained in the file itself, change it to your needs. Important to know is that basepath is mandatory to configure with the URL of your PrivateBin instance, including the full protocol (`https://`) and it needs to have a trailing slash.

Configure the Webserver

I use Nginx for this, so that’s what I will cover here. For Apache2 users, I’m pretty sure you know how to write a vhost file pointing at a directory. There is no rocket science involved in this one, just have it pointing to the right directory.

server {
    listen 80;
    listen [::]:80;

    server_name pastebin.yourdomain.net;

    # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name pastebin.yourdomain.net;

    ssl_certificate         /certificates/pastebin.yourdomain.net.crt;
    ssl_certificate_key     /certificates/pastebin.yourdomain.net.key;

    include /etc/nginx/options-ssl-nginx.conf;

    gzip on;
    access_log  /var/log/nginx/pastebin.yourdomain.net/access.log;
    error_log   /var/log/nginx/pastebin.yourdomain.net/error.log  warn;

    root /var/www/pastebin;
    index index.php index.html index.htm index.nginx-debian.html;

    location / {
        try_files $uri $uri/ =404;
    }

    # In case you are running PHP-FPM, uncomment the following lines
#    location ~ .php$ {
#        include snippets/fastcgi-php.conf;
#        fastcgi_pass unix:/var/run/php/php-fpm.sock;
#    }
}

That’s it, have fun with your own pastebin service!

Leave a Reply