2 # This script will install a new BookStack instance on a fresh Ubuntu 16.04 server.
3 # This script is experimental and does not ensure any security.
6 echo -n "Enter the domain you want to host BookStack and press [ENTER]: "
9 myip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
11 export DEBIAN_FRONTEND=noninteractive
13 apt install -y software-properties-common python-software-properties
14 add-apt-repository -yu ppa:ondrej/php
15 apt install -y git nginx curl php7.4 php7.4-fpm php7.4-curl php7.4-mbstring php7.4-ldap \
16 php7.4-tidy php7.4-xml php7.4-zip php7.4-gd php7.4-mysql mysql-server-5.7
19 DB_PASS="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)"
20 mysql -u root --execute="CREATE DATABASE bookstack;"
21 mysql -u root --execute="CREATE USER 'bookstack'@'localhost' IDENTIFIED BY '$DB_PASS';"
22 mysql -u root --execute="GRANT ALL ON bookstack.* TO 'bookstack'@'localhost';FLUSH PRIVILEGES;"
26 git clone https://github.com/ssddanbrown/BookStack.git --branch release --single-branch bookstack
27 BOOKSTACK_DIR="/var/www/bookstack"
31 EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q)
32 curl -s https://getcomposer.org/installer > composer-setup.php
33 ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
35 if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
37 php composer-setup.php --quiet
41 >&2 echo 'ERROR: Invalid composer installer signature'
46 # Install BookStack composer dependancies
47 php composer.phar install
49 # Copy and update BookStack environment variables
51 sed -i.bak 's/DB_DATABASE=.*$/DB_DATABASE=bookstack/' .env
52 sed -i.bak 's/DB_USERNAME=.*$/DB_USERNAME=bookstack/' .env
53 sed -i.bak "s/DB_PASSWORD=.*\$/DB_PASSWORD=$DB_PASS/" .env
54 # Generate the application key
55 php artisan key:generate --no-interaction --force
56 # Migrate the databases
57 php artisan migrate --no-interaction --force
59 # Set file and folder permissions
60 chown www-data:www-data -R bootstrap/cache public/uploads storage && chmod -R 755 bootstrap/cache public/uploads storage
62 # Add nginx configuration
63 curl -s https://raw.githubusercontent.com/BookStackApp/devops/master/config/nginx > /etc/nginx/sites-available/bookstack
64 sed -i.bak "s/bookstack.dev/$DOMAIN/" /etc/nginx/sites-available/bookstack
65 ln -s /etc/nginx/sites-available/bookstack /etc/nginx/sites-enabled/bookstack
67 # Remove the default nginx configuration
68 rm /etc/nginx/sites-enabled/default
70 # Restart nginx to load new config
74 echo "Setup Finished, Your BookStack instance should now be installed."
76 echo "MySQL was installed without a root password, It is recommended that you set a root MySQL password."
78 echo "You can access your BookStack instance at: http://$myip/"