開源軟體

BookStack 開源知識管理平台
開源wiki系統

BookStack 架設
運行環境 

 

 PVE 

 LXC 

 Debian 12 

 

 安裝nginx mariadb 

 apt update 

 apt -y install nginx mariadb-server unzip git 

 systemctl enable nginx && systemctl start nginx

systemctl enable mariadb && systemctl start mariadb 

 資料庫設定 

 mariadb -u root -p 

CREATE DATABASE IF NOT EXISTS bookstackdb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 

GRANT ALL PRIVILEGES ON bookstackdb.* TO 'bookstackuser'@'localhost' IDENTIFIED BY 'bookstackpass' WITH GRANT OPTION; 

FLUSH PRIVILEGES; 

 

 安裝PHP 8.4 

 apt install -y lsb-release ca-certificates apt-transport-https software-properties-common 

 wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg 

 echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list 

 apt update && apt install curl php8.4 php8.4-{common,mbstring,fpm,mysql,gd,cli,opcache,curl,ldap,odbc,xmlrpc,soap,intl,zip,tidy,xml} -y 

 修改 /etc/php/8.4/fpm/php.ini 設定 

 sed -i "s|^;cgi.fix_pathinfo=1.*$|cgi.fix_pathinfo=0|" /etc/php/8.4/fpm/php.ini

sed -i "s|^;cgi.fix_pathinfo=1.*$|cgi.fix_pathinfo=0|" /etc/php/8.4/cli/php.ini

sed -i "s|^;date.timezone =.*$|date.timezone = Asia/Taipei|" /etc/php/8.4/fpm/php.ini

sed -i "s|^;date.timezone =.*$|date.timezone = Asia/Taipei|" /etc/php/8.4/cli/php.ini

sed -i "s|^upload_max_filesize = 2M.*$|upload_max_filesize = 50M|" /etc/php/8.4/fpm/php.ini

sed -i "s|^upload_max_filesize = 2M.*$|upload_max_filesize = 50M|" /etc/php/8.4/cli/php.ini

sed -i "s|^post_max_size = 8M.*$|post_max_size = 200M|" /etc/php/8.4/fpm/php.ini

sed -i "s|^post_max_size = 8M.*$|post_max_size = 200M|" /etc/php/8.4/cli/php.ini

sed -i "s|^memory_limit = 128M.*$|memory_limit = 512M|" /etc/php/8.4/fpm/php.ini

sed -i "s|^memory_limit = -1.*$|memory_limit = 512M|" /etc/php/8.4/cli/php.ini

sed -i "s|^max_execution_time = 30.*$|max_execution_time = 600|" /etc/php/8.4/fpm/php.ini

sed -i "s|^max_execution_time = 30.*$|max_execution_time = 600|" /etc/php/8.4/cli/php.ini

sed -i "s|^max_input_time = 60.*$|max_input_time = 600|" /etc/php/8.4/fpm/php.ini

sed -i "s|^max_input_time = 60.*$|max_input_time = 600|" /etc/php/8.4/cli/php.ini

sed -i "s|^default_socket_timeout = 60.*$|default_socket_timeout = 600|" /etc/php/8.4/fpm/php.ini

sed -i "s|^default_socket_timeout = 60.*$|default_socket_timeout = 600|" /etc/php/8.4/cli/php.ini 

 在 /etc /php/8.4/fpm/pool.d/www.conf  新增設定 

 確認以下設定正確

user = www-data

group = www-data

listen.owner = www-data

listen.group = www-data

listen.mode = 0660

#listen.mode註解打開

最後一行增加

php_value[session.save_path] = /var/www/html/sessions 

 systemctl start php8.4-fpm && systemctl enable php8.4-fpm 

 設定 /etc/nginx/nginx.conf 

 http區塊加入

client_body_timeout 120s;

client_max_body_size 100M; 

 建立 /etc/nginx/conf.d/bookstack.conf 

 server {

 listen 80;

 listen [::]:80;

 server_name _;

 root /var/www/html/bookstack/public;

 index index.php index.html;

 location / {

 try_files $uri $uri/ /index.php?$query_string;

 }

 

 location ~ \.php$ {

 include fastcgi_params;

 fastcgi_pass unix:/run/php/php8.4-fpm.sock;

 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

 }

} 

 BookStack下載安裝 

 

 安裝Composer 

 

 cd /usr/local/bin

curl -sS https://getcomposer.org/installer | php

mv composer.phar composer 

 

 新增目錄安裝 

 

 mkdir -p /var/www/html 

 

cd /var/www/html 

mkdir /var/www/html/sessions

git clone https://github.com/BookStackApp/BookStack.git --branch release --single-branch

cd BookStack && composer install --no-dev 

 

 BookStack 設定 

 

 cp .env.example .env

修改 .env 

#APP_URL=先設定空白

APP_URL=

DB_HOST=localhost

DB_DATABASE=bookstackdb

DB_USERNAME=bookstackuser

DB_PASSWORD=bookstackpass 

 php artisan key:generate --force 

chown -R www-data:www-data /var/www/html/{BookStack,sessions} 

php artisan migrate --force 

   

 

 設定完成輸入 http://ip ，預設帳密admin@admin.com、password 

 

 

 

 參考相關網頁 

 BUBU知識庫

