Skip to content

Instantly share code, notes, and snippets.

@pzl
Created February 1, 2018 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pzl/d9bbab41cbcd310ecd49f8a239c4ff8d to your computer and use it in GitHub Desktop.
Save pzl/d9bbab41cbcd310ecd49f8a239c4ff8d to your computer and use it in GitHub Desktop.
bookstack on alpine
server {
listen 80 default;
listen [::]:80;
server_name bookstack.dev;
set $base /opt/bookstack;
root $base/public;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-UA-Compatible "IE=Edge" always;
add_header Cache-Control "no-transform" always;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php7-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE open_basedir=$base/:/usr/lib/php/:/tmp/;
fastcgi_intercept_errors off;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
}
#!/bin/sh
# use alpine 3.7, enable community repo
echo "http://dl-4.alpinelinux.org/alpine/v3.7/community" >> /etc/apk/repositories
apk update
# install everything
apk add nginx # webserver
# all the PHP packages necessary for running, and using php-fpm to connect to nginx
apk add php7 php7-fpm php7-json php7-phar php7-zlib php7-simplexml php7-dom php7-fileinfo php7-xmlwriter php7-xml php7-pdo_mysql php7-session php7-ctype php7-mbstring php7-mysqlnd php7-tokenizer php7-curl php7-zip php7-mcrypt php7-openssl php7-pdo php7-tidy php7-gd
apk add mariadb-client mariadb # database
# or change this to your distro's package thing, apt-get install, yum, pacman -S, etc.
# copy the outside config files into place on the system
cp ./bookstack-nginx.conf /etc/nginx/conf.d/default.conf
# set up php-fpm to communicate via this socket file, referenced in the nginx config
echo "listen = /var/run/php7-fpm.sock" >> /etc/php7/php-fpm.d/www.conf
# create the database
mysql_install_db --user=mysql --datadir=/var/lib/mysql
mysqld --user=mysql --bootstrap --verbose=0 <<EOF
USE mysql;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
CREATE DATABASE IF NOT EXISTS \`db\` CHARACTER SET utf8 COLLATE utf8_general_ci;
FLUSH PRIVILEGES;
EOF
# download and unpack bookstack
LATEST="$(curl -sX GET "https://api.github.com/repos/BookStackApp/BookStack/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]')"
wget -O bookstack.tar.gz "https://github.com/BookStackApp/BookStack/archive/${LATEST}.tar.gz"
mkdir -p /opt/bookstack
tar -xzf bookstack.tar.gz -C /opt/bookstack --strip-components 1
rm -rf bookstack.tar.gz
chmod -R 777 /opt/bookstack/storage
chmod -R 777 /opt/bookstack/bootstrap/cache
chmod -R 777 /opt/bookstack/public/uploads
# download, set up, and run composer
wget -O composer-setup.php "https://getcomposer.org/installer"
php composer-setup.php --quiet && rm -rf composer-setup.php # creates ./composer.phar file here
./composer.phar --working-dir=/opt/bookstack install
# set up bookstack env
cp ./env /opt/bookstack/.env # contains our DB credentials, database name=db, root,etc..
php /opt/bookstack/artisan migrate -n --force # set up tables
php /opt/bookstack/artisan key:generate # replace APP_KEY in .env
# start all the services
rc-service nginx start
rc-service php-fpm start
rc-service mariadb start
# for systemd-based distros, change to: systemctl start nginx.service, systemctl start php-fpm.service, etc
# Environment
APP_ENV=production
APP_DEBUG=false
APP_KEY=changme
# The below url has to be set if using social auth options
# or if you are not using BookStack at the root path of your domain.
# APP_URL=http://bookstack.dev
# Database details
DB_HOST=127.0.0.1
DB_DATABASE=db
DB_USERNAME=root
DB_PASSWORD=
# try root as password if blank doesn't work
# Cache and session
CACHE_DRIVER=file
SESSION_DRIVER=file
# If using Memcached, comment the above and uncomment these
#CACHE_DRIVER=memcached
#SESSION_DRIVER=memcached
QUEUE_DRIVER=sync
# Memcached settings
# If using a UNIX socket path for the host, set the port to 0
# This follows the following format: HOST:PORT:WEIGHT
# For multiple servers separate with a comma
MEMCACHED_SERVERS=127.0.0.1:11211:100
# Storage
STORAGE_TYPE=local
# Amazon S3 Config
STORAGE_S3_KEY=false
STORAGE_S3_SECRET=false
STORAGE_S3_REGION=false
STORAGE_S3_BUCKET=false
# Storage URL
# Used to prefix image urls for when using custom domains/cdns
STORAGE_URL=false
# General auth
AUTH_METHOD=standard
# Social Authentication information. Defaults as off.
GITHUB_APP_ID=false
GITHUB_APP_SECRET=false
GOOGLE_APP_ID=false
GOOGLE_APP_SECRET=false
OKTA_BASE_URL=false
OKTA_KEY=false
OKTA_SECRET=false
# External services such as Gravatar
DISABLE_EXTERNAL_SERVICES=false
# LDAP Settings
LDAP_SERVER=false
LDAP_BASE_DN=false
LDAP_DN=false
LDAP_PASS=false
LDAP_USER_FILTER=false
LDAP_VERSION=false
# Mail settings
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment