Operating System BSD

How to Install Silverstripe CMS 6 on FreeBSD 15 with Apache, MariaDB and PHP

Install Silverstripe CMS 6 on a FreeBSD 15 server with Apache, MariaDB and PHP 8.5, using Composer, a .env file and the sake command line tool.

By the end of this guide you will have Silverstripe CMS 6 running on a FreeBSD server with Apache 2.4, MariaDB and PHP 8.5 (a FAMP stack), installed with Composer and configured through a .env file. The steps are written for FreeBSD 15.1, the current production release, and apply equally to the 14.5 legacy release. FreeBSD 11 reached end of life in 2021 and no longer receives packages or security fixes.

Silverstripe (formerly written "SilverStripe") is an open source PHP content management system and framework. Older tutorials describe downloading a tarball and clicking through a web installer. Neither exists any more: current releases are installed with Composer, configured with environment variables and initialised from the command line.

Requirements

  • A FreeBSD 15.1 or 14.5 server with root access over SSH. Commands are run as root unless stated otherwise; prefix them with sudo or doas if that is how you work.
  • An unprivileged user for running Composer. This guide calls it deploy.
  • A domain name such as example.com pointing to the server.

Silverstripe CMS 6.2 and newer support PHP 8.3 to 8.5 (6.0 and 6.1 support 8.3 and 8.4), need MySQL 8.0 or newer or MariaDB, and require Composer 2. The PHP extensions the project lists are ctype, dom, fileinfo, hash, intl, mbstring, session, simplexml, tokenizer and xml, plus gd or imagick for images and a database driver.

Bring the package catalogue and installed packages up to date first:

pkg update
pkg upgrade

Install Apache, MariaDB, PHP and Composer

PHP 8.5 is FreeBSD's default PHP version and is supported by Silverstripe CMS 6.2 and later, so the packages below use it. On FreeBSD most PHP extensions are separate packages, which is why the list is long. The hash extension is part of PHP itself.

pkg install apache24 mariadb118-server mariadb118-client \
  php85 mod_php85 php85-composer \
  php85-ctype php85-dom php85-fileinfo php85-filter php85-gd php85-intl \
  php85-mbstring php85-mysqli php85-session php85-simplexml \
  php85-tokenizer php85-xml php85-zip php85-curl

Create a PHP configuration file from the production template. Its default memory_limit is well above the 48 MB minimum Silverstripe asks for.

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

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 as root:

mariadb -u root

Create a database and a dedicated user. Replace the password with your own:

CREATE DATABASE silverstripe CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'silverstripe'@'localhost' IDENTIFIED BY 'change-this-password';
GRANT ALL ON silverstripe.* TO 'silverstripe'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Create the project with Composer

Composer should not run as root. Create the project directory, hand it to the deploy user and let that user download Silverstripe:

mkdir /usr/local/www/silverstripe
chown deploy /usr/local/www/silverstripe
su - deploy -c "composer create-project silverstripe/installer /usr/local/www/silverstripe"

This installs the latest stable release of the silverstripe/installer recipe (6.3 at the time of writing) with all its dependencies in vendor/. The directory that the web server will serve is public/; application code, configuration and vendor/ stay outside the document root.

Configure the environment

Silverstripe reads its settings from a .env file in the project root (not in public/). The installer ships an example file to start from:

cd /usr/local/www/silverstripe
cp .env.example .env

Edit .env so that it contains the following, with your own database password, admin password and host name:

SS_DATABASE_CLASS="MySQLDatabase"
SS_DATABASE_NAME="silverstripe"
SS_DATABASE_SERVER="localhost"
SS_DATABASE_USERNAME="silverstripe"
SS_DATABASE_PASSWORD="change-this-password"
SS_DEFAULT_ADMIN_USERNAME="admin"
SS_DEFAULT_ADMIN_PASSWORD="another-strong-password"
SS_ENVIRONMENT_TYPE="live"
SS_BASE_URL="https://example.com"
SS_ALLOWED_HOSTS="example.com,www.example.com"

