diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2cc706b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +data +.env* \ No newline at end of file diff --git a/Dockerfile-wordpress-xdebug b/Dockerfile-wordpress-xdebug new file mode 100644 index 0000000..fd7a1f1 --- /dev/null +++ b/Dockerfile-wordpress-xdebug @@ -0,0 +1,24 @@ +# Original: https://marioyepes.com/setup-debug-php-docker-visual-studio-code + +ARG DOCKER_IMG_TAG + +# Source image +FROM wordpress:${DOCKER_IMG_TAG} + +# We're going to use this path multile times. So save it in a variable. +ARG XDEBUG_INI="/usr/local/etc/php/conf.d/xdebug.ini" + +COPY ./wordpress-xdebug/plugins /root/wp-plugins + +# Install AND configure Xdebug +RUN pecl install xdebug \ + && docker-php-ext-enable xdebug \ + && echo "[xdebug]" > $XDEBUG_INI \ + && echo "xdebug.mode = debug" >> $XDEBUG_INI \ + && echo "xdebug.start_with_request = trigger" >> $XDEBUG_INI \ + && echo "xdebug.client_port = 9003" >> $XDEBUG_INI \ + && echo "xdebug.client_host = 'host.docker.internal'" >> $XDEBUG_INI \ + && echo "xdebug.log = /tmp/xdebug.log" >> $XDEBUG_INI + +RUN cp -Rf /root/wp-plugins/* /var/www/html/wp-content/plugins/ \ + && chown -R www-data:www-data /var/www/html/wp-content/plugins/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f51393a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,65 @@ +services: + db: + image: mariadb:${MARIADB_IMG_TAG} + command: "--log-bin=mysqld-bin" + # volumes: + # - ./data/mysql:/var/lib/mysql + restart: "no" + environment: + MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} + MARIADB_DATABASE: ${DB_DATABASE} + MARIADB_USER: ${DB_USER} + MARIADB_PASSWORD: ${DB_PASSWORD} + + + phpmyadmin: + image: phpmyadmin:latest + restart: "no" + depends_on: + - db + ports: + - ${PHPMYADMIN_LOCAL_PORT}:80 + environment: + PMA_ARBITRARY: "1" + PMA_HOST: db + PMA_USER: root + PMA_PASSWORD: ${DB_ROOT_PASSWORD} + + # Optional for WordPress redis cache plugin + redis: + # restart: always + restart: "no" + image: bitnami/redis:${REDIS_IMG_TAG} + environment: + - ALLOW_EMPTY_PASSWORD=yes + # volumes: + # - ./data/redis:/bitnami/redis/data + command: /opt/bitnami/scripts/redis/run.sh --maxmemory 100mb + + wordpress: + # image: wordpress:${WORDPRESS_IMG_TAG} + build: + context: . + dockerfile: Dockerfile-wordpress-xdebug + args: + - DOCKER_IMG_TAG=${WORDPRESS_IMG_TAG} + image: badbuta/wordpress-debug:${WORDPRESS_IMG_TAG} + # env_file: + # - .env + depends_on: + - db + - redis + volumes: + # - ./data/wp-content:/var/www/html/wp-content + # - ./data/php/upload.ini:/usr/local/etc/php/conf.d/uploads.ini + - ./wordpress-xdebug/plugins/wordpress-docker-xdebug/plugin.php:/var/www/html/wp-content/plugins/wordpress-docker-xdebug/plugin.php:ro + ports: + - ${WORDPRESS_LOCAL_PORT}:80 + # restart: always + restart: "no" + environment: + WORDPRESS_DB_HOST: db + WORDPRESS_DB_NAME: ${DB_DATABASE} + WORDPRESS_DB_USER: ${DB_USER} + WORDPRESS_DB_PASSWORD: ${DB_PASSWORD} + WORDPRESS_CONFIG_EXTRA: ${WORDPRESS_CONFIG_EXTRA} diff --git a/sample.env b/sample.env new file mode 100644 index 0000000..a606adb --- /dev/null +++ b/sample.env @@ -0,0 +1,11 @@ +DB_ROOT_PASSWORD=wordpress +DB_DATABASE=wordpress +DB_USER=wordpress +DB_PASSWORD=wordpress + +MARIADB_IMG_TAG=10.10 +PHPMYADMIN_LOCAL_PORT=40081 +REDIS_IMG_TAG=6.2.8 +WORDPRESS_IMG_TAG=6.1.1 +WORDPRESS_LOCAL_PORT=40080 +WORDPRESS_CONFIG_EXTRA="define( 'WP_AUTO_UPDATE_CORE', false ); \n define( 'WP_HOME', 'http://localhost:40080' ); \n define( 'WP_SITEURL', 'http://localhost:40080' ); \n define( 'WP_REDIS_HOST', 'redis' ); \n define( 'WP_REDIS_PORT', 6379 ); \n // define( 'WP_REDIS_PASSWORD', 'secret' ); \n define( 'WP_REDIS_TIMEOUT', 1 ); \n define( 'WP_REDIS_READ_TIMEOUT', 1 ); \n define( 'WP_REDIS_DATABASE', 0 );" \ No newline at end of file diff --git a/wordpress-xdebug/plugins/wordpress-docker-xdebug/plugin.php b/wordpress-xdebug/plugins/wordpress-docker-xdebug/plugin.php new file mode 100644 index 0000000..a75d6d7 --- /dev/null +++ b/wordpress-xdebug/plugins/wordpress-docker-xdebug/plugin.php @@ -0,0 +1,44 @@ + Xdebug Info + * Version: 1.0.0 + * Requires at least: 5.2 + * Requires PHP: 7.2 + * Author: Mario Yepes + * Author URI: https://marioyepes.com + * Text Domain: wordpress-docker-xdebug + * License: GPL v2 or later + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt + * Update URI: https://marioyepes.com + */ + +add_action( 'admin_menu', 'add_php_info_page' ); + +function add_php_info_page() { + add_submenu_page( + 'tools.php', // Parent page + 'Xdebug Info', // Menu title + 'Xdebug Info', // Page title + 'manage_options', // user "role" + 'php-info-page', // page slug + 'php_info_page_body'); // callback function +} + +function php_info_page_body() { + $message = '

No Xdebug enabled

'; + if ( function_exists( 'xdebug_info' ) ) { + xdebug_info(); + } else { + echo $message; + } +} \ No newline at end of file