Textpattern

Install Textpattern CMS using NGinx on Ubuntu

published on

Textpattern is another content management system that you might like to try in case Wordpress doesn't really meet your need and you want to look for an alternative.

To install it on your VPS follow thse instructions.

The initial setup

Make sure to run the following commands to install the necessary utility packages

sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common language-pack-en-base unzip zip curl
sudo locale-gen en_US.UTF-8
sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/nginx-mainline

You will also want to run sudo nano /etc/apt/sources.list.d/ondrej-ubuntu-nginx-mainline-*.list in order to uncomment the deb-src line before running sudo apt update.

Now install NGinx

This is done by running sudo apt install nginx-core nginx-common nginx nginx-full libgeoip-dev libpcre3-dev.

Next, install PHP 8.1

sudo apt install openssl php8.1-{common, cli, bz2, zip, curl, intl, mysql, snmp, memcached, imagick, gd, fileinfo, imap, ldap, soap, tidy, xml, gd, gmp, pspell, mbstring, opcache, fpm, ssh2, imap, redis, apcu, mcrypt}
sudo apt install unzip ghostscript imagemagick

Edit the /etc/php/8.1/fpm/pool.d/www.conf file and add, or edit, lines to look like the ones below

listen = /run/php/php8.1-fpm.sock
listen.owner = www-data
listen.mode = 0660 

Now edit the /etc/php/8.1/fpm/php.ini file and add or edit the following lines

output_buffering = Off
zlib.output_compression On
zlib.output_compression_level 5
expose_php = off
max_execution_time = 120
max_input_time = 60
max_input_vars = 1000
memory_limit = 512M       
display_errors = Off
display_startup_errors = Off
log_errors = On
html_errors = On
post_max_size = 128M
upload_max_filesize = 128M
cgi.fix_pathinfo=0
allow_url_fopen = Off
extension=curl.dll
extension=pdo_mysql
date.timezone = Europe/London
opcache.enable=1
opcache.jit_buffer_size=100M
opcache.jit=1255
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=200

Lastly run sudo systemctl restart php8.1-fpm to update the PHP settings.

Now install MariaDB

Run the following commands to install and secure MariaDB

sudo apt install mariadb-server
sudo mysql_secure_installation

Now run sudo mysql -u root -p and enter the following commands to create the database that TextPattern will use

CREATE DATABASE tpdb charset=utf8;
CREATE USER 'tpu'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON tpdb.* TO 'tpu'@'localhost';
FLUSH PRIVILEGES;
exit

Next, create the NGinx server block

Run sudo nano /etc/nginx/sites-available/[domain] where [domain] is the domain name you are using to access your site and add the following lines

server {
        listen 80;
        listen [::]:80;
        server_name [domain] www.[domain];
        root /var/www/[domain];
        index index.php;
        charset uft-8;
        client_max_body_size 30M;

        location ~ /\.ht {
                deny  all;
        }

        location / {
          index index.php;
          try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_pass   unix:/run/php/php8.1-fpm.sock;
        }

        #Inhibits direct file downloads
        #location ^~ /files/\.*$ {
          #  return 403;
        #}

        location ^~ /themes/\.txp$ {
          return 403;
        }

        types {
         image/svg+xml svg svgz;
        }

        gzip on;
        gzip_types image/svg+xml;

        access_log /var/log/nginx/[domain].access.log;
        error_log /var/log/nginx/[domain].error.log;
}

Finally run the following commands to test and activate your configuration

sudo ln -s /etc/nginx/sites-available/[domain] /etc/nginx/sites-enabled/[domain]
sudo nginx -t
sudo systemctl restart nginx

Secure your site with a TLS certificate

sudo apt install snapd
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot -d [domain] -d www.[domain] --nginx

Now it is time to install Textpattern

Run the following set of commands to download Textpattern and put it in your web directory

cd ~
wget https://textpattern.com/file_download/118/textpattern-4.8.8.zip
unzip textpattern-4.8.8.zip
cd textpattern-4.8.8
sudo mkdir /var/www/[domain]
sudo cp -r * /var/www/[domain]
cd ..
rm -rf textpattern-4.8.8.zip textpattern-4.8.8
sudo touch /var/www/[domain]/error.html
sudo chown -R www-data:www-data /var/www/[domain]
sudo chmod -R 755 /var/www/[domain]

Finish setting up Textpattern

Visit [domain]/textpattern/setup in your browser and answer all the questions.

After you have worked your way through the setup process run the following two commands and add all the values shown in your browser. Make sure to uncomment the protocol line at the end of the file too!

sudo mv /var/www/[domain]/textpattern/config-dist.php /var/www/[domain]/textpattern/config.php
sudo nano /var/www/[domain]/textpattern/config.php

Lastly, delete the setup directory and login to the Textpattern administrator panel. Now navigate to the Admin - Diagnostics section and check for errors.

Conclusion

You should now have a fully working copy of Textpattern. Have fun playing with it and learning how to create your next great site!