Tutorial-9122023

How to Install Bolt CMS with Nginx and Let’s Encrypt on FreeBSD 12

How to Install Bolt CMS with Nginx and Let’s Encrypt on FreeBSD 12

Bolt is a sophisticated, lightweight and simple CMS built with PHP. It is released under the open-source MIT-license and source code is hosted as a public repository on Github. A bolt is a tool for Content Management, which strives to be as simple and straightforward as possible. It is quick to set up, easy to configure, uses elegant templates. Bolt is created using modern open-source libraries and is best suited to build sites in HTML5 with modern markup. In this tutorial, we will go through the Bolt CMS installation on FreeBSD 12 system by using Nginx as a web server, MySQL as a database server, and optionally you can secure the transport layer by using acme.sh client and Let’s Encrypt certificate authority to add SSL support.

Requirements

The system requirements for Bolt are modest, and it should run on any fairly modern web server:

  • PHP version 5.5.9 or higher with the following common PHP extensions: pdo, mysqlnd, pgsql, openssl, curl, gd, intl, json, mbstring, opcache, posix, xml, fileinfo, exif, zip.
  • Access to SQLite (which comes bundled with PHP), or MySQL or PostgreSQL.
  • Apache with mod_rewrite enabled (.htaccess files) or Nginx (virtual host configuration covered below).
  • A minimum of 32MB of memory allocated to PHP.

Prerequisites

  • An operating system running FreeBSD 12.
  • A non-root user with sudo privileges.

Initial steps

Check your FreeBSD version:
uname -ro
# FreeBSD 12.0-RELEASE

Set up the timezone:
tzsetup

Update your operating system packages (software). This is an important first step because it ensures you have the latest updates and security fixes for your operating system’s default software packages:
freebsd-update fetch install
pkg update && pkg upgrade -y

Install some essential packages that are necessary for basic administration of FreeBSD 12.0 operating system:
pkg install -y sudo vim unzip wget bash

Step 1 – Install MySQL and create a database for Bolt

Bolt supports MySQL, MariaDB, PostgreSQL and SQLite databases. In this tutorial, we will use MySQL as a database server.

Install MySQL database server:
sudo pkg install -y mysql57-server

Check MySQL version:
mysql --version
# mysql  Ver 14.14 Distrib 5.7.27, for FreeBSD12.0 (amd64) using  EditLine wrapper

Enable and start MySQL service:
sudo sysrc mysql_enable="yes"
sudo service mysql-server start

Run mysql_secure installation script to improve MySQL security and set the password for MySQL root user:
sudo mysql_secure_installation

Answer each of the questions:
Would you like to setup VALIDATE PASSWORD plugin? N
New password: your_secure_password
Re-enter new password: your_secure_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

Connect to MySQL shell as the root user:
sudo mysql -u root -p
# Enter password

Create an empty MySQL database and user for Bolt and remember the credentials:
CREATE DATABASE dbname;
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

Exit from MySQL:
exit

Replace dbname, username and password with your own names.

Step 2 – Install PHP and necessary PHP extensions

Install PHP, as well as the necessary PHP extensions:
sudo pkg install -y php72 php72-ctype php72-curl php72-dom php72-hash php72-iconv php72-gd php72-json php72-mbstring php72-openssl php72-session php72-simplexml php72-xml php72-zip php72-zlib php72-pdo php72-pdo_mysql php72-mysqli php72-filter php72-ftp php72-tokenizer php72-calendar php72-pecl-APCu php72-opcache php72-sqlite3 php72-pdo_sqlite php72-intl php72-posix

Check the PHP version:
php --version

# PHP 7.2.22 (cli) (built: Sep 7 2019 01:12:40) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
# with Zend OPcache v7.2.22, Copyright (c) 1999-2018, by Zend Technologies

Enable and start PHP-FPM service:
sudo sysrc php_fpm_enable=yes
sudo service php-fpm start

We can move on to the next step, which is obtaining free SSL certs from Let’s Encrypt CA.

Step 3 – Install acme.sh client and obtain Let’s Encrypt certificate (optional)

