How to Install Textpattern CMS with Nginx on Debian 10

Textpattern is a free and open-source PHP content management system. It is rather lightweight, fast, and easy to use while providing decent customizability through themes and plugins. In this guide, we will install Textpattern on a fresh Debian 10 instance.

Requirements

  • A fresh Debian 10 system on which you have access to the root user or any user with sudo privileges.
  • A registered domain name pointing to your server.

If logged in as a sudo user, switch to root for this setup:

sudo su -

Set the $VISUAL environment variable to a text editor of your preference. For example, to use nano:

echo "export VISUAL=nano" >> ~/.profile
. ~/.profile

Step 1: Installing Required Software.

Update the package cache on your system:

apt update

Then install Nginx, PHP-FPM, the required PHP extensions, MariaDB, and certbot:

apt install -y nginx mariadb-server php-fpm php-xml php-mysql php-json php-mbstring php-zip certbot

Ensure the Nginx and MariaDB services are enabled and running:

systemctl enable --now nginx.service mariadb.service

Step 2: Textpattern Download

Copy the download link (in .tar.gz format) for the latest textpattern release from their Releases on Github and download it to your server with wget as follows:

wget https://github.com/textpattern/textpattern/releases/download/4.7.3/textpattern-4.7.3.tar.gz

Then unpack the archive and move the contents to a location inside the webroot directory:

tar -xzf textpattern*.tar.gz
rm textpattern*.tar.gz
mv textpattern* /var/www/html/textpattern

Step 3: Database Setup

Start by running the mysql_secure_installation script to perform basic security enhancements:

mysql_secure_installation

Answer the questions as shown below and make sure to choose a secure password for the root user:

Enter current password for root (enter for none): 
Set root password? [Y/n] y
New password: your_password
Re-enter new password: your_password
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Next, we will create a database and user to be used by Textpattern. Log into the MySQL shell with:

mysql -u root -p

Enter your root password, then issue the following statements. Make sure to replace textpattern_user_password with a proper password.

MariaDB [(none)]> CREATE DATABASE textpattern_db;
MariaDB [(none)]> CREATE USER textpattern_user IDENTIFIED BY 'textpattern_user_password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON textpattern_db.* TO textpattern_user;
MariaDB [(none)]> \q

Step 4: Nginx Configuration

First, obtain an SSL certificate for your domain by running the following command:

certbot certonly --webroot --webroot-path /var/www/html -d "your_domain" -m "[email protected]"

Assuming your domain is correctly configured, certbot will automatically obtain a certificate which we will use to configure HTTPS.

Next, disable the default Nginx server configuration file:

rm /etc/nginx/sites-enabled/default

Then open a new configuration file under /etc/nginx/sites-available:

$VISUAL /etc/nginx/sites-available/textpattern

And enter the following sensible configuration, replacing your_domain with your domain name:

server {
  listen 80;
  #replace your_domain below
  server_name your_domain;
  return 301 https://$server_name$request_uri;
}
server {
  listen 443 ssl;
  #replace your_domain below
  server_name your_domain;
  root /var/www/html/textpattern;
  index index.php;
  ssl on;
  #replace your_domain below
  ssl_certificate /etc/letsencrypt/live/your_domain/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/your_domain/privkey.pem;
  location ~* \.php$ {
    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
  }
}

Note that this configuration will redirect all HTTP requests to HTTPS. You may want to modify it if you have specific preferences or requirements. Once you're satisfied with it, create a symbolic link in the sites-enabled directory:

ln -s /etc/nginx/sites-available/textpattern /etc/nginx/sites-enabled/

Then check for any syntax errors with:

nginx -t

Finally, issue the following command to load the new configuration:

systemctl reload nginx.service

Step 5: Textpattern Configuration

Your Textpattern installation should now be accessible but isn't configured yet. Browse to https://your_domain/textpattern/setup/ to start the web installer. After choosing a language, enter database details:

  • MySQL user name: textpattern_user
  • MySQL password: Enter the password chosen for textpattern_user during step 2.
  • MySQL server: localhost
  • MySQL database: textpattern_db
  • Table prefix: leave blank

The installer will check the database credentials entered before generating the corresponding configuration. Create the required file:

$VISUAL /var/www/html/textpattern/textpattern/config.php

Paste the generated configuration, save the file and exit. Proceed to the next step in the web installer, where you'll be asked to enter information for the CMS administrator account and site configuration. Once that is done, remove the setup directory:

rm -rf /var/www/html/textpattern/textpattern/setup

And give the Nginx system user ownership of the directories to which Textpattern needs write access:

chown -R www-data /var/www/html/textpattern/{files,images,themes}

Your Textpattern site is now ready for use. The administration interface can be accessed at https://your_domain/textpattern.

More Information

Share this page:

1 Comment(s)