Photo of Tony
April 16, 2024

Installing Umami analytics on Laravel Forge

Umami is a simple, fast, privacy-focused alternative to Google Analytics. Let's see how we can install it on Laravel Forge.

I like to use Umami Analytics for my sites as it offers a very nice user interface and gives me most of the information I need. Plus there is an added benefit, that I can host it myself. So in this post, I want to show you how I am setting up Umami on Laravel Forge.

1. Create a site

I will assume you know how to provision a server in Laravel Forge. If not you can check their docs. Once we have a server we can go ahead and create a site for our analytics. For the sake of this post, we will be using the following domain umami.example.com.

  • Root domain: umami.example.com
  • Project type: Static HTML/ Nuxt.js / Next.js
  • Aliases: Empty
  • Web Directory: /
  • Tick Create database and name it to fit your needs. In this post we will be using umami

Now create the site.

2. SSL

We want to use a secure connection so the next step is to configure SSL.

  • Go to the SSL tab
  • Press Let's Encrypt
  • Press Obtain certificate

3. Install the application

  • Head over to the Application tab
  • Choose Git Repository
  • Fill umami-software/umami to the Repository field
  • Select master branch
  • Select the umami database (or any name you used for the database in the 1st step)
  • Uncheck Install composer dependencies
  • Click Install repository

4. Deployment script

  • Head over to the Deployments tab
  • Update the Deployment script as follows:
cd /home/forge/umami.example.com
git pull origin $FORGE_SITE_BRANCH

yarn install
yarn build
yarn update-db
  • Press Update to save changes

5. Database

  • Head over to the Environment tab
  • Add the following line: DATABASE_URL=mysql://forge:<DB_PASSWORD>@localhost:3306/umami
  • Press Save

This is MySQL connection string in the following format: mysql://<DB_USERNAME>:<DB_PASSWORD>@<SERVER>:<PORT>/<DB_NAME>. So you can easily create a separate database user and fill in the credentials here.

6. Nginx configuration

  • Click the Edit files button at the top right of the page (You have to be in your site detail to see this button)
  • Select Edit Nginx Configuration
  • Locate the following part:
location / {
    try_files $uri $uri/ /index.php?$query_string;
}
  • Replace it with:
location / {
    proxy_pass http://localhost:3000;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
  • Press Save

7. Initial build

  • Click the Deploy now button in the top right corner of your site detail

8. Set up a daemon

  • Go to your server detail page
  • Go to the Daemons tab
  • Command: yarn start
  • Directory: /home/forge/umami.example.com
  • Press Create

Summary

So that's all there is to it. Now you should be able to access Umami. When in doubt you can always consult official Umami docs. I hope this was helpful to you and until next time,

Tony.

© 2024 Tony Masek