BookStack 改為子目錄
BookStack設定 

 cd /var/www/html/bookstack

nano .env

修改為子目錄

APP_URL=http://ip/bookstack 

   

 NGINX設定 

 修改 /etc/nginx/conf.d/bookstack.conf 

 server {

 listen 8080;

 listen [::]:8080;

 server_name _;

 root /var/www/html/bookstack/public;

 index index.php index.html;

 location / {

 try_files $uri $uri/ /index.php?$query_string;

 }

 location ~ \.php$ {

 include fastcgi_params;

 fastcgi_pass unix:/run/php/php8.4-fpm.sock;

 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

 }

}

server {

 listen 80;

 listen [::]:80;

 server_name _;

 root /var/www/html;

 index index.html;

 location /bookstack/ {

 proxy_pass http://localhost:8080/;

 proxy_redirect off;

 }

 

} 

 nginx -t

service nginx restart 

 http://ip/bookstack

BookStack - SSL設定
運行環境 

 

 使用反向代理主機 

 

 反向代理主機設定 

 location /bookstack/ {

 client_max_body_size 50M;

 proxy_pass http://bookstack主機ip/bookstack/;

 } 

 BookStack主機設定 

 進入bookstack目錄

cd /var/www/html/bookstack

更新網址

php artisan bookstack:update-url <oldUrl> <newUrl>

清除快取

php artisan cache:clear

編輯.env

APP_URL=https://xxx.com/bookstack 

 瀏覽器輸入 https://xxx.com/bookstack

BookStack 備份還原
備份 

 透過 mysqldump 備份資料庫 

 # Example

mysqldump -u user bookstack > bookstack.backup.sql

mysqldump -u 使用者 -p 資料庫名稱 > 資料庫名稱.backup.sql 

 文件 

 以下是包含應備份資料的檔案和資料夾清單。 

 

 .env - 文件，包含重要的設定資訊。 

 public/uploads - 資料夾，包含所有上傳的圖像。 

 storage/uploads - 資料夾，包含上傳的頁面附件。 

 themes - 資料夾，包含任何已配置的視覺/邏輯主題。 

 

 或者，您可以備份整個 BookStack 資料夾，但預設只有上述資料夾包含重要的特定於實例的資料。 

 tar -czvf bookstack-files-backup.tar.gz .env public/uploads storage/uploads themes 

 打包整個BookStack 

 tar -czvf bookstack-files-backup.tar.gz bookstack 

 還原 

 先重新安裝BookStack後再還原備份檔案 

 資料庫還原 

 # Example

mysql -u root -p bookstack < bookstack.backup.sql

mysql -u 使用者 -p 資料庫名稱 < 資料庫名稱.backup.sql 

 還原備份檔 

 tar -xvzf bookstack-files-backup.tar.gz 

 更新URL 

 

 在設定檔中 .env 更新 APP_URL 值以完全符合您的新基本 URL。 

 執行 「更新系統 URL」命令 來更新資料庫內容以使用新的 URL。 

 

 # Searches for <oldUrl> and replaces it with <newUrl>

php artisan bookstack:update-url <oldUrl> <newUrl>

# Example:

php artisan bookstack:update-url http://docs.example.com https://demo.bookstackapp.com 

   

   

  

OpenVPN Server 使用帳號密碼驗證登入
Server 設定 

 編輯設定檔 /etc/openvpn/server/server.conf 

 client-cert-not-required

auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env

username-as-common-name

script-security 3 

 client-cert-not-required 不使用證書認證

auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env 使用驗證腳本

username-as-common-name 使用帳密認證

script-security 3 安全級別 

 建立驗證腳本 /etc/openvpn/checkpsw.sh 

 #!/bin/sh

###########################################################

# checkpsw.sh (C) 2004 Mathias Sundman <mathias@openvpn.se>

#

# This script will authenticate OpenVPN users against

# a plain text file. The passfile should simply contain

# one row per user with the username first followed by

# one or more space(s) or tab(s) and then the password.

PASSFILE="/etc/openvpn/psw-file"

LOG_FILE="/var/log/openvpn/openvpn-password.log"

TIME_STAMP=`date "+%Y-%m-%d %T"`

###########################################################

if [ ! -r "${PASSFILE}" ]; then

 echo "${TIME_STAMP}: Could not open password file \"${PASSFILE}\" for reading." >> ${LOG_FILE}

 exit 1

fi

CORRECT_PASSWORD=`awk '!/^;/&&!/^#/&&$1=="'${username}'"{print $2;exit}' ${PASSFILE}`

if [ "${CORRECT_PASSWORD}" = "" ]; then

 echo "${TIME_STAMP}: User does not exist: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}

 exit 1

fi

if [ "${password}" = "${CORRECT_PASSWORD}" ]; then

 echo "${TIME_STAMP}: Successful authentication: username=\"${username}\"." >> ${LOG_FILE}

 exit 0

fi

echo "${TIME_STAMP}: Incorrect password: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}

exit 1 

 chmod +x /etc/openvpn/checkpsw.sh 

 帳號密碼管理清單 /etc/openvpn/psw-file 

 user1 pswd1

user2 pswd2 

   

 chmod 777 /etc/openvpn/psw-file

chown root.root /etc/openvpn/* -R 

 Client 設定 

 設定檔註解或移除client.crt client.key，保留ca，新增auth-user-pass