2 # This script will install a new BookStack instance on a fresh Ubuntu 18.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"
9 # Fetch domain to use from first provided parameter,
10 # Otherwise request the user to input their domain
15 printf "Enter the domain you want to host BookStack and press [ENTER]\nExamples: my-site.com or docs.my-site.com\n"
19 # Get the current machine IP address
20 CURRENT_IP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
22 # Install core system packages
24 apt install -y software-properties-common
25 export DEBIAN_FRONTEND=noninteractive
26 add-apt-repository universe
27 add-apt-repository -yu ppa:ondrej/php
28 apt install -y git apache2 curl php8.2 php8.2-curl php8.2-mbstring php8.2-ldap \
29 php8.2-xml php8.2-zip php8.2-gd php8.2-mysql mysql-server-5.7 libapache2-mod-php8.2
32 DB_PASS="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)"
33 mysql -u root --execute="CREATE DATABASE bookstack;"
34 mysql -u root --execute="CREATE USER 'bookstack'@'localhost' IDENTIFIED BY '$DB_PASS';"
35 mysql -u root --execute="GRANT ALL ON bookstack.* TO 'bookstack'@'localhost';FLUSH PRIVILEGES;"
39 git clone https://github.com/BookStackApp/BookStack.git --branch release --single-branch bookstack
40 BOOKSTACK_DIR="/var/www/bookstack"
44 EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q)
45 curl -s https://getcomposer.org/installer > composer-setup.php
46 ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
48 if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
50 php composer-setup.php --quiet
54 >&2 echo 'ERROR: Invalid composer installer signature'
59 # Install BookStack composer dependencies
60 export COMPOSER_ALLOW_SUPERUSER=1
61 php composer.phar install --no-dev --no-plugins
63 # Copy and update BookStack environment variables
65 sed -i.bak "s@APP_URL=.*\$@APP_URL=http://$DOMAIN@" .env
66 sed -i.bak 's/DB_DATABASE=.*$/DB_DATABASE=bookstack/' .env
67 sed -i.bak 's/DB_USERNAME=.*$/DB_USERNAME=bookstack/' .env
68 sed -i.bak "s/DB_PASSWORD=.*\$/DB_PASSWORD=$DB_PASS/" .env
70 # Generate the application key
71 php artisan key:generate --no-interaction --force
72 # Migrate the databases
73 php artisan migrate --no-interaction --force
75 # Set file and folder permissions
76 chown www-data:www-data -R bootstrap/cache public/uploads storage && chmod -R 755 bootstrap/cache public/uploads storage
82 cat >/etc/apache2/sites-available/bookstack.conf <<EOL
86 ServerAdmin webmaster@localhost
87 DocumentRoot /var/www/bookstack/public/
89 <Directory /var/www/bookstack/public/>
90 Options Indexes FollowSymLinks
93 <IfModule mod_rewrite.c>
94 <IfModule mod_negotiation.c>
95 Options -MultiViews -Indexes
100 # Handle Authorization Header
101 RewriteCond %{HTTP:Authorization} .
102 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
104 # Redirect Trailing Slashes If Not A Folder...
105 RewriteCond %{REQUEST_FILENAME} !-d
106 RewriteCond %{REQUEST_URI} (.+)/$
107 RewriteRule ^ %1 [L,R=301]
109 # Handle Front Controller...
110 RewriteCond %{REQUEST_FILENAME} !-d
111 RewriteCond %{REQUEST_FILENAME} !-f
112 RewriteRule ^ index.php [L]
116 ErrorLog \${APACHE_LOG_DIR}/error.log
117 CustomLog \${APACHE_LOG_DIR}/access.log combined
122 a2dissite 000-default.conf
123 a2ensite bookstack.conf
125 # Restart apache to load new config
126 systemctl restart apache2
129 echo "Setup Finished, Your BookStack instance should now be installed."
130 echo "You can login with the email 'admin@admin.com' and password of 'password'"
131 echo "MySQL was installed without a root password, It is recommended that you set a root MySQL password."
133 echo "You can access your BookStack instance at: http://$CURRENT_IP/ or http://$DOMAIN/"