Virtual Server
This guide explains how to deploy a Brezel instance to a (virtual) server.
For this guide, we assume the base domain is called example.io
and Brezel will be accessible under brezel.example.io
.
The example IP of the server is given as 5.35.243.342
.
Prerequisites
Available since: brezel/api@1.0.0
- Root access
- Ubuntu or Debian
- Nginx
- GitLab repository for your Brezel instance
0. Install Nginx, PHP, PHP extensions other needed dependencies, Imagick, CertBot and MySQL/MariaDB
- Nginx, PHP, PHP extensions, and other necessary dependencies
- Imagick
- Certbot for SSL certificates See https://certbot.eff.org/instructions?ws=nginx for up-to-date instructions.
If
sudo snap install --classic certbot
does not work because you are behind some kind of firewall or don’t have access to snap, you can also install certbot viasudo apt install certbot python3-certbot-nginx
- Install MariaDB using a guide like this.
Or follow these rough steps:
In the installation process, read closely what it asks you and answer accordingly. You probably don’t want anything related to changing the root users passwort, but do want to remove the test database and disallow remote root login.
At this point you can already create a “brezel” user with the necessary permissions while you are at it.
GRANT ALL ON *.* TO 'brezel'@'localhost' IDENTIFIED BY '<your secure password>' WITH GRANT OPTION;
FLUSH PRIVILEGES;
1. Add DNS records
Login to your external DNS provider and add the following DNS records (replace the bold values with your use case):
Name | Type | Value |
---|---|---|
brezel.example.io | A | 5.35.243.342 |
api.brezel.example.io | A | 5.35.243.342 |
ws.brezel.example.io | A | 5.35.243.342 |
2. Add the SPA domain
In /etc/nginx/sites-available
, create a new file called spa
:
Save the file, then create a symlink:
Restart NGINX:
Secure the SPA domain
3. Add the API domain
In /etc/nginx/sites-available
, create a new file called api
:
Save the file, then create a symlink:
Ensure these values in your top level/etc/nginx/nginx.conf
file:
If they have already been set, be sure to change the values and not just add a new line with the same directive.
Configure your php-fpm settings in /etc/php/8.3/fpm/pool.d/www.conf
:
You can either just paste these values at the end of the file or search for the values and change them.
Finally, add the following values to your /etc/php/8.3/fpm/php.ini
file:
Restart Nginx:
Secure the API domain
4. Configure Brotcast
Brotcast is a websocket server that is used for real-time communication between the Brezel instance and the frontend.
Installation
Run via Laravel Reverb New
Available since: brezel/api@1.0.0 Since 1.0.0, Brezel ships with a Laravel Reverb based Brotcast server integrated! Once you setup Supervisor, the server will be started automatically. In this case you only need to configure the nginx proxy
Run it via docker compose
Make sure you have docker installed.
Then create a docker-compose.yml file with the following content:
Run docker compose up
in the same directory.
Add the domain
In /etc/nginx/sites-available
, create a new file called brotcast
:
Save the file, then create a symlink:
Restart Nginx:
Secure the Brotcast domain
Performance tweaks
You might want to take a look at https://laravel.com/docs/11.x/reverb#production for some possible performance considerations.
Especially increasing the available ports / file descriptors as well as switching to a different runtime might be beneficial.
5. Create a new user for Brezel
- Create the new user.
- Add your new user to the
www-data
group to ensure the correct permissions for the Nginx web server.
- Create the web root directory for the new user.
Set the correct permissions:
6. Connect the server to GitLab
The Brezel instance will be deployed to the API subdomain.
The SPA domain will receive the contents of the minified frontend found in the dist/
folder.
Create SSH keys for GitLab
- Switch to the new user.
- Generate an RSA key pair:
Now generate the key.
You will be asked for a path. The default is probably fine.
Just ensure it is in the home directory of the brezel user (~/.ssh/id_rsa
).
Hit enter.
You will then be asked for a passphrase. We want no passphrase. Leave the field empty and hit enter.
Hit enter again to confirm the empty password. It will then output something like this:
Now, go to GitLab, to the repository of your Brezel instance and go to Settings > Repository > Deploy Keys.
We want our server to be able to read from the GitLab repository.
Paste the contents of ~/.ssh/id_rsa.pub
to the Key field. Give it a meaningful title like Production [brezel.example.io]
.
Clone the repository
- Move to your new user’s web root directory where we will clone the application repository to.
- Install Git if it’s not already installed.
Clone the instance repository (Get the SSH URL from the GitLab repository):
7. Set up Brezel
Install composer and do
Enter your private package credentials:
Only needed if you don’t deploy via a pipeline Change $PACKAGE_TOKEN and $PACKAGE_TOKEN_USER to a GitLab token and user that can read brezel/api
Then, install dependencies:
Only needed if you don’t deploy via a pipeline
If you want to merge pdf files or use file thumbnails, you need to install ghostscript and the php imagick extension respectively.
Update folder permissions for the storage
directory:
Next, configure your environment:
Database
Adjust your database configuration in /etc/mysql/my.cnf
by adding this block to the very bottom:
If you are running MariaDB add the following options too:
Now restart the database (Use mariadb
if you are running MariaDB):
For the database credentials:
Variant 1: Use root credentials
Variant 2: Use a privileged database user
Or, if you have root privileges, you can create a brezel
MySQL/MariaDB user with ALL privileges:
You don’t need to do that if you did it while installing MariaDB!
And set the following credentials:
Setting up the brotcast environment
Configure the brotcast environment in the .env
file:
8. Set up the pipeline
Follow the Pipeline guide.
Initialization
Ensure that you have an .env
file in the root of your instance with the correct values.
Copy the .env.example
file and adjust the values.
Make sure to change APP_ENV to “production”!
If the database credentials were set up, you can initialize the instance with
Now, you can add your system
And fill it with your config:
9. Configure file system permissions
Make sure that the instance folder is owned by brezel and www-data with both having permissions to read, write and create files.
10. Install and configure supervisor
For async workflows and other background jobs to work, we need to install supervisor.
Switch back to the brezel
user and go into the instance directory.
Now copy supervisor.conf.example
to supervisor.conf
and adjust the socket names if desired.
Ensure you are still in the instance directory and run the following command to create the supervisor configuration:
Now start supervisor in your instance directory with:
Check that all jobs are up and running:
12. Set up crons
If you want to use event/cron
, you need to set up a cronjob.
Very basically: this should trigger php bakery schedule
in the directory of your instance every minute as the user that normally runs your brezel (when using nginx and following this setup it will be www-data
).
How you achieve this depends on you, especially on your local setup, but on a server it makes sense to use cron
.
Make sure you are the brezel
user and run
now add the following line:
Finally, verify that this was saved correctly by running crontab -l
and checking if the line is there.