# Enabling HTTPS for the BookStack web interface

[https://docs.sam.gy/books/bookstack/page/enabling-https-for-the-bookstack-web-interface](https://docs.sam.gy/books/bookstack/page/enabling-https-for-the-bookstack-web-interface)

When finished with this guide, will likely want to follow [Using Cert Bot to get a Valid SSL certificate](https://docs.coltscomputer.services/books/operating-systems/page/using-cert-bot-to-get-a-valid-ssl-certificate "Using Cert Bot to get a Valid SSL certificate")

The default BookStack installation script for Ubuntu 20.04/18.04/16.04 only configures the Apache2 server to use HTTP, not HTTPS. With plain HTTP becoming more and more obsolete each day, you'll likely want to use HTTPS instead in combination with a Let's Encrypt SSL certificate (or a self-signed cert if you're only accessing locally).

Move the original BootStack config file (so you can access it again if needed)

- sudo mv /etc/apache2/sites-available/bookstack.conf /etc/apache2/sites-available/bookstack.conf.old

Create a new BookStack Apache2 config file:

- sudo nano /etc/apache2/sites-available/bookstack.conf

Here is an example configuration - you will need to change the **ServerName** and **SSLCertificate** directives to match your requirements.

<table border="1" id="bkmrk-%3Cvirtualhost-%2A%3A80%3E-%C2%A0" style="border-collapse: collapse; width: 100%; height: 29.7969px;"><colgroup><col style="width: 99.8765%;"></col></colgroup><tbody><tr style="height: 29.7969px;"><td style="height: 29.7969px;"><div>&lt;VirtualHost *:80&gt;</div><div> ServerName YOUR-DOMAIN-HERE</div><div> RewriteEngine On</div><div> RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]</div><div>&lt;/VirtualHost&gt;</div><div>  
</div><div>&lt;VirtualHost *:443&gt;</div><div>ServerName YOUR-DOMAIN-HERE</div><div>ServerAdmin webmaster@localhost</div><div>DocumentRoot /var/www/bookstack/public/</div><div>  
</div><div> SSLEngine on</div><div> SSLCertificateFile /etc/letsencrypt/live/YOUR-DOMAIN-HERE/fullchain.pem</div><div> SSLCertificateKeyFile /etc/letsencrypt/live/YOUR-DOMAIN-HERE/privkey.pem</div><div>  
</div><div> &lt;Directory /var/www/bookstack/public/&gt;</div><div> Options Indexes FollowSymLinks</div><div> AllowOverride None</div><div> Require all granted</div><div> &lt;IfModule mod_rewrite.c&gt;</div><div> &lt;IfModule mod_negotiation.c&gt;</div><div> Options -MultiViews -Indexes</div><div> &lt;/IfModule&gt;</div><div> RewriteEngine On</div><div> # Handle Authorization Header</div><div> RewriteCond %{HTTP:Authorization} .</div><div> RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]</div><div> # Redirect Trailing Slashes If Not A Folder...</div><div> RewriteCond %{REQUEST_FILENAME} !-d</div><div> RewriteCond %{REQUEST_URI} (.+)/$</div><div> RewriteRule ^ %1 [L,R=301]</div><div> # Handle Front Controller...</div><div> RewriteCond %{REQUEST_FILENAME} !-d</div><div> RewriteCond %{REQUEST_FILENAME} !-f</div><div> RewriteRule ^ index.php [L]</div><div> &lt;/IfModule&gt;</div><div> &lt;/Directory&gt;</div><div>  
</div><div>ErrorLog ${APACHE_LOG_DIR}/error.log</div><div>CustomLog ${APACHE_LOG_DIR}/access.log combined</div><div>&lt;/VirtualHost&gt;</div></td></tr></tbody></table>

Enable Apache2's SSL module

- sudo a2enmod ssl

Run Apache2's built in config tester to confirm there are no errors:

- sudo apachectl configtest
- Syntax OK

Edit BookStack's .env config file:

- sudo nano /var/www/bookstack/.env

Change the **APP\_URL** parameter so that it uses the full domain name, making sure that it specifies **https://** not http://

<table border="1" id="bkmrk-%23-application-url%23-t" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8765%;"></col></colgroup><tbody><tr><td>\# Application URL  
\# This must be the root URL that you want to host BookStack on.  
\# All URLs in BookStack will be generated using this value  
\# to ensure URLs generated are consistent and secure.  
\# If you change this in the future you may need to run a command  
\# to update stored URLs in the database. Command example:  
\# php artisan bookstack:update-url https://old.example.com https://new.example.com  
APP\_URL=https://YOUR-DOMAIN-HERE</td></tr></tbody></table>

Restart Apache2

- sudo systemctl restart apache2