Skip to content

Wordpress

Iva edited this page Aug 23, 2024 · 6 revisions

Wordpress Docker

  • WordPress Installation and Configuration

    Some tools will be necessary for the communication between the WordPress program and the MariaDB database to be possible:

    • mysqli: A PHP extension, similar to a “library” to be “included” in PHP files, responsible for allowing PHP programs to execute MariaDB commands. Necessary because WordPress is a PHP program, and this allows WordPress to make modifications and searches in the database.
    • wp-config.php: A configuration file read during the WordPress initialization, responsible for configuring the operation in connection with the database. Therefore, it is necessary to create this file in a customized way before creating the WordPress Docker image.
    • Add the mysqli installation command, which will be used to allow access and modification commands to MariaDB by PHP files, and curl, which will be used to download the WordPress CLI from the internet, for later installation, in the Dockerfile for WordPress:

      FROM debian:bullseye
      RUN apt update && apt upgrade -y && apt install -y \
      php7.4-fpm \
      php7.4-mysqli \
      curl
      RUN mkdir -p /run/php && chown -R www-data:www-data /run/php
      COPY conf/www.conf /etc/php/7.4/fpm/pool.d/.
      ENTRYPOINT ["php-fpm7.4", "-F"]
    • Create the bash script wp-install.sh in the /srcs/requirements/wordpress/tools/ directory, which will be responsible for installing the WordPress CLI, downloading the main WordPress files, creating and configuring the wp-config.php file, and installing WordPress:

      #!/bin/bash
      cd /var/www/html
      curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
      chmod +x wp-cli.phar
      sleep 5
      ./wp-cli.phar core download --allow-root
      ./wp-cli.phar config create --dbname=wordpress --dbuser=wpuser --dbpass=password --dbhost=mariadb --allow-root
      ./wp-cli.phar core install --url=localhost --title=inception --admin_user=ivbatist --admin_password=123456789 --admin_email=ivbatist@inception.com --allow-root
      ./wp-cli.phar user create guest guest@inception.com --role=subscriber --user_pass=123456789 --allow-root
      
      php-fpm7.4 -F

      👉🏼 The parameters passed to create the wp-install.sh file and create a WordPress account should later be passed through environment variables.

    • Add the copy command for the wp-install.sh script from the /srcs/requirements/wordpress/tools/ directory to the current /srcs/requirements/wordpress/ directory, change the execution permissions of the script, and change the final execution command from php-fpm to the script execution in the Dockerfile for WordPress:

      FROM debian:bullseye
      RUN apt update && apt upgrade -y && apt install -y \
      php7.4-fpm \
      php7.4-mysqli \
      curl
      RUN mkdir -p /run/php && chown -R www-data:www-data /run/php
      COPY conf/www.conf /etc/php/7.4/fpm/pool.d/.
      COPY ./tools/wp-install.sh .
      RUN chmod +X wp-install.sh
      ENTRYPOINT ["./wp-install.sh"]

      👉🏼 At this stage, you can test the WordPress configuration's functionality by rebuilding the images and starting all the containers. Finally, accessing the address http://localhost should display a static, styled page created by WordPress.

    ⏮️ Previous
    Next ⏭️

Clone this wiki locally