Install BookStack on CentOS 7

This post was last updated on Feb 16, 2018. Updated php packages to 7.2 and added a few new requirements, and also changed mariadb to version 10.1.

I recently was informed about a pretty neat documentation app, as I was looking for a replacement of my person Confluence instance (I like Confluence, but don't care for the cost and I'm no big fan of Java apps). BookStack is an open-source Wiki-like piece of software, that runs from a typical LAMP/LEMP stack. For this guide, I will be using MariaDB, Nginx, and PHP 5.6.

The interesting thing about this software is the struction of how data is stored. Books are at the highest level, followed by Chapters, and then Pages. That's the organizational struction, though Chapters are completely option.

This guide assumes firewalld/iptables is disabled, as well as selinux (though both can be easily enabled as this is just a standard web app).

Let's Get Started!

1.) prerequisites:
yum -y install epel-release   # EPEL Repo
yum -y install   # IUS Repo
yum -y install git mariadb101u-server nginx php72u php72u-cli php72u-fpm php72u-gd php72u-json php72u-mbstring php72u-mysqlnd php72u-openssl php72u-tidy php72u-tokenizer php72u-xml   # Packages we need
2.) database setup
systemctl restart mariadb.service   # Start MySQL service
mysql_secure_installation   # Set root password
mysql -u root -p   # Enter root password you just set
GRANT ALL PRIVILEGES ON bookstackdb.* TO 'bookstackuser'@'localhost' IDENTIFIED BY 'bookstackpass' WITH GRANT OPTION;

Database created, and ready to rock.

3.) php-fpm setup
vi /etc/php-fpm.d/www.conf   # Set critcal settings
listen = /var/run/php-fpm.sock
listen.owner = nginx ; SOCKS permission = nginx ; SOCKS permission
listen.mode = 0660 ; SOCKS permission
user = nginx ; PHP-FPM running user
group = nginx ; PHP-FPM running group
php_value[session.save_path]    = /var/www/sessions

php-fpm configured and ready to serve php files.

4.) nginx setup
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig   # Backup original file
vi /etc/nginx/nginx.conf   # Nginx config
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

vi /etc/nginx/conf.d/bookstack.conf   # Server config
server {
  listen 80;
  server_name localhost;
  root /var/www/BookStack/public;

  access_log  /var/log/nginx/bookstack_access.log;
  error_log  /var/log/nginx/bookstack_error.log;

  client_max_body_size 1G;
  fastcgi_buffers 64 4K;

  index  index.php;

  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.sock;

  location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
    expires 30d;
    access_log off;

Nginx configured, and ready to rock.

5.) bookstack setup
cd /usr/local/bin   # Change dirs to where we want composer installed to
curl -sS | php   # Install composer
mv composer.phar composer   # Rename composer

cd /var/www   # Change dirs to where we want BookStack installed to   
mkdir /var/www/sessions   # Dir for php sessions
git clone --branch release --single-branch   # Clone the latest from the release branch
cd BookStack && composer install   # Change dirs into the BookStack dir, and let composer do it's thing

cp .env.example .env   # Make a copy of the example config
vi .env   # Update the new config with database, and other settings

All other settings are fine as default, but feel free to change any others as you see fit.

php artisan key:generate --force   # Generate and update APP_KEY in .env
chown -R nginx:nginx /var/www/{BookStack,sessions}   # Change ownership to the webserver user
php artisan migrate --force   # Generate database tables and other settings

BookStack should be good to go now.

6.) Cleanup

All that's left is a little housecleaning!

systemctl enable nginx.service && systemctl enable mariadb.service && systemctl enable php-fpm.service
systemctl reboot

Afteer your server boots, you should be all good to go. head over to http://server_ip to start using BookStack! Default username is and the default password is password. Log in and changes those.

Go forth and document!

Related Posts

Share on: Twitter | Facebook | Google+ | Email

comments powered by Disqus