docs/main/deployment-guide/server/preparations.mdx
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
This guide outlines the key preparation steps required before installing the Mattermost Server, focusing on setting up the database and file storage systems.
Before installing Mattermost Server, review the following preparation requirements:
PostgreSQL v14+ is required for Mattermost server installations. MySQL database support is being deprecated starting with Mattermost v11. See the PostgreSQL migration documentation for guidance on migrating from MySQL to PostgreSQL.
Create an PostgreSQL server instance. See the PostgreSQL documentation for details. When the installation is complete, the PostgreSQL server is running, and a Linux user account called postgres has been created.
Create the Mattermost database and user:
Access PostgreSQL by running:
sudo -u postgres psql
Create the database:
CREATE DATABASE mattermost WITH ENCODING 'UTF8' LC_COLLATE='en_US.UTF-8' LC_CTYPE='en_US.UTF-8' TEMPLATE=template0;
If this steps fails with an error message like invalid LC_COLLATE locale name: "en_US.UTF-8", you need to generate the locale first using locale-gen en_US.UTF-8.
Create the Mattermost user with a secure password:
CREATE USER mmuser WITH PASSWORD 'mmuser-password';
Grant database access to the user:
GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
If using PostgreSQL v15.x or later, additional grants are required:
ALTER DATABASE mattermost OWNER TO mmuser;
-- Connect to the mattermost database so the schema grants below apply to the right schema
\c mattermost
ALTER SCHEMA public OWNER TO mmuser;
GRANT USAGE, CREATE ON SCHEMA public TO mmuser;
Configure PostgreSQL for remote connections (if database is on a separate server):
postgresql.conf to allow remote connections:Edit /etc/postgresql/{version}/main/postgresql.conf:
``` text
listen_addresses = '*'
```
Edit /var/lib/pgsql/{version}/data/postgresql.conf:
``` text
listen_addresses = '*'
```
2. Configure client authentication by editing `pg_hba.conf`:
Add the following line, replacing `{mattermost-server-IP}`:
``` text
host all all {mattermost-server-IP}/32 md5
```
4. Restart the PostgreSQL service to apply the configuration changes:
<Tabs> <TabItem value="ubuntu-debian" label="Ubuntu/Debian">sudo systemctl restart postgresql
sudo systemctl restart postgresql
If you are upgrading a major version of PostgreSQL, see Upgrade PostgreSQL for the full upgrade procedure and post-upgrade steps.
Once you've completed the database preparation, return to the Linux deployment documentation to continue with your Mattermost server installation.
Mattermost requires a file storage system for storing user files, images, and attachments. You have several options, including:
For production environments, we recommend using S3-compatible object storage such as:
When using S3 storage, you'll need:
For production environments that cannot use S3-compatible object storage, we recommend using a Network Addressable Storage (NAS) solution with Network File System (NFS).
You'll need to prepare an NFS server with a dedicated share for Mattermost (e.g. <code>/mnt/mattermost_data</code>) and mount it on all servers that will be running Mattermost.
For simple deployments, you can use local file storage. However, we don't recommend this for production environments or multi-node deployments.
Create a directory for file storage:
sudo mkdir -p /opt/mattermost/data
Set appropriate permissions:
sudo chown -R mattermost:mattermost /opt/mattermost/data
Using an image proxy means that all requests for images made by Mattermost clients will go through the proxy instead of contacting third-party servers directly. This helps protect user privacy by preventing third-party servers from tracking who views an image. This also prevents the use of tracking pixels (invisible images that do the same thing without the user even seeing an image).
Certain proxy servers also provide a layer of caching which can make loading images faster and more reliable. This caching also helps preserve posts by protecting them from dead images.
The following table outlines the network ports and protocols required for Mattermost server:
<table style={{width: '98%'}}> <colgroup> <col style={{width: '26%'}} /> <col style={{width: '17%'}} /> <col style={{width: '15%'}} /> <col style={{width: '5%'}} /> <col style={{width: '5%'}} /> <col style={{width: '27%'}} /> </colgroup> <thead> <tr> <th>Service Name</th> <th>Config Setting</th> <th>Port (default)</th> <th>Protocol</th> <th>Direction</th> <th>Info</th> </tr> </thead> <tbody> <tr> <td>HTTP/Websocket</td> <td>ServiceSettings.ListenAddress</td> <td>8065/80/443 (TLS)</td> <td>TCP</td> <td>Inbound</td> <td rowspan="2">External (no proxy) / Internal (with proxy) Usually this requires port 80 and 443 when running HTTPS.</td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td>Cluster</td> <td>ClusterSettings.GossipPort</td> <td>8074</td> <td>TCP/UDP</td> <td>Inbound</td> <td>Internal</td> </tr> <tr> <td>Metrics</td> <td>MetricsSettings.ListenAddress</td> <td>8067</td> <td>TCP</td> <td>Inbound</td> <td>External (no proxy) / Internal (with proxy)</td> </tr> <tr> <td>Database</td> <td>SqlSettings.DataSource</td> <td>5432 (PostgreSQL) / 3306 (MySQL)</td> <td>TCP</td> <td>Outbound</td> <td>Usually internal (recommended)</td> </tr> <tr> <td>LDAP</td> <td>LdapSettings.LdapPort</td> <td>389</td> <td>TCP/UDP</td> <td>Outbound</td> <td></td> </tr> <tr> <td>S3 Storage</td> <td>FileSettings.AmazonS3Endpoint</td> <td>443 (TLS)</td> <td>TCP</td> <td>Outbound</td> <td></td> </tr> <tr> <td>SMTP</td> <td>EmailSettings.SMTPPort</td> <td>10025</td> <td>TCP/UDP</td> <td>Outbound</td> <td></td> </tr> <tr> <td>Push Notifications</td> <td>EmailSettings.PushNotificationServer</td> <td>443 (TLS)</td> <td>TCP</td> <td>Outbound</td> <td></td> </tr> </tbody> </table> <Note>If your deployment requires using an outbound proxy, you can configure Mattermost using environment variables:
Configure the proxy settings in your service configuration:
Environment=HTTP_PROXY=http://proxy.example.com:3128
Environment=HTTPS_PROXY=https://proxy.example.com:3128
Environment=NO_PROXY=localhost,127.0.0.1,.internal.example.com
For authenticated proxies, include credentials in the URL:
Environment=HTTP_PROXY=http://username:[email protected]:3128
Environment=HTTPS_PROXY=https://username:[email protected]:3128
The NO_PROXY variable can include:
1.2.3.4)1.2.3.4/8)example.com).example.com)When using an HTTPS proxy, ensure your Mattermost server has the proxy's root certificate configured to avoid connection issues.
Example systemd Service Configuration
[Unit]
Description=Mattermost
After=network.target
After=postgresql.service
BindsTo=postgresql.service
[Service]
Type=notify
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
KillMode=mixed
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost
LimitNOFILE=49152
# Configure proxy settings if needed
#Environment=HTTP_PROXY=http://proxy.example.com:3128
#Environment=HTTPS_PROXY=https://proxy.example.com:3128
#Environment=NO_PROXY=localhost,127.0.0.1,.internal.example.com
# Recommended security options
ProtectSystem=full
PrivateTmp=true
NoNewPrivileges=true
[Install]
WantedBy=postgresql.service
Ensure your system meets these minimum requirements:
See the software and hardware requirements documentation for additional requirements.
Once you've completed these preparation steps, you can proceed with installing the Mattermost server. Choose your preferred installation method: