Dorokhov.codes
01. Development process
To start WordPress development we can take a Docker image.
Dockerfile:
FROM wordpress:php8.2-apache
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions xdebug
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
# Modify PHP settings using sed
# max_execution_time - This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser.
# max_input_time - This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET.
# post_max_size - Sets max size of post data allowed. This setting also affects file upload.
# memory_limit - This sets the maximum amount of memory in bytes that a script is allowed to allocate.
RUN sed -i 's/upload_max_filesize = .*/upload_max_filesize = 30720M/' /usr/local/etc/php/php.ini && \
sed -i 's/max_input_time = .*/max_input_time = -1/' /usr/local/etc/php/php.ini && \
sed -i 's/memory_limit = .*/memory_limit = -1/' /usr/local/etc/php/php.ini && \
sed -i 's/post_max_size = .*/post_max_size = 30720M/' /usr/local/etc/php/php.ini && \
sed -i 's/max_execution_time = .*/max_execution_time = 86400/' /usr/local/etc/php/php.ini
# I use this to avoid the error "413 Request Entity Too large"
RUN echo "LimitRequestBody 0" > /etc/apache2/conf-available/custom.conf && a2enconf custom
# Setting up xDebug for PHP
RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
echo "xdebug.client_host=192.168.1.13" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
I use the next docker-compose.yml
:
services:
wordpress:
container_name: project.wp
build: .
ports:
- "80:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DEBUG: 1
WORDPRESS_CONFIG_EXTRA: |
define( 'FS_METHOD', 'direct' );
define( 'DISABLE_WP_CRON', true );
depends_on:
- db
volumes:
- ./volumes/wordpress:/var/www/html
db:
container_name: project.db
image: mysql:5.7
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- ./volumes/db:/var/lib/mysql
phpmyadmin:
container_name: project.phpmyadmin
image: phpmyadmin
ports:
- "81:80"
environment:
- PMA_HOST=db
- PMA_USER=wordpress
- PMA_PASSWORD=wordpress
- UPLOAD_LIMIT=3000M
depends_on:
- db
We can choose a specific WP version (wordpress:php7.4-apache
, for example).
Command:
docker compose up
The default owner of the files in the image is www-data
. We should change the owner of the wp-content
(or of the whole wordpress
folder):
sudo chown andrew -R volumes/wordpress/
And leave possibility for the www-data
to update files:
sudo chmod g+rw * -R volumes/wordpress/
Docker images
MySQL:
mysql:5.7
mysql:8.0.35
WordPress:
wordpress:php8.2-apache
wordpress:php8.1-apache
wordpress:php8.0-apache
wordpress:php7.4-apache
Update options
If you need to find and update some options quickly, you can directly access the /wp-admin/options.php
path.
Plugins for development
Name | Description |
---|---|
Query Monitor | Great developer tools panel for WordPress. |
Debug Bar | Adds a debug menu to the admin bar that shows query, cache, and other helpful debugging information. |
Debug Bar Console | Adds a PHP/MySQL console to the debug bar. |
Debug Bar Shortcodes | Adds a new panel to the Debug Bar that displays the registered shortcodes for the current request. |
Debug Bar Constants | Adds three new panels to the Debug Bar that display the defined constants. |
Debug Bar Post Types | Adds a new panel to the Debug Bar that displays detailed information about the registered post types. |
Debug Bar Cron | Adds information about WP scheduled events. |
Debug Bar Actions and Filters Addon | Adds two more tabs in the Debug Bar to display hooks (actions and filters). |
Debug Bar Transients | Adds information about WordPress Transients to a new panel in the Debug Bar. |
Debug Bar List Script & Style Dependencies | Adds information to view the loaded scripts and styles. |
Debug Bar Remote Requests | Debug Bar plugin that will log and profile remote requests made through the HTTP API. |
Download ZIP file with all these plugins:
Query Monitor - v3.15.0
Debug Bar - v1.1.4
Debug Bar Console - v0.3
Debug Bar Shortcodes - v2.0.3
Debug Bar Constants - v2.0.0
Debug Bar Post Types - v2.0.0
Debug Bar Cron - v0.1.3
Debug Bar Actions and Filters Addon - v1.5.5
Debug Bar Transients - v0.5
Debug Bar List Script & Style Dependencies - v1.1.2
Debug Bar Remote Requests - v0.1.2
Backups and migrations
For the development purpose, it’s always a good idea to restore the client’s WordPress project on a local environment. To do it, we have several options.
All-in-One WP Migration plugin
There’s a good plugin for this: All-in-One WP Migration
. Link.
It the size of a backup is large, we can simply put a *.wpress
file into the /wp-content/ai1wm-backup
without
importing it through the web interface.
You can check the PHP version in the backup (package.json
file) before downloading an appropriate Docker WP image.
Duplicator plugin
Another good option is the Duplicator plugin.
UpdraftPlus
https://updraftplus.com - WordPress Backup and Migration Plugin.
Manual migration
To manually do a migration, we need to copy the WordPress project’s files and copy the database. So there are two tasks.