Setting up WordPress, MySQL, and phpMyAdmin using Docker Compose via Git
This guide demonstrates setting up WordPress, MySQL, and phpMyAdmin using Docker Compose version 3.1. This setup allows you to quickly create a local development environment for WordPress with a MySQL database and phpMyAdmin for database management.
Docker Compose File (docker-compose.yml
)
version: '3.1'
services:
wordpress:
image: wordpress:php7.2-apache
ports:
- "8001:80"
environment:
WORDPRESS_DB_HOST: mysql
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD:
WORDPRESS_DB_NAME: wordpress_db
volumes:
- ./website:/var/www/html
- ./ssl:/etc/apache2/ssl # Mount SSL directory
depends_on:
- mysql
networks:
- my_network
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: wordpress_db
MYSQL_ROOT_PASSWORD:
ports:
- "3306:3306"
volumes:
- ./data:/var/lib/mysql
networks:
- my_network
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mysql
ports:
- "8081:80"
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD:
networks:
- my_network
networks:
my_network:
driver: bridge
Bash Script (setup.sh
)
#!/bin/bash
# Function to generate SSL certificates
generate_ssl_certificates() {
SSL_DIR="./ssl"
PRIVATE_KEY="$SSL_DIR/private.key"
CERTIFICATE="$SSL_DIR/certificate.crt"
# Create SSL directory if it doesn't exist
mkdir -p $SSL_DIR
# Generate SSL certificate if not already present
if [ ! -f "$PRIVATE_KEY" ] || [ ! -f "$CERTIFICATE" ]; then
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$PRIVATE_KEY" -out "$CERTIFICATE"
fi
}
# Function to start containers using Docker Compose
start_containers() {
docker-compose up -d
}
# Main function
main() {
generate_ssl_certificates
# Start containers using Docker Compose
start_containers
}
# Execute main function
main
Instructions for Setup
- Ensure Docker and Docker Compose are installed on your system.
- Clone the GitHub repository:
git clone https://github.com/j551n-ncloud/
wordpress/wordpress.git - Navigate to the cloned directory:
cd wordpress
- Create the
docker-compose.yml
file with the provided content. - Create the
setup.sh
file with the provided content. - Make the
setup.sh
file executable:chmod +x setup.sh
- Execute the script to start the containers:
./setup.sh
This setup will launch WordPress accessible at http://localhost:8001
, phpMyAdmin accessible at http://localhost:8081
, and MySQL running internally. Additionally, SSL certificates will be generated for the Apache server hosting WordPress. You can customize ports and environment variables as per your requirements.
Please ensure to handle sensitive information like passwords securely, especially in a production environment.