Deployment Overview of WordPress + WooCommerce plugin on Server¶
Prerequisites and Basic Requirements¶
The deployment requires a Debian-based operating system with root privileges. The following system components and network configurations are necessary:
- Operating System: Debian-based distribution.
- Privileges: Root access is required for installing Docker, managing system services, and configuring the proxy.
- Ports:
- Port
443for HTTPS traffic via the Nginx proxy. - Port
9000(bound to127.0.0.1) for internal communication between Nginx and the PHP-FPM container. - Domain: A valid domain name configured to point to the server IP address is required for SSL certificate generation.
- Software: Docker Engine and Docker Compose must be installed on the host system.
File and Directory Structure¶
The application files, configuration data, and certificates are organized in the following locations on the server:
/data/wordpress: Contains the WordPress core files and thewp-content/plugins/woocommercedirectory./root/wordpress: Contains thecompose.ymlfile used to orchestrate the Docker containers./data/nginx/user_conf.d: Stores the Nginx server configuration files./data/nginx/nginx-certbot.env: Contains environment variables for the Nginx-Certbot container./etc/letsencrypt: Stores SSL certificates and keys generated by Certbot./tmp: Temporary location used during the initial extraction of the WooCommerce plugin archive.
Application Installation Process¶
The application is deployed using Docker containers orchestrated via Docker Compose. The installation involves the following steps:
- System Preparation: Update APT packages and install prerequisites such as
lsb-release,apt-transport-https,vim,htop, andzip. - Directory Creation: Create the
/data/wordpressdirectory with ownership set to user ID33and group ID33. - Plugin Installation:
- Download the WooCommerce plugin version
8.7.0from the official WordPress repository. - Extract the archive to
/tmp. - Move the
woocommercefolder to/data/wordpress/wp-content/plugins/.
- Download the WooCommerce plugin version
- Docker Deployment:
- Install Docker Engine.
- Configure the Nginx proxy and generate the necessary configuration files.
- Create the
/root/wordpressdirectory. - Generate the
compose.ymlfile defining the services. - Execute
docker compose up -din the/root/wordpressdirectory to start the containers.
Docker Containers and Their Deployment¶
The application consists of three primary services defined in the compose.yml file located at /root/wordpress/compose.yml:
- MariaDB:
- Image:
bitnami/mariadb:latest - Purpose: Database storage.
- Volume:
mariadb_datamounted to/bitnami/mariadbfor persistent data. -
Environment Variables:
MARIADB_USER:wordpressMARIADB_DATABASE:wordpressMARIADB_PASSWORD: Set via the deployment script.MARIADB_ROOT_PASSWORD: Set via the deployment script.
-
WordPress:
- Image:
docker.io/wordpress:php8.2-fpm - Purpose: PHP-FPM application server.
- Port:
127.0.0.1:9000mapped to container port9000. - Volume:
/data/wordpressmounted to/var/www/html. - Dependencies: Starts after the
mariadbservice. -
Environment Variables:
MYSQL_ROOT_PASSWORD: Set via the deployment script.WORDPRESS_DB_PASSWORD: Set via the deployment script.WORDPRESS_DB_HOST:mariadbWORDPRESS_DB_USER:wordpressWORDPRESS_DB_NAME:wordpress
-
Nginx:
- Image:
jonasal/nginx-certbot:latest - Purpose: Reverse proxy and SSL termination.
- Network Mode:
host. - Dependencies: Starts after the
wordpressservice. - Environment Variables:
CERTBOT_EMAIL:[email protected]
- Volumes:
nginx_secretsmounted to/etc/letsencrypt./data/nginx/user_conf.dmounted to/etc/nginx/user_conf.d./data/wordpressmounted to/var/www/html.
Proxy Servers¶
The Nginx container acts as the reverse proxy, handling SSL termination and routing traffic to the WordPress PHP-FPM container.
- Configuration File: The server block is defined in
/data/nginx/user_conf.d/<prefix><server_id>.<zone>.conf. - SSL Configuration:
- Listens on port
443with SSL enabled. - Certificates are stored in
/etc/letsencrypt/live/<prefix><server_id>.<zone>/. - Uses
fullchain.pemfor the certificate,privkey.pemfor the key, andchain.pemfor the trusted certificate. - Routing Rules:
- The root location
/serves static files and routes PHP requests toindex.php. - The
location ~ \.php$block handles PHP execution:- Passes requests to
localhost:9000. - Sets
SCRIPT_FILENAMEandPATH_INFOfor FastCGI processing. - Includes standard
fastcgi_params.
- Passes requests to
Databases¶
The application uses a MariaDB database managed within a Docker container.
- Connection Method: The WordPress container connects to the database service named
mariadbwithin the Docker network. - Storage Location: Database data is persisted in the named volume
mariadb_data. - Database Settings:
- Database Name:
wordpress - Database User:
wordpress - Root Password and User Password: Configured dynamically during the deployment process.
Permission Settings¶
File and directory permissions are configured as follows to ensure proper operation:
/data/wordpress:- Owner:
33(www-data) - Group:
33(www-data) - Mode:
0755 /root/wordpress:- Owner:
root - Group:
root - Mode:
0640 /data/nginx/user_conf.d/<prefix><server_id>.<zone>.conf:- Owner:
root - Group:
root - Mode:
0644 /root/wordpress/compose.yml:- Owner:
root - Group:
root - Mode:
0644
Starting, Stopping, and Updating¶
The services are managed using Docker Compose commands executed from the /root/wordpress directory.
- Start Services:
- Stop Services:
- Update Services: To update the application, pull the latest images and restart the containers:
- View Logs: