Pastebin

From Alpine Linux
Revision as of 22:45, 27 July 2023 by Zcrayfish (talk | contribs) (Rescued dead URLs.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A quick'n dirty doc about how to install a private pastebin service.

There are a lot of pastebin services (https://web.archive.org/web/20111205120332/https://en.wikipedia.org/wiki/Comparison_of_pastebins). We're going to use the oldest pastebin service, without DB support but only file.

Requirements:

  • An up-and-running Web server (here are quoted apache, but is also possible to add nginx and lighttpd configuration) with modules:
  • PHP
  • vhosts
  • mod_rewrite (for Apache and lighttpd, or NginxHttpRewriteModule for nginx)


Download Pastebin setup file

wget https://web.archive.org/web/20130602110905/http://pastebin.dixo.net/pastebin.tar.gz


Web Server Configuration to host pastebin

Apache Unzip the downloaded file in the web server vhosts dir:

tar -zxvf pastebin.tar.gz -C /var/www/vhosts

Rename vhosts dir:

mv /var/www/vhosts/pastebin-0.60 /var/www/vhosts/pastebin

  • Edit /etc/apache/httpd.conf and add the following:
       <VirtualHost *:80>
               ServerName  pastebin.my.domain
               DocumentRoot /var/www/vhosts/pastebin/public_html
               ErrorLog /var/log/apache2/pastebin-error.log
               CustomLog /var/log/apache2/pastebin-access.log common
               php_value include_path .:/var/www/vhosts/pastebin/lib
               php_value register_globals off
               DirectoryIndex pastebin.php
               RewriteEngine on
               RewriteLog /var/log/apache2/pastebin-rewrite.log
               RewriteRule /([a-z0-9]+)$ /pastebin.php?show=$1 [L]
       </VirtualHost>

lighttpd

  • Edit lighttpd.conf:
$HTTP["host"] =~ "(^|\.)paste.bin\.com$" {
   server.document-root = "/var/www/vhosts/pastebin/public_html"
   accesslog.filename = "/var/log/lighttpd/pastebin/access.log"
    fastcgi.server = (
       ".php" => (
           "localhost" => (
               "bin-path" => "/usr/bin/php-cgi",
               "socket" => "/tmp/php-pastebin.socket",
               "min-procs" => 1,
                "max-procs" => 2,
                "bin-copy-environment" => (
                    "PATH", "SHELL", "USER"
                )
            )
        )
    )
    compress.cache-dir = "/var/www/cache/pastebin/"
    url.rewrite-once = (
        "^/(pastebin.css)" => "$0",
        "^/(pastebin.js)" => "$0",
        "^/diff/(.*)" => "/pastebin.php?diff=$1",
        "^/(.*)" => "/pastebin.php?show=$1"
    )
}


Nginx

  • Edit nginx.conf (this is the significative part).
rewrite ^/([a-z0-9]+)$/pastebin.php?show=$1 last;
Warning: Nginx and Lighttpd configuration was not tested. These directive give you an idea on how is possible to implement pastebin on those web servers.


Configure pastebin

The configuration file is outside the directory "public_html", but is in "/lib/config" dir.

Copy default.conf.php into file that match your fqdn where pastebin service is hosted (e.g. pastebin.mydomain.com) with .conf.php extension.

In this case, will be: pastebin.mydomain.com.conf.php

  • Edit pastebin.mydomain.com.conf.php and modify the following part:
$CONF['dbsystem']='file';
$CONF['base_domain_elements']=2;


The others directive are not mandatory, but should be modified according with your needs.

The first directive mean that the backend must be a file instead of mysql (that is by default).

The second specify which part of the filename pastebin.mydomain.com.conf.php is the domain name.

In this case the number is 2: mydomain and com.

Now, you have to create the directory that will contain the posts file.

According with db.file.class.php the directory must be $_SERVER['DOCUMENT_ROOT'].'/../posts/ and must be writable by the user which runs webserver daemon.

mkdir -p /var/www/vhosts/pastebin/posts chown apache:apache /var/www/vhosts/pastebin/posts

Now, restart the web server. Pastebin service should be reachable on pastebin.mydomain.com