Bookmark

Self-Host BookStack on Linux

BookStack is a self-hosted wiki platform for organizing HomeLab documentation. This article adapts the complete Linux installation flow from i12bretro, including Apache, MariaDB, PHP, Composer, the .env file, and the Apache site configuration. Example credentials from the source are replaced with placeholders; generate your own secrets during deployment.

Source reference: i12bretro – Install BookStack on Linux . The original video belongs to i12bretro on YouTube .

Youtube video player

Requirements

  • A Linux host with sudo access.
  • A hostname or domain for BookStack.
  • MariaDB, Apache, and PHP compatible with the BookStack release being installed.
  • A separate database password and an app key generated by Artisan.

Install the base packages

  1. Log into the Linux host.
  2. Update the package list:
1
sudo apt update
  1. Install available updates:
1
sudo apt upgrade -y
  1. Install the required tools:
1
sudo apt install git openssl curl wget zip composer -y
  1. Install Apache and MariaDB:
1
sudo apt install apache2 mariadb-server mariadb-client -y
  1. Install PHP and the extensions commonly required by BookStack:
1
sudo apt install php libapache2-mod-php php-curl php-tokenizer php-ldap php-cli php-json php-gd php-mbstring php-mysql php-xml php-zip php-bcmath -y

Secure MariaDB

  1. Start the MariaDB security wizard:
1
sudo mysql_secure_installation
  1. Press Enter at the root login prompt if the installation does not yet have a root password.
  2. Choose Y to set a root password and enter it twice. Never put the real password in this article, logs, or Git.
  3. Choose Y to remove anonymous users.
  4. Choose Y to disallow remote root login.
  5. Choose Y to remove the test database.
  6. Choose Y to reload privilege tables.
  7. Log into MariaDB:
1
mysql -u root -p
  1. Enter the root password created earlier.
  2. Create a dedicated BookStack database and user. Replace [DB_PASSWORD] with a secret stored outside the repository:
1
2
3
4
CREATE DATABASE bookstack;
GRANT ALL ON bookstack.* TO 'bookstack_rw'@'localhost' IDENTIFIED BY '[DB_PASSWORD]';
FLUSH PRIVILEGES;
EXIT;
  1. Exit the shell if necessary:
1
exit

Download BookStack and create the environment file

  1. Clone the release branch into /var/www/bookstack:
1
sudo git clone https://github.com/BookStackApp/BookStack.git --branch release --single-branch /var/www/bookstack
  1. Copy the sample environment file:
1
sudo cp /var/www/bookstack/.env.example /var/www/bookstack/.env
  1. Open the configuration file:
1
sudo nano /var/www/bookstack/.env
  1. Adjust the main variables below. Do not use sample passwords, mail hosts, or app keys:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
APP_ENV=production
APP_DEBUG=false
APP_KEY=
APP_URL=http://DNSorIP/bookstack
APP_TIMEZONE=Asia/Ho_Chi_Minh
APP_LOCALE=en

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=bookstack
DB_USERNAME=bookstack_rw
DB_PASSWORD=[DB_PASSWORD]

MAIL_DRIVER=smtp
MAIL_HOST=[SMTP_HOST]
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDR=bookstack@[YOUR_DOMAIN]
MAIL_FROM_NAME='BookStack'
MAIL_REPLYTO_ADDR=bookstack@[YOUR_DOMAIN]
MAIL_REPLYTO_NAME='BookStack'
MAIL_AUTO_EMBED_METHOD='attachment'
  1. Set APP_URL to the real URL. Use https:// when the site is served through HTTPS.
  2. Press Ctrl+O, Enter, then Ctrl+X to save and close nano.

Install dependencies and generate the app key

  1. Set the BookStack directory owner:
1
sudo chown -R www-data:www-data /var/www/bookstack
  1. Create the Composer working directory and assign its owner:
1
2
sudo mkdir /var/www/.composer
sudo chown -R www-data:www-data /var/www/.composer
  1. Change into the BookStack directory:
1
cd /var/www/bookstack
  1. Install production dependencies:
1
sudo -u www-data composer install --no-dev --no-plugins
  1. Generate the app key with Artisan:
1
sudo php artisan key:generate --no-interaction --force
  1. Run the database migration:
1
sudo php artisan migrate --no-interaction --force
  1. Open the Apache site configuration:
1
sudo nano /etc/apache2/sites-available/bookstack.conf
  1. Add the following configuration and adjust the path/domain if using a different deployment path:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Alias /bookstack "/var/www/bookstack/public"
<Directory /var/www/bookstack/public>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews -Indexes
        </IfModule>

        RewriteEngine On

        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]

        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
</Directory>
  1. Press Ctrl+O, Enter, then Ctrl+X to save the file.
  2. Enable rewrite, enable the BookStack site, and restart Apache:
1
2
3
sudo a2enmod rewrite
sudo a2ensite bookstack
sudo systemctl restart apache2

Complete the Web Installer

  1. Open http://DNSorIP/bookstack.
  2. Use the default first-login information only when confirmed by the BookStack version documentation; immediately replace it with a unique account and password.
  3. Open the user dropdown in the top-right corner and select My Account.
  4. Update the username and email, then click Save.
  5. Select Access & Security in the left navigation.
  6. Enter and confirm a new password, then click Update.
  7. Open the user dropdown and select Logout.
  8. Log in again with the updated email and password.
  9. Verify that BookStack can read the database, write uploads, and load the wiki pages.

Operations note: Enable HTTPS, back up both the database and /var/www/bookstack, protect .env, disallow remote MariaDB root login, and test compatibility before updating the release branch.

Source and video


0 Bình luận

Góp Ý / Bình Luận / Đánh giá