Skip to content

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 443 for HTTPS traffic via the Nginx proxy.
  • Port 9000 (bound to 127.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 the wp-content/plugins/woocommerce directory.
  • /root/wordpress: Contains the compose.yml file 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:

  1. System Preparation: Update APT packages and install prerequisites such as lsb-release, apt-transport-https, vim, htop, and zip.
  2. Directory Creation: Create the /data/wordpress directory with ownership set to user ID 33 and group ID 33.
  3. Plugin Installation:
    • Download the WooCommerce plugin version 8.7.0 from the official WordPress repository.
    • Extract the archive to /tmp.
    • Move the woocommerce folder to /data/wordpress/wp-content/plugins/.
  4. Docker Deployment:
    • Install Docker Engine.
    • Configure the Nginx proxy and generate the necessary configuration files.
    • Create the /root/wordpress directory.
    • Generate the compose.yml file defining the services.
    • Execute docker compose up -d in the /root/wordpress directory 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_data mounted to /bitnami/mariadb for persistent data.
  • Environment Variables:

    • MARIADB_USER: wordpress
    • MARIADB_DATABASE: wordpress
    • MARIADB_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:9000 mapped to container port 9000.
  • Volume: /data/wordpress mounted to /var/www/html.
  • Dependencies: Starts after the mariadb service.
  • Environment Variables:

    • MYSQL_ROOT_PASSWORD: Set via the deployment script.
    • WORDPRESS_DB_PASSWORD: Set via the deployment script.
    • WORDPRESS_DB_HOST: mariadb
    • WORDPRESS_DB_USER: wordpress
    • WORDPRESS_DB_NAME: wordpress
  • Nginx:

  • Image: jonasal/nginx-certbot:latest
  • Purpose: Reverse proxy and SSL termination.
  • Network Mode: host.
  • Dependencies: Starts after the wordpress service.
  • Environment Variables:
  • Volumes:
    • nginx_secrets mounted to /etc/letsencrypt.
    • /data/nginx/user_conf.d mounted to /etc/nginx/user_conf.d.
    • /data/wordpress mounted 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 443 with SSL enabled.
  • Certificates are stored in /etc/letsencrypt/live/<prefix><server_id>.<zone>/.
  • Uses fullchain.pem for the certificate, privkey.pem for the key, and chain.pem for the trusted certificate.
  • Routing Rules:
  • The root location / serves static files and routes PHP requests to index.php.
  • The location ~ \.php$ block handles PHP execution:
    • Passes requests to localhost:9000.
    • Sets SCRIPT_FILENAME and PATH_INFO for FastCGI processing.
    • Includes standard fastcgi_params.

Databases

The application uses a MariaDB database managed within a Docker container.

  • Connection Method: The WordPress container connects to the database service named mariadb within 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:
    cd /root/wordpress
    docker compose up -d
    
  • Stop Services:
    cd /root/wordpress
    docker compose down
    
  • Update Services: To update the application, pull the latest images and restart the containers:
    cd /root/wordpress
    docker compose pull
    docker compose up -d
    
  • View Logs:
    cd /root/wordpress
    docker compose logs -f
    
question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×