Operating System BSD

How to Install Paste 3 (Pastebin Script) on FreeBSD 15 with Apache, PHP and MariaDB

Install the self-hosted Paste 3 pastebin on a FreeBSD 15 FAMP stack with Apache 2.4, PHP 8.4 and MariaDB, then secure and maintain it.

Paste is a self-hosted pastebin written in PHP, descended from the original pastebin.com source code. It offers syntax highlighting, user accounts, paste expiry, an admin panel with bans and spam controls, and an installer that sets up the database for you. This guide installs the current Paste 3.x on FreeBSD 15 with Apache 2.4, PHP 8.4 and MariaDB (a FAMP stack). Paste 2.1, which older tutorials describe, needed PHP 5 with the mcrypt extension and no longer runs on a supported PHP release; development now happens in the boxlabss/PASTE repository, and version 3.x requires PHP 8.1 or newer.

Requirements

  • A FreeBSD 15 server (15.1 is the production release at the time of writing; the same packages exist on 14.x) with root access.
  • PHP 8.1 or newer with the pdo_mysql, openssl, curl and fileinfo extensions, plus gd for the built-in CAPTCHA.
  • MySQL or MariaDB.
  • Apache with mod_rewrite (or NGINX; the project ships an example configuration in docs/nginx.example.conf).
  • A domain such as paste.example.com pointing at the server. HTTPS is required if you enable Google sign-in.

All commands below are run as root. If you work from an unprivileged account, install sudo with pkg install sudo and prefix them accordingly.

Step 1: Install Apache, PHP and MariaDB

pkg update
pkg upgrade -y
pkg install -y apache24 mod_php84 mariadb118-server git \
  php84-pdo_mysql php84-mysqli php84-curl php84-fileinfo php84-gd \
  php84-session php84-mbstring php84-ctype php84-filter

On FreeBSD, OpenSSL support is compiled into the base PHP package, so there is no separate openssl extension package to install. Enable the services at boot:

sysrc apache24_enable=YES
sysrc mysql_enable=YES

Step 2: Configure PHP for Apache

Create the PHP configuration from the production template:

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Tell Apache to hand .php files to the PHP module and to use index.php as a directory index. Create /usr/local/etc/apache24/Includes/php.conf:

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>

Paste uses clean URLs through its .htaccess file, which needs mod_rewrite. The module is installed but commented out in /usr/local/etc/apache24/httpd.conf. Enable it:

sed -i '' 's|^#LoadModule rewrite_module|LoadModule rewrite_module|' /usr/local/etc/apache24/httpd.conf

Step 3: Create the database

Start MariaDB and run the hardening script (set a root password, remove anonymous users and the test database):

service mysql-server start
mariadb-secure-installation

Open the client and create a database and user for Paste. Replace the password with your own:

mariadb -u root -p
CREATE DATABASE paste CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'paste'@'localhost' IDENTIFIED BY 'ChangeThisPassword';
GRANT ALL PRIVILEGES ON paste.* TO 'paste'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 4: Download Paste

Clone the source into its own directory under /usr/local/www and give it to the www user that Apache runs as, so that the installer can write config.php:

git clone https://github.com/boxlabss/PASTE.git /usr/local/www/paste
chown -R www:www /usr/local/www/paste

The project also publishes release archives on SourceForge (project name phpaste) if you prefer not to track the Git branch.

Step 5: Create the virtual host

Create /usr/local/etc/apache24/Includes/paste.conf:

<VirtualHost *:80>
    ServerName paste.example.com
    DocumentRoot "/usr/local/www/paste"

    <Directory "/usr/local/www/paste">
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog "/var/log/paste-error.log"
    CustomLog "/var/log/paste-access.log" combined
</VirtualHost>

Check the syntax and start Apache:

apachectl configtest
service apache24 start

If you run a packet filter, allow TCP ports 80 and 443. Before going public, add a TLS certificate (for example with Certbot from the package repository, or any other ACME client) so that logins are not sent in clear text.

Step 6: Run the web installer

Open http://paste.example.com/install in a browser. The installer checks the PHP requirements, asks for the database host (localhost), name, user and password from step 3, creates the tables, writes config.php and lets you create the administrator account.

When it finishes, delete the installer. The project is explicit that the install folder must not stay on a live site:

rm -rf /usr/local/www/paste/install

Clean URLs are controlled by the $mod_rewrite setting in config.php; set it to "1" if it is not already. The site address, name, CAPTCHA, mail and paste limits are set in the admin panel at http://paste.example.com/admin.

Verify the installation

  • Create a paste on the front page and open its link. A short URL without .php in it confirms that mod_rewrite and .htaccess work.
  • Request http://paste.example.com/install again: it must return 404.
  • If you get a blank page or a 500 error, read /var/log/paste-error.log. A missing PHP extension is the usual cause; list the loaded ones with php -m and restart Apache after installing a package.

Maintenance

To upgrade within the 3.x series, back up the database, update the files while keeping your config.php, and run the upgrade script. With a Git checkout, git reset --hard discards local changes (which is why config.php is copied away first) and the installer folder comes back with the new files, so remove it again afterwards:

mariadb-dump -u root -p paste > /root/paste-backup.sql
cd /usr/local/www/paste
cp config.php /root/paste-config.php
git reset --hard
git pull
cp /root/paste-config.php config.php
php install/upgrade.php
rm -rf install
chown -R www:www /usr/local/www/paste

Keep the operating system and packages current with freebsd-update fetch install and pkg upgrade. Optional Google sign-in and SMTP through Gmail need extra Composer packages; the commands are in the project README.

Frequently asked questions

Can I still install Paste 2.1?

You should not. It depends on PHP versions and the mcrypt extension that have been unsupported for years. Version 3.x is the same project brought up to date for PHP 8, with a new installer and admin panel.

Can I upgrade an existing Paste 2.x site?

Yes. Upload the 3.x files, open the installer, sign in with an admin account and choose the option to reinstall or change the database settings; it asks for the old $sec_key from your previous config.php so that pastes encrypted by 2.x can be re-encrypted. Take a database dump first.

Does Paste work with NGINX and PHP-FPM instead of Apache?

Yes. Install nginx and enable php_fpm instead of apache24 and mod_php84, and base your server block on docs/nginx.example.conf from the repository, which contains the rewrite rules that .htaccess provides on Apache.

Why does the installer say it cannot write the configuration?

The web server user needs write access to the Paste directory during installation. Run chown -R www:www /usr/local/www/paste and reload the page.

Share story:

Continue reading other guides on How VPS.