Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WordPress Docker Compose Setup

This a local development setup that allows you to run a WordPress easily using docker compose. This is basically an alternative to using MAMP to quickly spin up a site on your local.

Requirements:

  1. Docker

Setup

  1. Download your FULL (WordPress core included) WordPress website and put it into the ./site directory.
  2. Update the wp-config.php to have the following database connection information:
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** Database username */
define( 'DB_USER', 'wordpress' );

/** Database password */
define( 'DB_PASSWORD', 'wordpress' );

/** Database hostname */
define( 'DB_HOST', 'database' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
  1. Download a copy of the WordPress database and put it in the ./docker/initdb/ folder (it can have a .gz extension if you want to save space)
  2. Build the WordPress Docker image by running docker compose build --no-cache
  3. Bring up the services with docker compose up -d
  4. Your site should appear at http://localhost

Tips and Tricks

Note: Depending on your setup you may need to go into the phpMyAdmin service and update the wordpress database options table. The two options you would need to update are siteurl and home - these may need to be set to http://localhost but it may work fine without changing it.

You may want to implement a wp-config-local.php file rather than directly changing the database settings in your wp-config.php file. To do this, simply add the following line to your wp-config.php (this can be committed to source control if you choose since it checks if the file exists before loading it's content):

// Load local configuration if it exists
if (file_exists(__DIR__ . '/wp-config-local.php')) {
    require_once __DIR__ . '/wp-config-local.php';
}

You can then override any settings you want to in the wp-config-local.php file. As an example, you can override the options siteurl and home from this file instead of changing them in the database with the following settings:

// Override siteurl and home options
define('WP_SITEURL', 'http://localhost');
define('WP_HOME', 'http://localhost');

Changing PHP Version

If you want to update the PHP version, do the following steps:

  1. Ensure your services are not running by using docker compose down
  2. Replace every instance of 8.2 in the ./Dockerfile and ./docker/nginx/nginx.conf files
  3. Run docker compose build --no-cache to build the image with the new PHP version
  4. Spin up your services with docker compose up -d

About

Local development setup to quickly spin up a WordPress site using `docker compose` as an alternative to MAMP.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages