]> BookStack Code Mirror - devops/blob - scripts/installation-ubuntu-18.04.sh
Debian 13 script: Fixed mysql use for mariadb, removed composer use
[devops] / scripts / installation-ubuntu-18.04.sh
1 #!/bin/sh
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.
4
5 echo "THIS SCRIPT IS NO LONGER SUPPORTED OR MAINTAINED"
6 echo "IT MAY NOT WORK WITH CURRENT VERSIONS OF BOOKSTACK"
7 echo ""
8
9 # Fetch domain to use from first provided parameter,
10 # Otherwise request the user to input their domain
11 DOMAIN=$1
12 if [ -z $1 ]
13 then
14 echo ""
15 printf "Enter the domain you want to host BookStack and press [ENTER]\nExamples: my-site.com or docs.my-site.com\n"
16 read DOMAIN
17 fi
18
19 # Get the current machine IP address
20 CURRENT_IP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/')
21
22 # Install core system packages
23 apt update
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
30
31 # Set up database
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;"
36
37 # Download BookStack
38 cd /var/www
39 git clone https://github.com/BookStackApp/BookStack.git --branch release --single-branch bookstack
40 BOOKSTACK_DIR="/var/www/bookstack"
41 cd $BOOKSTACK_DIR
42
43 # Install composer
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');")
47
48 if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
49 then
50     php composer-setup.php --quiet
51     RESULT=$?
52     rm composer-setup.php
53 else
54     >&2 echo 'ERROR: Invalid composer installer signature'
55     rm composer-setup.php
56     exit 1
57 fi
58
59 # Install BookStack composer dependencies
60 export COMPOSER_ALLOW_SUPERUSER=1
61 php composer.phar install --no-dev --no-plugins
62
63 # Copy and update BookStack environment variables
64 cp .env.example .env
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
69
70 # Generate the application key
71 php artisan key:generate --no-interaction --force
72 # Migrate the databases
73 php artisan migrate --no-interaction --force
74
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
77
78 # Set up apache
79 a2enmod rewrite
80 a2enmod php8.2
81
82 cat >/etc/apache2/sites-available/bookstack.conf <<EOL
83 <VirtualHost *:80>
84         ServerName ${DOMAIN}
85
86         ServerAdmin webmaster@localhost
87         DocumentRoot /var/www/bookstack/public/
88
89     <Directory /var/www/bookstack/public/>
90         Options Indexes FollowSymLinks
91         AllowOverride None
92         Require all granted
93         <IfModule mod_rewrite.c>
94             <IfModule mod_negotiation.c>
95                 Options -MultiViews -Indexes
96             </IfModule>
97
98             RewriteEngine On
99
100             # Handle Authorization Header
101             RewriteCond %{HTTP:Authorization} .
102             RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
103
104             # Redirect Trailing Slashes If Not A Folder...
105             RewriteCond %{REQUEST_FILENAME} !-d
106             RewriteCond %{REQUEST_URI} (.+)/$
107             RewriteRule ^ %1 [L,R=301]
108
109             # Handle Front Controller...
110             RewriteCond %{REQUEST_FILENAME} !-d
111             RewriteCond %{REQUEST_FILENAME} !-f
112             RewriteRule ^ index.php [L]
113         </IfModule>
114     </Directory>
115
116         ErrorLog \${APACHE_LOG_DIR}/error.log
117         CustomLog \${APACHE_LOG_DIR}/access.log combined
118
119 </VirtualHost>
120 EOL
121
122 a2dissite 000-default.conf
123 a2ensite bookstack.conf
124
125 # Restart apache to load new config
126 systemctl restart apache2
127
128 echo ""
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."
132 echo ""
133 echo "You can access your BookStack instance at: http://$CURRENT_IP/ or http://$DOMAIN/"
Morty Proxy This is a proxified and sanitized view of the page, visit original site.