BookStack Documentation Platform Installation
BookStack is an elegant, open-source platform for storing and organizing documentation. Built on Laravel and PHP, BookStack provides a clean interface for creating, organizing, and sharing documentation within teams and organizations. This guide covers PHP setup, Laravel configuration, MySQL database setup, Nginx installation, LDAP authentication, and production deployment.
Table of Contents
- Prerequisites
- System Requirements
- PHP Installation
- Database Setup
- BookStack Installation
- Nginx Configuration
- SSL Certificate Configuration
- Initial Configuration
- LDAP Authentication
- Backup and Updates
- Conclusion
Prerequisites
Ensure you have:
- Ubuntu 20.04 LTS or later
- Root or sudo access
- A registered domain name
- Minimum 2GB RAM (4GB+ recommended)
- 15GB available disk space
- Basic Linux administration knowledge
Update system packages:
sudo apt update && sudo apt upgrade -y
System Requirements
Verify system specifications:
Check OS version:
cat /etc/os-release
uname -m
Check available resources:
free -h
df -h
Install required system packages:
sudo apt install -y curl wget git build-essential unzip
PHP Installation
Install PHP 8.0 or later with required extensions:
sudo apt install -y php php-common php-cli php-fpm php-mysql php-xml php-mbstring php-json php-curl php-gd php-intl php-zip php-ldap php-opcache
Verify PHP version:
php --version
Verify extensions:
php -m | grep -E "mysql|xml|mbstring|json|curl|gd|intl|zip|ldap"
Configure PHP:
sudo nano /etc/php/8.0/fpm/php.ini
Update settings:
memory_limit = 256M
max_execution_time = 300
post_max_size = 100M
upload_max_filesize = 100M
date.timezone = UTC
Restart PHP-FPM:
sudo systemctl restart php8.0-fpm
Database Setup
Install MySQL Server:
sudo apt install -y mysql-server
Start and enable MySQL:
sudo systemctl start mysql
sudo systemctl enable mysql
Secure MySQL:
sudo mysql_secure_installation
Create BookStack database:
sudo mysql -u root -p << EOF
CREATE DATABASE bookstack CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'bookstack'@'localhost' IDENTIFIED BY 'SecurePassword123!';
GRANT ALL PRIVILEGES ON bookstack.* TO 'bookstack'@'localhost';
FLUSH PRIVILEGES;
EXIT;
EOF
Test connection:
mysql -u bookstack -p -h localhost bookstack
EXIT;
BookStack Installation
Create web root directory:
sudo mkdir -p /var/www/bookstack
sudo chown -R www-data:www-data /var/www/bookstack
cd /var/www/bookstack
Download latest BookStack release:
cd /tmp
wget https://github.com/BookStackApp/BookStack/releases/download/v22.06.2/BookStack-v22.06.2.tar.gz
tar -xzf BookStack-v22.06.2.tar.gz
sudo cp -r BookStack-v22.06.2/* /var/www/bookstack/
Set correct permissions:
sudo chown -R www-data:www-data /var/www/bookstack
sudo find /var/www/bookstack -type f -exec chmod 644 {} \;
sudo find /var/www/bookstack -type d -exec chmod 755 {} \;
sudo chmod -R 755 /var/www/bookstack/bootstrap
sudo chmod -R 755 /var/www/bookstack/storage
Install Composer:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
Install PHP dependencies:
cd /var/www/bookstack
sudo -u www-data composer install --no-dev
Copy environment file:
sudo -u www-data cp .env.example .env
Configure environment:
sudo nano /var/www/bookstack/.env
Update settings:
APP_URL=https://docs.example.com
DB_HOST=localhost
DB_DATABASE=bookstack
DB_USERNAME=bookstack
DB_PASSWORD=SecurePassword123!
APP_KEY=
CACHE_DRIVER=file
SESSION_DRIVER=file
Generate application key:
cd /var/www/bookstack
sudo -u www-data php artisan key:generate
Run migrations:
cd /var/www/bookstack
sudo -u www-data php artisan migrate --force
Create admin account:
cd /var/www/bookstack
sudo -u www-data php artisan bookstack:create-admin
Follow the prompts to create admin account.
Nginx Configuration
Install Nginx:
sudo apt install -y nginx
Create Nginx configuration:
sudo nano /etc/nginx/sites-available/bookstack
Add configuration:
upstream bookstack {
server unix:/var/run/php/php8.0-fpm.sock;
}
server {
listen 80;
listen [::]:80;
server_name docs.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name docs.example.com;
ssl_certificate /etc/letsencrypt/live/docs.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/docs.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /var/www/bookstack/public;
index index.php;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\. {
deny all;
}
}
Enable site:
sudo ln -s /etc/nginx/sites-available/bookstack /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl start nginx
sudo systemctl enable nginx
SSL Certificate Configuration
Install Certbot:
sudo apt install -y certbot python3-certbot-nginx
Obtain SSL certificate:
sudo certbot certonly --nginx -d docs.example.com
Verify certificate:
sudo openssl x509 -in /etc/letsencrypt/live/docs.example.com/fullchain.pem -noout -dates
Set up auto-renewal:
sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer
Initial Configuration
Access BookStack web interface:
Navigate to https://docs.example.com and login with admin account credentials.
Configure basic settings:
-
Settings → General
- Application name
- Default locale
- Allow public viewing (if desired)
-
Settings → Features
- Enable/disable features
- Configure permissions
-
Settings → Maintenance
- Set up webhooks
- Configure backups
LDAP Authentication
Configure LDAP for enterprise authentication:
Edit environment file:
sudo nano /var/www/bookstack/.env
Add LDAP configuration:
LDAP_SERVER=ldap://ldap.example.com
LDAP_BASE_DN=dc=example,dc=com
LDAP_DN=cn=admin,dc=example,dc=com
LDAP_PASS=ldap_password
LDAP_USER_FILTER=(&(objectClass=inetOrgPerson)(uid={input}))
LDAP_VERSION=3
LDAP_USER_TO_GROUPS=false
LDAP_DUMP_USER_ATTRIBUTES=false
LDAP_START_TLS=false
Clear cache:
cd /var/www/bookstack
sudo -u www-data php artisan cache:clear
sudo -u www-data php artisan config:cache
Backup and Updates
Create backup script:
sudo nano /usr/local/bin/bookstack-backup.sh
Add:
#!/bin/bash
BACKUP_DIR="/backups/bookstack"
BOOKSTACK_DIR="/var/www/bookstack"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
# Database backup
mysqldump -u bookstack -p'SecurePassword123!' bookstack | gzip > "$BACKUP_DIR/bookstack-db-$DATE.sql.gz"
# Files backup
tar -czf "$BACKUP_DIR/bookstack-files-$DATE.tar.gz" "$BOOKSTACK_DIR"
# Keep only 30 days
find $BACKUP_DIR -type f -mtime +30 -delete
echo "Backup completed: $DATE"
Make executable:
sudo chmod +x /usr/local/bin/bookstack-backup.sh
Schedule daily backups:
sudo crontab -e
Add:
0 2 * * * /usr/local/bin/bookstack-backup.sh >> /var/log/bookstack-backup.log 2>&1
Update BookStack:
cd /var/www/bookstack
sudo -u www-data composer update
sudo -u www-data php artisan migrate --force
sudo -u www-data php artisan cache:clear
sudo systemctl reload nginx
Conclusion
BookStack is now fully installed and configured as a documentation platform. With Laravel framework, MySQL database, Nginx web server, SSL encryption, and LDAP authentication, you have a secure, enterprise-ready documentation solution. Create shelves, books, and chapters to organize your documentation. Configure LDAP for single sign-on and simplify user management. Regular backups ensure data protection and document preservation.


