This content originally appeared on DEV Community and was authored by Praneeth Perera
In this guide, we'll walk you through the process of setting up Postfix Admin, a web-based management interface for Postfix mail servers, within a PHP-FPM Docker container with the Nginx server on the host machine. We'll also show you how to integrate an external Nginx server to handle incoming requests. This configuration will allow you to efficiently manage your Postfix mail server using the Postfix Admin interface through a user-friendly web interface.
Prerequisites:
Basic understanding of Docker and Docker Compose
Familiarity with Nginx server configuration
Access to a domain name (e.g., postfixadmin.example.com) pointing to your server's IP address
Step 1: Docker Compose Setup:
Create a directory for your project and create a docker-compose.yml file.
Copy
version: '3'
services:
postfixadmin-db:
image: mysql:5.7
container_name: postfixadmin-db
environment:
MYSQL_ROOT_PASSWORD: Welcome@2023
MYSQL_DATABASE: postfixadmin
MYSQL_USER: postfixadmin
MYSQL_PASSWORD: welcome@2023
volumes:
- /opt/postfixadmin-db-data:/var/lib/mysql
postfixadmin:
image: postfixadmin:fpm
container_name: postfixadmin
ports:
- 9000:9000
environment:
POSTFIXADMIN_DB_TYPE: mysqli
POSTFIXADMIN_DB_HOST: postfixadmin-db
POSTFIXADMIN_DB_USER: postfixadmin
POSTFIXADMIN_DB_NAME: postfixadmin
POSTFIXADMIN_DB_PASSWORD: welcome@2023
POSTFIXADMIN_SETUP_PASSWORD: $2y$10$3x1qygHUpsdb42FuG0DfYumBEEWQssfjK0ib8cEHQMIFgTAuV1gq2
CONF_SMTP_SERVER: smtp.gmail.com
CONF_SMTP_PORT: '587'
CONF_SMTP_USER: example@gmail.com
CONF_SMTP_PASS: example
volumes:
- /opt/postfixadmin-data:/var/www/html
depends_on:
- postfixadmin-db
volumes:
postfixadmin-db-data:
postfixadmin-data:
Save the docker-compose.yml file.
or building the postfix admin docker image from the source.
Procedure to build the Postfix Admin Docker image from its source code. By meticulously following these instructions, you will be able to obtain the necessary Docker image for Postfix Admin, facilitating its seamless integration within your setup.
Step 1: Cloning the Repository:
Begin by cloning the official Postfix Admin Docker repository using the following command:
Copy
git clone https://github.com/postfixadmin/docker.git
Change your current directory to the newly cloned repository:
Copy
cd docker
Step 2: Building the Docker Image:
Within the cloned repository directory, initiate the Docker image-building process. The following command accomplishes this:
Copy
docker build --pull --rm -t postfixadmin-image
In this command, replace with the specific variant of the image you intend to build. For our purposes, we will utilize the "fpm" variant.
Copy
docker build --pull --rm -t postfixadmin-image fpm
This command ensures that the image is pulled and built anew, with the image tagged as "postfixadmin-image."
Step 3: Integrating the Docker Image:
After successfully building the Docker image for Postfix Admin, you can now incorporate it into your Docker Compose setup.
Modify your existing Docker Compose file to include the newly created Postfix Admin image. For instance:
Copy
version: '3'
services:
postfixadmin-db:
# ... (MySQL configuration)
postfixadmin:
image: postfixadmin-image # Utilize the newly built image
container_name: postfixadmin
ports:
- 9000:9000
# ... (Other configuration settings)
Save the Docker Compose file after including the Postfix Admin image.
Step 2: Nginx Configuration:
On your server, create an Nginx configuration file for Postfix Admin. Let's name it postfixadmin.example.com.conf.
Add the following configuration to the file, modifying paths, server_name, and other details as needed:
Copy
server {
listen 80;
server_name postfixadmin.example.com;
root /var/www/html; # Path to your Postfix Admin container's web root
location / {
index index.php index.html;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass postfixadmin:9000; # Point to the PHP-FPM container within the Docker network
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Save the Nginx configuration file.
Step 3: Deploy and Configure:
Deploy the Docker containers by running docker-compose up -d in the project directory.
Ensure your DNS settings have the domain postfixadmin.example.com pointing to your server's IP address.
Upload your Nginx configuration file to the appropriate Nginx configuration directory (e.g., /etc/nginx/sites-available/) and create a symbolic link to enable it:
Copy
sudo ln -s /etc/nginx/sites-available/postfixadmin.example.com.conf /etc/nginx/sites-enabled/
Test Nginx configuration for syntax errors: sudo nginx -t
Reload Nginx to apply changes: sudo systemctl reload nginx
Step 4: Access Postfix Admin:
Open a web browser and navigate to http://postfixadmin.example.com.
Log in using the setup password provided in your docker-compose.yml file.
You can now manage your Postfix mail server using the Postfix Admin web interface.
Conclusion: Congratulations! You've successfully set up Postfix Admin within a PHP-FPM Docker container and configured an external Nginx server to handle incoming requests. This configuration provides a convenient way to manage your Postfix mail server through a user-friendly web interface. Make sure to keep your server and software updated to ensure security and stability.
This content originally appeared on DEV Community and was authored by Praneeth Perera
Praneeth Perera | Sciencx (2024-08-30T03:51:49+00:00) Configuring Postfix Admin in PHP-FPM Docker with Nginx Server on Host Machine. Retrieved from https://www.scien.cx/2024/08/30/configuring-postfix-admin-in-php-fpm-docker-with-nginx-server-on-host-machine/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.