Laravel Forge MailHog Install Guide
EmailMailHog is a great email testing tool that can enable end-users to see email without the server actually sending the email.
In this guide I'll show you how to install MailHog on a Laravel Forge Server. The installation was done on Ubuntu 24.04 but should be similar for other Ubuntu versions.
If you want to learn more about MailHog, here is their GitHub repo: https://github.com/mailhog/MailHog
When you're done with the installation, you'll have an `SMTP` server running on port `1025` and a web-based email client running on port `8025`. Sweet.
Preparation
MailHog seems to need a fairly new version of Go, so on some Ubuntu servers one has to first set up the "back ports". You may skip this step and try installation below first and look at the output...if it's obvious that Go doesn't want to install MailHog due to version issues, come back here for some `apt` love.
forge sudo -i add-apt-repository ppa:longsleep/golang-backports apt update apt -y install golang-go lang-bash
Installation
apt -y install golang-go go install github.com/mailhog/MailHog@latest lang-bash
If you want to test it, you can use the command below:
~/go/bin/MailHog & lang-bash
You should see something like the following:
[1] 242137 root@forge:~# 2024/08/07 08:32:34 Using in-memory storage 2024/08/07 08:32:34 [SMTP] Binding to address: 0.0.0.0:1025 [HTTP] Binding to address: 0.0.0.0:8025 2024/08/07 08:32:34 Serving under http://0.0.0.0:8025/ Creating API v1 with WebPath: Creating API v2 with WebPath: lang-bash
To continue with this guide, you'll want to `kill` the process output above as just now we're adding a Linux service for automatic startup and this won't work if you are also listening on those ports.
Allowing firewall access and securing the MailHog interface
Navigate to your Forge server, `Settings -> Network -> Firewall Rules`, and add a firewall rule to allow port `8025` to view the email interface from the outside.
Next, use the commands below to set up a `username:bcryptpw` mapping file. Change `username` and `secret` to your desired preference:
apt install apache2-utils htpasswd -nbB username secret > /root/go/bin/mailhog.security
Create a Service
Next, install it as a service:
# cat /etc/systemd/system/mailhog.service [Unit] Description=MailHog service [Service] ExecStart=/root/go/bin/MailHog -auth-file=/root/go/bin/mailhog.security [Install] WantedBy=multi-user.target lang-bash
Enable the service for automatic startup, and then start it:
systemctl enable mailhog service mailhog start lang-bash
Remember to update your `.env` file to port `1025` to access the MailHog SMTP service:
MAIL_PORT=1025 lang-php
Go here to see the email interface running: https://forge-server-ip:8025