SS_ENVIRONMENT_TYPE accepts dev, test or live; use live on a public server so that errors are not shown to visitors. SS_BASE_URL tells command line tasks what the site address is, and SS_ALLOWED_HOSTS stops the site answering for unexpected Host headers. Use http:// in SS_BASE_URL until you have a TLS certificate in place.

Set file permissions

Apache runs as the www user on FreeBSD. It needs to read the whole project but write only to two places: public/assets/ for uploads, and a cache directory. If a directory named silverstripe-cache exists in the project root, Silverstripe uses it for its caches instead of the system temporary directory.

cd /usr/local/www/silverstripe
mkdir -p public/assets silverstripe-cache
chown -R www:www public/assets silverstripe-cache
chown deploy:www .env
chmod 640 .env

The last two commands keep the database password readable by the web server but not by other local users.

Configure Apache

Silverstripe routes every request through public/index.php using the .htaccess files it ships, which requires mod_rewrite. The module is disabled in FreeBSD's default configuration. Open /usr/local/etc/apache24/httpd.conf and remove the leading # from this line:

LoadModule rewrite_module libexec/apache24/mod_rewrite.so

Create /usr/local/etc/apache24/Includes/php.conf so that Apache passes 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/silverstripe.conf. The document root is the public sub-directory, and AllowOverride All lets Apache apply the bundled .htaccess rules, including the one that blocks PHP execution in the uploads directory:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "/usr/local/www/silverstripe/public"
    <Directory "/usr/local/www/silverstripe/public">
        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

For a public site, add a TLS certificate and an HTTPS virtual host before you log in to the CMS over the internet.

Build the database and log in

The database tables are created by sake, Silverstripe's command line tool. Run it as the web server user so that the cache files it writes belong to www:

su -m www -c "cd /usr/local/www/silverstripe && vendor/bin/sake db:build"

The command lists each table it creates. When it finishes, open http://example.com/ to see the default home page, and http://example.com/admin to log in with the SS_DEFAULT_ADMIN_USERNAME and SS_DEFAULT_ADMIN_PASSWORD values from .env.

The default admin account lives only in .env; its password is not stored in the database. Once you are in, create a personal administrator account in the Security section of the CMS, log in with it, and then delete the two SS_DEFAULT_ADMIN_* lines from .env.

Maintenance

Updates are applied with Composer as the deploy user, followed by a database build as www. The --flush flag clears Silverstripe's manifest and template caches, which is needed after any code or configuration change:

su - deploy -c "cd /usr/local/www/silverstripe && composer update"
su -m www -c "cd /usr/local/www/silverstripe && vendor/bin/sake db:build --flush"

Back up three things: a dump of the silverstripe database, the public/assets directory, and your project files including composer.lock and .env.

If pages other than the home page return 404, mod_rewrite is not loaded or AllowOverride All is missing. A blank page or a 500 error after a change usually means stale caches: run vendor/bin/sake flush as www and check /var/log/httpd-error.log.

Frequently asked questions

Is there still a web-based installer or a downloadable archive?

No. Silverstripe CMS is distributed through Composer only. The project is created with composer create-project, configured in .env and initialised with sake db:build.

Why must sake run as the www user?

Silverstripe keeps a filesystem cache per system user. If you run sake as another user, it builds and flushes a separate cache, and the web server keeps serving from its own stale one. The project documentation recommends using the same user and PHP version as the web server.

Can I use PostgreSQL or SQLite instead of MariaDB?

MySQL and MariaDB are the databases supported by the core project. PostgreSQL, SQLite and SQL Server work through community-maintained modules, which you install with Composer and select with SS_DATABASE_CLASS.

Should the protected assets folder stay inside public/?

Draft and restricted files are stored in public/assets/.protected by default, and the bundled .htaccess denies access to it. The documentation recommends moving it outside the document root by setting SS_PROTECTED_ASSETS_PATH in .env to a directory that www can write to.

Share story:

Continue reading other guides on How VPS.