Securing your website with HTTPS is not necessary, but it is a good practice to secure your site traffic. In order to obtain a TLS certificate from Let’s Encrypt we will use Acme.sh client. Acme.sh is a pure UNIX shell software for obtaining TLS certificates from Let’s Encrypt with zero dependencies. 

Download and install Acme.sh:
sudo pkg install -y acme.sh

Check Acme.sh version:
acme.sh --version
# v2.8.2

Obtain RSA and ECC/ECDSA certificates for your domain/hostname:

# RSA
sudo acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --keylength 2048
# ECDSA
sudo acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --keylength ec-256

After running the above commands, your certificates and keys will be in:

  • For RSA: /etc/letsencrypt/example.com directory.
  • For ECC/ECDSA: /etc/letsencrypt/example.com_ecc directory.

Step 3 – Install NGINX and configure NGINX for Bolt CMS

Bolt CMS can work fine with many popular web server software. In this tutorial, we selected Nginx. 

Download and install the latest mainline release of Nginx from the FreeBSD repository:
sudo pkg install -y nginx-devel

Check the Nginx version:
nginx -v
# nginx version: nginx/1.17.1

Enable and start Nginx:
sudo sysrc nginx_enable=yes
sudo service nginx start

Configure Nginx for Bolt by running:
sudo vim /usr/local/etc/nginx/bolt.conf

And populate the file with the following configuration:
server {

listen 80;
listen 443 ssl;
server_name example.com;
root /usr/local/www/bolt/public;
index index.php;

# RSA
ssl_certificate /etc/letsencrypt/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/example.com/private.key;
# ECC
ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/example.com_ecc/private.key;

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

location = /bolt {
try_files $uri /index.php?$query_string;
}

location ^~ /bolt/ {
try_files $uri /index.php?$query_string;
}

location ~ /index.php/(.*) {
rewrite ^/index.php/(.*) /$1 permanent;
}

location ~ /. { deny all; }
location ~ /.(htaccess|htpasswd)$ { deny all; }
location ~ /.(?:db)$ { deny all; }
location ~* /(.*).(?:markdown|md|twig|yaml|yml)$ { deny all; }

location ~ [^/].php(/|$) {
include fastcgi_params;
fastcgi_split_path_info ^(.+?.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_PROXY "";
fastcgi_param HTTPS $https if_not_empty;
fastcgi_pass 127.0.0.1:9000;
}

}

NOTE: For complete and production-ready Nginx config for Bolt CMS check out https://docs.bolt.cm/3.6/installation/webserver/nginx.

Run sudo vim /usr/local/etc/nginx/nginx.conf and add the below line to http {} block to include Bolt config.
include bolt.conf;

Check Nginx configuration for syntax errors:
sudo nginx -t

Reload Nginx service:
sudo service nginx reload

Step 5 – Install Bolt CMS

Create /usr/local/www directory:
sudo mkdir -p /usr/local/www

Navigate to /usr/local/www directory:
cd /usr/local/www

Download the latest release Bolt CMS via wget and unzip it:
sudo wget https://bolt.cm/distribution/bolt-latest.zip && sudo unzip bolt-latest.zip

Remove downloaded bolt-latest.zip file:
sudo rm bolt-latest.zip

Rename the bolt-v3.6.10 directory to just bolt:
sudo mv bolt-v3.6.10 bolt

Navigate to /usr/local/www/bolt directory:
cd /usr/local/www/bolt

To finish the installation you will need to rename the following files:
sudo mv .bolt.yml.dist .bolt.yml
sudo mv composer.json.dist composer.json
sudo mv composer.lock.dist composer.lock
sudo mv src/Site/CustomisationExtension.php.dist src/Site/CustomisationExtension.php

Change ownership of the /usr/local/www/bolt directory to www user:
sudo chown -R www:www /usr/local/www/bolt

Navigate to the folder where you uploaded Bolt in your web browser and follow the instructions on the screen.

Step 6 – Complete the Bolt CMS Installation and Setup

After opening your site in a web browser, you should be redirected to the following page:

Set admin username in Bolt CMS

Fill in the required information to create a user and click the “Create the first user” button to continue. After that Bolt CMS admin interface should show up:

Bolt CMS Dashboard

Bolt CMS installation is now finished. To access Bolt CMS admin append /bolt to your site IP or domain.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !