Skip to main content

Manual Installation on Debian 11

For this guide, I am will be using NGINX as the webserver, MariaDB as the database, and PHP version 8,1

Install Utilities and Update System

We will begin by installing some basic utilities that are not included as part of the default Debian 11 installation.

sudo apt install gnupg git unzip curl 

Screenshot 2022-09-17 000552.png

Make sure the Debian 11 install is up to date.

sudo apt update && sudo apt upgrade -y

Screenshot 2022-09-17 001043.png

Install NGINX

sudo apt install nginx

Screenshot 2022-09-17 000947.png

Start NGINX at boot

sudo systemctl enable nginx

Screenshot 2022-09-17 001151.png

Install MariaDB

sudo apt install mariadb-server mariadb-client

Screenshot 2022-09-17 001402.png

Start MariaDB at boot

sudo systemctl enable mariadb

Screenshot 2022-09-17 001512.png

Install PHP 8.1

Add the PHP 8.1 Repository and update afterwards

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
sudo apt update

Screenshot 2022-09-17 001804.png

Install PHP 8.1 and the required PHP packages for BookStack

sudo apt install php8.1 php8.1-{curl,mbstring,ldap,xml,zip,gd,mysql,fpm}

Screenshot 2022-09-17 002116.png

Start PHP FPM at boot

sudo systemctl enable php8.1-fpm

Screenshot 2022-09-17 002225.png

Create BookStack Database

Run the following command to create the BookStack Database. Replace YOUR-SUPER-STRONG-PASSWORD with an actual, strong password. This password will be needed for the BookStack application to connect to the database.

You may change the Database name and database user name to suit your need.

sudo mysql -u root --execute="CREATE DATABASE bookstack;"
sudo mysql -u root --execute="CREATE USER 'bookstack'@'localhost' IDENTIFIED WITH mysql_native_password AS PASSWORD('YOUR-SUPER-STRONG-PASSWORD');"
sudo mysql -u root --execute="GRANT ALL ON bookstack.* TO 'bookstack'@'localhost';FLUSH PRIVILEGES;"

Screenshot 2022-09-17 002822.png

Secure your local MariaDB instance by running the mysql_secure_installation script.

sudo mysql_secure_installation

Choose the following for the questions:

Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] y
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

Screenshot 2022-09-17 003539.png

Install Composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Screenshot 2022-09-17 003801.png

sudo mv composer.phar /usr/local/bin/composer

Screenshot 2022-09-17 003939.png

Install BookStack

Change directory into /var/www/ and clone the repository from GitHub

cd /var/www/
sudo git clone https://github.com/BookStackApp/BookStack.git --branch release --single-branch

Screenshot 2022-09-17 004246.png

cd BookStack
sudo composer install --no-dev

Screenshot 2022-09-17 004727.png

Copy the default .env config file.

sudo cp .env.example .env

Use your preferred text editor, edit the .env file and fill out the database information.

Screenshot 2022-09-17 005151.png

Screenshot 2022-09-17 005924.png

Make sure the storage, bootstrap/cache, and public/uploads folders are accessible by the web-server user, www-data

sudo chown -R www-data:www-data storage bootstrap/cache public/uploads

Screenshot 2022-09-17 005403.png

Generate the application key

sudo php artisan key:generate

Screenshot 2022-09-17 005722.png

Update the BookStack database

sudo php artisan migrate

Screenshot 2022-09-17 010012.png

Create NGINX Config

Screenshot 2022-09-17 154255.png

Using your preferred text editor, create a new nginx file at /etc/nginx/sites-available/ , and copy the following configuration in it. Make sure to change the server_name and the SSL cert locations.

server {
  #This config is for HTTPS setup
  listen 443 ssl;
  server_name your_servers_name.domain.com;

  #SSL Cert Location
  ssl_certificate /etc/ssl/certs/self-sign-SSL-or-public-ssl.crt;
  ssl_certificate_key /etc/ssl/private/self-sign-SSL-or-public-ssl.key;
  
  #Force strong TLS
  ssl_protocols      TLSv1.3;
  ssl_prefer_server_ciphers   on;
  #Disable weak ciphers
  ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA HIGH !RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS";

  #Increase Upload Size
  client_max_body_size 12M;

  root /var/www/BookStack/public;
  index index.php index.html;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }
  
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;
  }
}
sudo ln -s /etc/nginx/sites-available/bookstack /etc/nginx/sites-enabled/bookstack

Test the config file.

sudo nginx -t

Screenshot 2022-09-17 155118.png

Restart the NGINX service

sudo systemctl restart nginx

That's it! Open up the web-browser, and head over to the server's IP or FQDN, and you will see the default BookStack login page.

Screenshot 2022-09-17 155624.png