Deploying a Self-Hosted Pastebin with PrivateBin


Introduction

PrivateBin is a self-hosted, open-source pastebin that allows users to share text and code snippets securely. Unlike public pastebin services, PrivateBin encrypts data client-side, ensuring privacy. This guide will walk you through setting up PrivateBin on a Linux server.


Step 1: Install Required Dependencies

  1. Update your package list:
sudo apt update && sudo apt upgrade -y
  1. Install Apache or Nginx and PHP:
sudo apt install -y apache2 php php-fpm php-xml php-json php-mbstring unzip

Step 2: Download and Configure PrivateBin

  1. Navigate to the web directory:
cd /var/www
  1. Download the latest PrivateBin release:
sudo wget https://github.com/PrivateBin/PrivateBin/archive/refs/heads/master.zip
  1. Extract the archive and rename the folder:
sudo unzip master.zip && mv PrivateBin-master privatebin
  1. Set proper permissions:
sudo chown -R www-data:www-data /var/www/privatebin
  1. Configure PrivateBin settings:
sudo nano /var/www/privatebin/cfg/conf.php

Modify the settings as needed, then save and exit.


Step 3: Set Up a Web Server

Using Apache

  1. Create a new VirtualHost file:
sudo nano /etc/apache2/sites-available/privatebin.conf
  1. Add the following configuration:
<VirtualHost *:80>
	ServerName yourdomain.com
	DocumentRoot /var/www/privatebin

	<Directory /var/www/privatebin>
		AllowOverride All
		Require all granted
	</Directory>

	ErrorLog ${APACHE_LOG_DIR}/privatebin_error.log
	CustomLog ${APACHE_LOG_DIR}/privatebin_access.log combined

Using Nginx

  1. Create a new server block:
sudo nano /etc/nginx/sites-available/privatebin
  1. Add the following configuration:
server {
	listen 80;
	server_name yourdomain.com;
	root /var/www/privatebin;

	index index.php;

	location / {
		try_files $uri $uri/ /index.php?$query_string;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php-fpm.sock;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
	}
}
  1. Enable the site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/privatebin /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Step 4: Secure PrivateBin with HTTPS

  1. Install Certbot for Let’s Encrypt:
sudo apt install -y certbot python3-certbot-apache

(for Apache)

sudo apt install -y certbot python3-certbot-nginx

(for Nginx)

  1. Obtain an SSL certificate:
sudo certbot --apache -d yourdomain.com

(for Apache)

sudo certbot --nginx -d yourdomain.com

(for Nginx)

  1. Verify that HTTPS is working by visiting https://yourdomain.com.

Conclusion

You have successfully set up a self-hosted PrivateBin instance. This allows you to share text securely while maintaining control over your data. Regularly update your server and PrivateBin installation to ensure security and stability.