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.
5 echo "THIS SCRIPT IS NO LONGER SUPPORTED OR MAINTAINED"
6 echo "IT MAY NOT WORK WITH CURRENT VERSIONS OF BOOKSTACK"
10 echo -n "Enter the domain you want to host BookStack and press [ENTER]: "
13 myip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
15 export DEBIAN_FRONTEND=noninteractive
17 apt install -y software-properties-common python-software-properties
18 add-apt-repository -yu ppa:ondrej/php
19 apt install -y git nginx curl php7.4 php7.4-fpm php7.4-curl php7.4-mbstring php7.4-ldap \
20 php7.4-tidy php7.4-xml php7.4-zip php7.4-gd php7.4-mysql mysql-server-5.7
23 DB_PASS="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)"
24 mysql -u root --execute="CREATE DATABASE bookstack;"
25 mysql -u root --execute="CREATE USER 'bookstack'@'localhost' IDENTIFIED BY '$DB_PASS';"
26 mysql -u root --execute="GRANT ALL ON bookstack.* TO 'bookstack'@'localhost';FLUSH PRIVILEGES;"
30 git clone https://github.com/ssddanbrown/BookStack.git --branch release --single-branch bookstack
31 BOOKSTACK_DIR="/var/www/bookstack"
35 EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q)
36 curl -s https://getcomposer.org/installer > composer-setup.php
37 ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
39 if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
41 php composer-setup.php --quiet
45 >&2 echo 'ERROR: Invalid composer installer signature'
50 # Install BookStack composer dependencies
51 php composer.phar install --no-dev
53 # Copy and update BookStack environment variables
55 sed -i.bak "s@APP_URL=.*\$@APP_URL=http://$DOMAIN@" .env
56 sed -i.bak 's/DB_DATABASE=.*$/DB_DATABASE=bookstack/' .env
57 sed -i.bak 's/DB_USERNAME=.*$/DB_USERNAME=bookstack/' .env
58 sed -i.bak "s/DB_PASSWORD=.*\$/DB_PASSWORD=$DB_PASS/" .env
60 # Generate the application key
61 php artisan key:generate --no-interaction --force
62 # Migrate the databases
63 php artisan migrate --no-interaction --force
65 # Set file and folder permissions
66 chown www-data:www-data -R bootstrap/cache public/uploads storage && chmod -R 755 bootstrap/cache public/uploads storage
68 # Add nginx configuration
69 curl -s https://raw.githubusercontent.com/BookStackApp/devops/main/config/nginx/ubuntu-1604-install-config > /etc/nginx/sites-available/bookstack
70 sed -i.bak "s/bookstack.dev/$DOMAIN/" /etc/nginx/sites-available/bookstack
71 ln -s /etc/nginx/sites-available/bookstack /etc/nginx/sites-enabled/bookstack
73 # Remove the default nginx configuration
74 rm /etc/nginx/sites-enabled/default
76 # Restart nginx to load new config
80 echo "Setup Finished, Your BookStack instance should now be installed."
81 echo "You can login with the email 'admin@admin.com' and password of 'password'"
82 echo "MySQL was installed without a root password, It is recommended that you set a root MySQL password."
84 echo "You can access your BookStack instance at: http://$myip/"