Operating System BSD

How to Install Couch CMS 2.4 on FreeBSD 15 With Apache, MariaDB and PHP

Set up Couch CMS 2.4 on a FreeBSD 15 server with Apache, PHP 8.4 and MariaDB, from packages to the first editable template.

Couch CMS is an open-source content management system aimed at designers: you add a few special tags to an existing HTML template and its regions become editable in an admin panel, without writing PHP. This guide installs the current release, Couch CMS 2.4, on FreeBSD 15 with Apache 2.4, PHP 8.4 and MariaDB (a "FAMP" stack). The same commands work on FreeBSD 14. FreeBSD 11 and PHP 7.1 are long out of support and should not be used for a new site.

Requirements

  • A server running FreeBSD 15 (15.1 is the current release) with root access.
  • A user that can run sudo. If sudo is not installed, run pkg install sudo as root, add your user to the wheel group and enable the %wheel line with visudo; or run the commands below as root without the sudo prefix.
  • A domain name pointing at the server if you want HTTPS. The examples use example.com and the address 203.0.113.10.

Couch officially supports Apache and compatible web servers and MySQL-compatible databases; Microsoft IIS is not supported.

Step 1: Update the system

sudo freebsd-update fetch install
sudo pkg update
sudo pkg upgrade

Reboot if a new kernel was installed. On a FreeBSD 15 system installed with packaged base (pkgbase), the base system is updated by pkg upgrade and freebsd-update does not apply.

Step 2: Install and configure Apache

sudo pkg install -y apache24
sudo sysrc apache24_enable=YES

Couch uses mod_rewrite for pretty URLs. Enable the module, which is commented out in the default configuration:

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

Allow .htaccess files in the document root by creating /usr/local/etc/apache24/Includes/couch.conf:

ServerName example.com

<Directory "/usr/local/www/apache24/data">
    AllowOverride All
</Directory>

Step 3: Install PHP 8.4

Install PHP, the Apache module and the extensions Couch uses for the database, images, sessions and text handling:

sudo pkg install -y php84 mod_php84 php84-mysqli php84-gd php84-mbstring php84-curl php84-ctype php84-tokenizer php84-dom php84-session php84-iconv php84-fileinfo php84-zlib php84-filter

Create the production php.ini:

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

Tell Apache to hand .php files to the module. 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>

Check the syntax and start Apache:

sudo apachectl configtest
sudo service apache24 start

Step 4: Install MariaDB and create the database

sudo pkg install -y mariadb118-server mariadb118-client
sudo sysrc mysql_enable=YES
sudo service mysql-server start
sudo mariadb-secure-installation

The service is still called mysql-server on FreeBSD. In the hardening script, accept the defaults to remove anonymous users and the test database. Then open the client:

sudo mariadb

Create a database and a user for Couch, with a password of your own:

CREATE DATABASE couch_db;
CREATE USER 'couch_user'@'localhost' IDENTIFIED BY 'choose-a-strong-password';
GRANT ALL PRIVILEGES ON couch_db.* TO 'couch_user'@'localhost';
EXIT;

Step 5: Download Couch CMS

Couch is a single folder named couch that you place inside your website. The 2.4 release was tagged in October 2023, and fixes for newer PHP versions have been committed to the repository since then, so take the current master branch (it still reports version 2.4):

sudo pkg install -y git
git clone --depth 1 https://github.com/CouchCMS/CouchCMS.git /tmp/CouchCMS
sudo cp -R /tmp/CouchCMS/couch /usr/local/www/apache24/data/

Step 6: Configure Couch

Create the configuration file from the example and open it:

cd /usr/local/www/apache24/data/couch
sudo cp config.example.php config.php
sudo ee config.php

Set the database values, and uncomment and set the site URL, which the file recommends defining on a production site:

define( 'K_SITE_URL', 'http://example.com/' );

define( 'K_DB_NAME', 'couch_db' );
define( 'K_DB_USER', 'couch_user' );
define( 'K_DB_PASSWORD', 'choose-a-strong-password' );
define( 'K_DB_HOST', 'localhost' );

Also set K_EMAIL_TO and K_EMAIL_FROM to real addresses and K_GMT_OFFSET to your time zone. Then give the web server ownership of the site so Couch can store uploads and cache files:

sudo chown -R www:www /usr/local/www/apache24/data
sudo service apache24 restart

Step 7: Run the installer

Open the admin folder in a browser:

http://example.com/couch/

Couch detects that it is not installed yet and asks for a name, password and email address. These create the super-admin account; only one such account can exist per installation, and its email address is used for password recovery. Submit the form and log in.

Step 8: Verify with a first editable page

The admin panel is empty until a template registers itself. Create /usr/local/www/apache24/data/index.php:

<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Home' />
<!DOCTYPE html>
<html>
<body>
<cms:editable name='intro' type='richtext'>
    <p>Hello from Couch.</p>
</cms:editable>
</body>
</html>
<?php COUCH::invoke(); ?>

Remove the default index.html, then visit http://example.com/ while you are logged in as super-admin. The template named "Home" now appears in the admin panel with an editable intro field. Any existing HTML page becomes a Couch template the same way: rename it to .php, add the first and last line, and wrap regions in cms:editable tags.

Next steps

  • HTTPS: obtain a certificate with an ACME client such as certbot, enable mod_ssl in Apache, then change K_SITE_URL to https://.
  • Pretty URLs: set K_PRETTY_URLS to 1 in config.php and save the rewrite rules that http://example.com/couch/gen_htaccess.php generates as an .htaccess file in the site root, as described in the Couch documentation.
  • Firewall: allow only SSH, HTTP and HTTPS with pf or your provider's firewall.
  • Backups: dump the database with mariadb-dump couch_db and copy the couch/uploads folder along with your templates.

Frequently asked questions

Is Couch CMS still maintained?

Yes. Version 2.4 is the latest tagged release, and the GitHub repository continues to receive bug and security fixes, including PHP 8 compatibility changes. To update, overwrite the core files in the couch folder with a newer copy while keeping your config.php and the uploads and snippets folders; the repository's UPGRADE.md lists the steps.

Can I remove the Couch branding?

Couch is released under the Common Public Attribution License, which lets you use it commercially free of charge. Replacing the logo and footer in the admin panel with your own requires the paid commercial licence, which is enabled through K_PAID_LICENSE in config.php.

Does Couch work with Nginx?

The project lists Apache and compatible servers such as LiteSpeed as supported, and it relies on .htaccess files for pretty URLs and for protecting its own folders. Nginx ignores .htaccess, so every rule has to be translated by hand; Apache is the simpler choice.

I get a 500 Internal Server Error at /couch/. What is wrong?

Check /var/log/httpd-error.log. The couch folder ships an .htaccess file containing Options -Indexes, which fails on servers that do not permit that override; the AllowOverride All setting from Step 2 permits it. If the error persists, the Couch documentation suggests deleting that file.

Share story:

Continue reading other guides on How VPS.