Rocky Linux 安装 Bookstack
一、概要
1. 概念
与Wiki.js类似,Bookstack也是一款知识管理系统(KMS),由PHP实现。在免费开源的KMS中,Bookstack是最像Confluence的一个。
2. 环境
(1) Rocky Linux 9.1
(2) Bookstack 23.02.1
(3) PHP 8.0.27
3. 目录
sudo mkdir -p /opt/BookStack
sudo mkdir -p /opt/BookStack/certs sudo mkdir -p /var/opt/BookStack/logs
4. 依赖
(1) epel-release
(2) 关闭Selinux
(3) unzip
sudo dnf install unzip -y
二、安装
1. PHP
(1) php
sudo dnf info php sudo dnf install php -y php -v
(2) php extensions
sudo dnf install -y php-openssl php-pdo php-mbstring php-iconv php-tokenizer php-gd php-mysqlnd php-xml php-dom php-ldap php-fpm
(3) 配置/etc/php.ini
sudo vi /etc/php.ini
按下ESC键,输入
:/cgi.fix_pathinfo
回车。改为:
cgi.fix_pathinfo=0
此外,还可以按需修改以下项目:
date.timezone = Asia/Shanghai ;时区 upload_max_filesize = 60M ;上传单一文件最大Size post_max_size = 200M ;POST请求最大数据量 memory_limit = 512M ;内存用量限制 max_execution_time = 600 ;脚本执行时间上限,单位为秒 max_input_time = 600 ;脚本处理输入数据时间上限,单位为秒; default_socket_timeout = 600 ;Socket链接无回应时长,单位为秒;
2. PHP-FPM
(1) 配置/etc/php-fpm.d/www.conf
sudo vi /etc/php-fpm.d/www.conf
a. 注意这里的listen属性对应的值,它用于接受CGI请求,这个参数非常重要,在之后配置nginx的时候也需要用到。
b. 按需修改以下内容:user = nginx
group = nginx
... listen = /run/php-fpm/www.sock
... listen.owner = nginx listen.group = nginx listen.mode = 0660
移除以下配置行之前的注释符号:
env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
(2) 启动PHP-FPM
sudo systemctl enable --now php-fpm systemctl status php-fpm
3. PHP Composer
(1) 安装
cd ~/ curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
(2) 测试
composer -V
4. 数据库
(1) 登录MySQL
mysql -u root -p
(2) 数据库
create database if not exists bookstack default character set UTF8MB4;
(3) 用户
CREATE USER 'bsuser'@'%' IDENTIFIED BY 'MyNewPass1!'; GRANT ALL PRIVILEGES ON *.* TO 'bookstack'@'%' WITH GRANT OPTION; flush privileges;
5. Bookstack
(1) 下载
a. Git下载(需要首先安装Git)
cd /opt/BookStack git clone https://github.com/BookStackApp/BookStack.git --branch release --single-branch
b. 源码下载
查找最新版本: https://github.com/BookStackApp/BookStack/releases
cd ~/Download wget https://github.com/BookStackApp/BookStack/archive/refs/tags/v23.02.1.tar.gz
(2) 解压
sudo tar -xvf 23.02.1.tar.gz --strip-components=1 -C /opt/BookStack
(3) 安装
cd /opt/BookStack composer install
6. Nginx
(1) 安装
(2) 授权
sudo chown -R nginx:nginx /opt/BookStack sudo chmod -R 755 /opt/BookStack sudo chown -R nginx:nginx /var/opt/BookStack sudo chmod -R 755 /var/opt/BookStack
三、配置
1. 配置文件
(1) 初始化
cp /opt/BookStack/.env.example /opt/BookStack/.env
(2) 生成应用Key
sudo cd /opt/BookStack
sudo php artisan key:generate
2. 数据库
(1) 编辑
sudo vi /opt/BookStack/.env
(2) 配置
DB_HOST=10.8.0.6 DB_DATABASE=bookstack DB_USERNAME=bkuser DB_PASSWORD=MyNewPass1!
(3) 初始化数据库
sudo php artisan migrate
运行之后:
打开数据库,会发现新建了许多表:
3. 证书
(1) 生成证书参考:OpenSSL 系列2 --- 应用
(2) 准备
sudo mv -f /etc/pki/CA/certs/bookstack.example.com.crt.pem /opt/BookStack/certs sudo mv -f /etc/pki/CA/private/key.pem /opt/BookStack/certs
4. Nginx
假设我们希望使用二级域名bookstack.example.com来访问BookStack程序。
(1) 配置文件
sudo vi /etc/nginx/conf.d/bookstack.conf
(2) 初始化
server { listen 80; server_name bookstack.example.com; rewrite ^(.*)$ https://${server_name}$1 permanent; } server { listen 443 ssl; listen [::]:443 ssl ipv6only=on; server_name .bookstack.example.com; root /opt/BookStack/public; index index.php; ssl_certificate /opt/BookStack/certs/bookstack.example.com.crt.pem; ssl_certificate_key /opt/BookStack/certs/key.pem; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_session_tickets on; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_ciphers 'TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5'; ssl_prefer_server_ciphers on; access_log /var/opt/BookStack/logs/access.log; error_log /var/opt/BookStack/logs/error.log; client_max_body_size 1G; fastcgi_buffers 64 4K; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README) { deny all; } location ~ \.php(?:$|/) { fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_pass unix:/var/run/php-fpm/www.sock; } location ~* \.(?:ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { expires 30d; access_log off; } }
(3) 启动
关闭Selinux
sudo systemctl enable --now nginx systemctl status nginx
(4) 测试
a. 访问 https://bookstack.example.com
b. 使用系统默认账号登录
uid: admin@admin.com pwd: password
5. LDAP
参考: https://www.bookstackapp.com/docs/admin/ldap-auth/
四、备份与恢复
1. 备份
(1) 数据库备份参考:MySQL Backup
(2) 文件备份:
a. .env: 配置文件;
b. public/uploads: 用户上传的图片;
c. storage/uploads: 用户上传的附件;
将文件压缩打包:
tar -czvf bookstack-files-backup.tar.gz .env public/uploads storage/uploads
2. 恢复
(1) 数据库恢复:
a. 如果BookStack的版本没有改变,则数据库恢复后直接配置链接即可;
b. 如果BookStack的版本被升级了,则新版本可能针对数据库有所更新,需要执行:
php artisan migrate
然后从原有数据库中将数据导入到新的数据库中。
(2) 将备份文件解压:
tar -xvzf bookstack-files-backup.tar.gz
(3) 恢复文件:
sudo mv -f .env /opt/BookStack
sudo mv -f public/uploads /opt/BookStack/public/uploads
sudo mv -f storage/uploads /opt/BookStack/storage/uploads
五、参考
1. 官方
https://www.bookstackapp.com/docs/admin/installation/
https://www.php.net/manual/en/extensions.alphabetical.php
https://www.bookstackapp.com/docs/admin/ldap-auth/
https://www.bookstackapp.com/docs/admin/filesystem-permissions/
2. 其他
https://www.howtoforge.com/tutorial/centos-bookstack-nginx/
https://dzone.com/articles/how-to-install-bookstack-on-centos-7
https://deviant.engineer/2017/02/bookstack-centos7/
3. PHP-FPM