How to Install Mautic on NixOS Latest
In this tutorial, we will be installing Mautic, an open-source marketing automation software, on NixOS Latest.
Prerequisites
- A server running NixOS
- A sudo user to perform the installation
Step 1: Update the System
Before getting started, make sure that your system is up-to-date with the latest packages.
sudo nix-channel --update
sudo nixos-rebuild switch
Step 2: Install PHP and Apache
Mautic requires PHP and Apache to run. Install the required packages with the following command:
sudo nix-env -iA nixos.apache httpd php php-fpm
Step 3: Install MariaDB
Mautic requires a database to store its data. We will be using MariaDB, a popular open-source database. Install it with the following command:
sudo nix-env -iA nixos.mariadb
Step 4: Create a Database for Mautic
Create a new database and user for Mautic.
mysql -u root -p
CREATE DATABASE mautic_db;
GRANT ALL ON mautic_db.* TO 'mautic_user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
QUIT
Make sure to replace mautic_db, mautic_user, and password with your own values.
Step 5: Download and Install Mautic
Download the latest version of Mautic from https://www.mautic.org/download/. Once downloaded, extract the file to your Apache document root directory.
sudo tar -xzf mautic-<version>.targ.gz -C /var/www/html/
sudo mv /var/www/html/mautic-<version> /var/www/html/mautic
sudo chown -R apache:apache /var/www/html/mautic
Make sure to replace <version> with the version number you downloaded.
Step 6: Configure Apache
Create a new virtual host configuration file for Mautic.
sudo nano /etc/nixos/apache/mysite-mautic.nix
Add the following lines to the file.
{ config, lib, pkgs, ... }:
{
environment.etc."php/7.2/fpm/pool.d/mautic.conf".source = "${pkgs.stdenv.lib.sourceIfExists [./mautic-fpm.conf]}";
environment.etc."httpd/conf.d/mautic.conf".source = "${pkgs.stdenv.lib.sourceIfExists [./mautic-apache.conf]}";
services.httpd.virtualHosts.mautic = {
enableACME = true;
enableSSL = true;
serverAliases = ["mautic.example.com"];
documentRoot = "/var/www/html/mautic";
};
}
Make sure to replace mautic.example.com with your domain name.
Step 7: Create the Mautic FPM and Apache Configuration Files
Create two new configuration files for Mautic.
sudo nano /etc/nixos/mautic-fpm.conf
Enter the following details.
[mautic]
listen = /run/php/php7.2-fpm.sock
listen.owner = apache
listen.group = apache
listen.mode = 0660
user = apache
group = apache
pm = dynamic
pm.max_children = 100
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 50
pm.status_path = /mautic-status
ping.path = /mautic-ping
php_admin_value[open_basedir] = /var/www/html/mautic:/tmp
php_admin_value[upload_tmp_dir] = /var/www/html/mautic/tmp
Create the configuration file for Apache.
sudo nano /etc/nixos/mautic-apache.conf
Enter the following details.
<VirtualHost *:80>
Redirect permanent / https://mautic.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName mautic.example.com
DocumentRoot "/var/www/html/mautic"
<Directory "/var/www/html/mautic">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
<IfModule php7_module>
php_admin_value engine Off
php_admin_value opcache.enable Off
php_admin_value opcache.enable_cli Off
SetEnvIfNoCase ^Authorization$ "(.+)" XAUTHORIZATION=$1
RequestHeader set XAuthorization %{XAUTHORIZATION}e env=XAUTHORIZATION
Action php-fcgi /php-fcgi
AddHandler php-fcgi .php
ScriptAlias /php-fcgi /run/current-system/sw/bin/php-cgi-7.2
<Location />
Require all granted
</Location>
</IfModule>
</Directory>
SSLEngine on
SSLCertificateFile /path/to/ssl/certificate
SSLCertificateKeyFile /path/to/ssl/key
</VirtualHost>
Make sure to replace /path/to/ssl/certificate and /path/to/ssl/key with the paths to your SSL certificate and key files.
Step 8: Enable HTTPD and PHP-FPM Services
Enable the HTTPD and PHP-FPM services in NixOS.
sudo systemctl enable httpd php-fpm
Step 9: Restart Services
Restart the HTTPD and PHP-FPM services for the changes to take effect.
sudo systemctl restart httpd php-fpm
Step 10: Access Mautic in Browser
Open your web browser and navigate to https://mautic.example.com, replacing mautic.example.com with your domain name. You should now see the Mautic installation page. Follow the on-screen instructions to complete the installation.
Congratulations! You have successfully installed Mautic on NixOS.