Virtual Server (PHP 7.4)
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
- Root access
- Ubuntu or Debian
- Nginx
- GitLab repository for your Brezel instance
0. Install Nginx, PHP, MySQL/MariaDB and Certbot
Install MariaDB using a guide like this.
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 |
*.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:
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/7.4/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/7.4/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
5. Create a new user and environment 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.
Set up a basic environment for the new user by copying the /etc/skel
directory.
- Change the ownership of the copied
/etc/skel
directory to the new user.
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.
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:
This will output:
The path is fine. Hit enter.
No passphrase. Hit enter.
Hit enter. 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 Laravel repository.
- Install Git if it’s not already installed.
Clone the instance repository:
Go to the cloned directory:
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.conf
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 give the brezel
MySQL/MariaDB user SUPER privileges:
And set the following credentials:
Setting up the brotcast environment
Configure the brotcast environment in the .env
file:
Initialization
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:
8. Configure system permissions
- Make sure that everything inside the vhost directory is owned by
brezel:www-data
. storage/app
should be owned bywww-data:www-data
.storage/framework
should also be owned bywww-data:www-data
.
9. Set up Brezel SPA
Follow the SPA instructions in the Pipeline guide.
10. Set up the pipeline
Follow the Pipeline guide.
11. Install and configure supervisor
For async workflows and other background jobs to work, we need to install supervisor.
Now copy supervisor.conf.example
to supervisor.conf
and adjust the socket names if desired.
Then run the following command to create the supervisor configuration:
Now start supervisor in your instance directory with:
You probably need to do this as a root user if you run into permission issues for the storage directory!
sudo supervisord -c supervisord.conf
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
.
For that, switch to a user with the necessary permissions (aka. root or a user that has access to sudo
) and edit the crontab of the www-data user.
For that run
and add the following line:
Finally, verify that this was saved correctly by running crontab -u www-data -l
and checking if the line is there.