How to Install PrivateBin on NixOS Latest

PrivateBin is an open-source, self-hosted, secure online pastebin where you can store and share sensitive information. In this tutorial, we will guide you on how to install PrivateBin on NixOS Latest.

Prerequisites

Before installing PrivateBin, you need to have:

Step 1 – Install PHP

PrivateBin is built with PHP, so you must first install PHP and its required modules. You can do this on NixOS using the following command:

$ sudo nix-env -i php

Step 2 – Install Composer

Composer is a dependency management tool for PHP. To install it, run the following command:

$ sudo nix-env -i composer

Step 3 – Download and Extract PrivateBin

To download and extract PrivateBin, use the following command:

$ sudo mkdir -p /var/www/privatebin
$ sudo chown -R www-data:www-data /var/www/privatebin
$ sudo su -s /bin/bash -c "composer create-project privatebin/privatebin /var/www/privatebin -s dev" www-data

Step 4 – Configure Nginx

Next, we need to configure the web server to serve our PrivateBin instance. We will use nginx as an example web server in this tutorial.

Create a new server block file /etc/nginx/sites-enabled/my-privatebin-site:

$ sudo nano /etc/nginx/sites-enabled/my-privatebin-site

And add these configuration blocks:

server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/privatebin/public;
 
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
 
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
 
    location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|svg)$ {
        expires 7d;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
}

Save and close the file.

Restart nginx to apply the configuration changes:

$ sudo systemctl restart nginx

Step 5 – Configure PrivateBin

Now, we need to configure PrivateBin using the config.php file. Copy the example config.php file to the config folder and edit it:

$ sudo cp /var/www/privatebin/cfg/conf.sample.php /var/www/privatebin/cfg/conf.php
$ sudo nano /var/www/privatebin/cfg/conf.php

Update the following settings in the BASE section:

$GLOBALS['config'] = array(
    'expire' => 'burnafterreading', // Set expiration - you can choose 'burnafterreading', '5min', '10min', '1hour', '1day', '1week', '1month', '1year'
    'upload' => true, // Enable or disable file uploading
    'htaccess' => false, // Enable (.htaccess) or disable (.user.ini) apache module configuration
    'template' => 'bootstrap', // Set the default theme
    'language' => 'en', // Set the default language
    'baseurl' => 'https://yourdomain.com/', // Replace 'yourdomain.com' with your actual domain name or IP address
);

Save and close the file.

Step 6 – Enable and Start PHP-FPM

Finally, start php-fpm and enable its service at boot time:

$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpm

Step 7 – Test PrivateBin

Visit your PrivateBin site at https://yourdomain.com/ and create a new paste. If you can create and read pastes successfully, then you have successfully installed and configured PrivateBin on NixOS Latest.

Conclusion

In this tutorial, we have shown you how to install and configure PrivateBin on NixOS Latest. You can now use your own self-hosted version of the online pastebin that keeps your data safe and secure.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!