Deploying a Self-Hosted Pastebin with PrivateBin
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
- Update your package list:
sudo apt update && sudo apt upgrade -y
- 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
- Navigate to the web directory:
cd /var/www
- Download the latest PrivateBin release:
sudo wget https://github.com/PrivateBin/PrivateBin/archive/refs/heads/master.zip
- Extract the archive and rename the folder:
sudo unzip master.zip && mv PrivateBin-master privatebin
- Set proper permissions:
sudo chown -R www-data:www-data /var/www/privatebin
- 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
- Create a new VirtualHost file:
sudo nano /etc/apache2/sites-available/privatebin.conf
- 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
- Create a new server block:
sudo nano /etc/nginx/sites-available/privatebin
- 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;
}
}
- 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
- 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)
- Obtain an SSL certificate:
sudo certbot --apache -d yourdomain.com
(for Apache)
sudo certbot --nginx -d yourdomain.com
(for Nginx)
- 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.