Operating System BSD

How to Install Textpattern CMS 4.9 on FreeBSD 15 with Apache, MariaDB and PHP

Install Textpattern CMS 4.9 on a FreeBSD 15 FAMP server: PHP extension packages, database, Apache virtual host, web setup and Diagnostics checks.

This guide installs Textpattern CMS 4.9 on a FreeBSD server with Apache 2.4, MariaDB and PHP 8.4 (a FAMP stack). At the end you will have a working Textpattern site with clean URLs, the setup directory removed and a clean Diagnostics panel. The steps are written for FreeBSD 15.1, the current production release, and apply equally to the 14.x legacy branch. FreeBSD 11 reached end of life in 2021 and no longer receives packages.

Textpattern is a small, actively maintained PHP content management system with a tag-based template language. The current release at the time of writing is 4.9.2. There is no usable FreeBSD package: the old www/textpattern port stopped at version 4.6.2 and was removed from the ports tree in 2018, so you install from the official release archive.

Requirements

  • A FreeBSD 15.1 or 14.x server with root access over SSH. Commands below are run as root; prefix them with sudo or doas if you use one of those.
  • A domain name such as example.com pointing to the server.

Textpattern 4.9 runs on PHP 5.6 or newer, but the project recommends PHP 8.4 or 8.5 and MySQL 8.4; MariaDB works as a drop-in replacement and is what this guide uses. The required PHP extensions are mysqli, xml with SimpleXML, and json (built into PHP 8). Recommended extensions are exif, intl, mbstring, zip and zlib.

Bring the package catalogue and installed packages up to date:

pkg update
pkg upgrade

Install Apache, MariaDB and PHP

FreeBSD splits PHP into one package per extension, so each one Textpattern uses has to be named:

pkg install apache24 mariadb118-server mariadb118-client \
  php84 mod_php84 php84-mysqli php84-xml php84-simplexml php84-session \
  php84-filter php84-dom php84-mbstring php84-intl php84-exif \
  php84-zip php84-zlib

Create a PHP configuration file from the production template:

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

Textpattern requires a valid date.timezone setting. Open /usr/local/etc/php.ini, find the commented ;date.timezone = line and set it to your zone, for example:

date.timezone = Europe/London

Create the database

Enable and start MariaDB, then run the hardening script and accept its suggestions:

sysrc mysql_enable=YES
service mysql-server start
mariadb-secure-installation

Open the MariaDB shell:

mariadb -u root

Create a database and a dedicated user. The privilege list is the one Textpattern documents as necessary; use your own strong password:

CREATE DATABASE textpattern CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'textpattern'@'localhost' IDENTIFIED BY 'change-this-password';
GRANT SELECT, CREATE, ALTER, INSERT, UPDATE, DELETE, DROP, INDEX, LOCK TABLES
  ON textpattern.* TO 'textpattern'@'localhost';
EXIT;

Some plugins also need CREATE TEMPORARY TABLES or CREATE VIEW; grant those later if a plugin asks for them.

Download Textpattern

Release archives are published on textpattern.com/download and on the project's GitHub releases page. Check the download page for a newer version and adjust the number in the commands.

cd /tmp
fetch https://github.com/textpattern/textpattern/releases/download/4.9.2/textpattern-4.9.2.tar.gz
sha256 textpattern-4.9.2.tar.gz

Compare the printed hash with the SHA256 checksum shown next to the .tar.gz file on the download page before continuing. Then unpack the archive into the web root:

mkdir -p /usr/local/www/textpattern
tar -xzf textpattern-4.9.2.tar.gz -C /usr/local/www/textpattern --strip-components 1

Apache runs as the www user on FreeBSD. Keep the code owned by root and give the web server write access only to the directories Textpattern writes to: files (file downloads), images (uploaded images), themes (theme import and export) and textpattern/plugins (installed plugins).

chown -R root:wheel /usr/local/www/textpattern
chown -R www:www /usr/local/www/textpattern/files \
  /usr/local/www/textpattern/images /usr/local/www/textpattern/themes   /usr/local/www/textpattern/textpattern/plugins

The installation notes also ask Apache users to activate the bundled rule that blocks direct browser access to plugin code:

cd /usr/local/www/textpattern/textpattern/plugins
mv .htaccess-dist .htaccess

Configure Apache

Textpattern's clean URLs rely on mod_rewrite, which is disabled in FreeBSD's default Apache configuration. Open /usr/local/etc/apache24/httpd.conf and remove the leading # from this line:

LoadModule rewrite_module libexec/apache24/mod_rewrite.so

Files ending in .conf in /usr/local/etc/apache24/Includes/ are loaded automatically. Create /usr/local/etc/apache24/Includes/php.conf so that Apache hands PHP files to mod_php:

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

Then create /usr/local/etc/apache24/Includes/textpattern.conf. AllowOverride All is needed so that the .htaccess files shipped with Textpattern take effect:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/usr/local/www/textpattern"
    <Directory "/usr/local/www/textpattern">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Check the syntax, enable Apache at boot and start it:

service apache24 configtest
sysrc apache24_enable=YES
service apache24 start

Run the setup

Browse to http://example.com/textpattern/setup/ and work through the screens:

  1. Choose a language.
  2. Enter the database details: user textpattern, its password, server localhost and database textpattern. Leave the table prefix empty unless the database is shared.
  3. The setup then shows the contents of a configuration file. Because the code directory is owned by root, create the file yourself: copy the generated text, save it as /usr/local/www/textpattern/textpattern/config.php, then continue in the browser.
  4. Create the first publisher account with your name, a login name, a strong password and an email address, and pick the admin and front-end themes.

Lock down the configuration file, which contains the database password, so that only root and the web server can read it:

chown root:www /usr/local/www/textpattern/textpattern/config.php
chmod 640 /usr/local/www/textpattern/textpattern/config.php

Finish and verify

Delete the setup directory. Textpattern reports it as a problem for as long as it exists:

rm -rf /usr/local/www/textpattern/textpattern/setup

Log in at http://example.com/textpattern/ and open Admin > Diagnostics. The panel lists anything that still needs attention, such as a missing PHP extension, a directory the web server cannot write to, or a leftover setup directory. A fresh installation should report that all checks pass once the steps above are done.

If article links return 404 errors while the home page works, mod_rewrite is not loaded or AllowOverride All is missing for the document root. As a temporary workaround you can switch Admin > Preferences > Site > Article URL pattern to the ?id= form.

Before you publish the site, add a TLS certificate (for example with a Let's Encrypt client from the FreeBSD package repository) and serve the admin area over HTTPS only.

Updating Textpattern

Back up the database and the files, images, themes and textpattern/plugins directories together with config.php:

mariadb-dump -u root textpattern | gzip > /root/textpattern-$(date +%F).sql.gz
tar -czf /root/textpattern-files-$(date +%F).tar.gz -C /usr/local/www/textpattern \
  files images themes textpattern/plugins textpattern/config.php

Log out of the admin side, then unpack the new release over the existing tree with the same tar command used for installation; your config.php and installed plugins are not part of the archive and stay in place. Delete the new textpattern/setup directory and log in again: the upgrade scripts run automatically on the first admin login. Check Admin > Diagnostics afterwards, and read UPGRADE.txt and HISTORY.txt in the archive for version-specific notes. Keep the operating system packages current with pkg upgrade as well.

Frequently asked questions

Can I use PHP 8.5 instead of 8.4?

Yes. Textpattern recommends either. Replace php84 with php85 in every package name, including mod_php85. Do not mix extension packages from two PHP versions on one server.

Does Textpattern work with Nginx on FreeBSD?

Yes. Nginx 1.13 or newer is supported alongside Apache. Nginx ignores the bundled .htaccess files, so you need a try_files rule that passes unknown paths to index.php, and PHP-FPM instead of mod_php.

What is the sites directory in the archive for?

It is a template for running several Textpattern sites from one copy of the code. A single-site installation does not use it and you can leave it in place or delete it.

The Diagnostics panel says a directory is not writable. What should I change?

Only files, images, themes and textpattern/plugins need to be writable by the www user. Re-run the chown command for the directory named in the warning rather than making the whole tree writable.

Share story:

Continue reading other guides on How VPS.