]> BookStack Code Mirror - devops/blob - scripts/installation-ubuntu-16.04.sh
Updated ubuntu 16.04 scripts to use php7.4
[devops] / scripts / installation-ubuntu-16.04.sh
1 #!/bin/sh
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.
4
5 echo ""
6 echo -n "Enter the domain you want to host BookStack and press [ENTER]: "
7 read DOMAIN
8
9 myip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/')
10
11 export DEBIAN_FRONTEND=noninteractive
12 apt update
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
17
18 # Set up database
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;"
23
24 # Download BookStack
25 cd /var/www
26 git clone https://github.com/ssddanbrown/BookStack.git --branch release --single-branch bookstack
27 BOOKSTACK_DIR="/var/www/bookstack"
28 cd $BOOKSTACK_DIR
29
30 # Install composer
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');")
34
35 if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
36 then
37     php composer-setup.php --quiet
38     RESULT=$?
39     rm composer-setup.php
40 else
41     >&2 echo 'ERROR: Invalid composer installer signature'
42     rm composer-setup.php
43     exit 1
44 fi
45
46 # Install BookStack composer dependancies
47 php composer.phar install
48
49 # Copy and update BookStack environment variables
50 cp .env.example .env
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
58
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
61
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
66
67 # Remove the default nginx configuration
68 rm /etc/nginx/sites-enabled/default
69
70 # Restart nginx to load new config
71 service nginx restart
72
73 echo ""
74 echo "Setup Finished, Your BookStack instance should now be installed."
75 echo "You can login with the email '[email protected]' and password of 'password'"
76 echo "MySQL was installed without a root password, It is recommended that you set a root MySQL password."
77 echo ""
78 echo "You can access your BookStack instance at: http://$myip/"