Skip to content
Joonas Sandell edited this page Apr 28, 2024 · 7 revisions

About plugins

If you're using caching or optimization plugins such as Autoptimize or W3 Total Cache you should disable locally because they might create issues with CORS and Vite etc.

Should database/wordpress.sql be ignored?

Well maybe but it's easier for other developers to install the project in the future if they have some starting point. If you don't like this, just remove the !database/wordpress.sql from .gitignore.

Why using wordpress:php*-apache docker image if installing WordPress w/ composer?

Because the official image includes all the basics WordPress requires. Image could very well be php:*-apache etc. as well.

How to setup a multisite network

How to setup a multisite with path-based install. This guide assumes that the project contains a MySQL dump in database/wordpress.sql.

  1. Read Before You Create A Network
  2. Change all strings with localhost:8000 to localhost and change ports: 8000:80 to ports: 80:80 in docker-compose.yml. E.g. make sure you don't have port in the dev url
  3. Restart docker. Note that your new site is now located in localhost
  4. Run docker-compose exec web bash -c "wp search-replace 'localhost:8000' 'localhost' --allow-root --network" to replace all the old strings in database
  5. Run docker-compose exec web bash -c "wp search-replace 'localhost/wp' 'localhost' wp_options --allow-root --network" so that the site root is set correctly
  6. Do steps Allow Multisite and Installing a Network. Add the instructed line to wp-config.php:~103:
/**
 * Setup multisite
 */
define('WP_ALLOW_MULTISITE', true);
  1. As instructed in step 6. make sure the following lines are in wp-config.php:~103 & wp-config.example.php:~103 with the correct domain:
/**
 * Setup multisite
 */
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', getenv('WORDPRESS_ENV') == 'development' ? '127.0.0.1' : 'example.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
  1. As instructed in step 6. make sure the following lines are in .htaccess & .htaccess.example:
# ======
# WordPress
# ======

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) wp/$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ wp/$2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
  1. Change define('WP_SITEURL', getenv('DEVELOPMENT_URL') . '/wp'); -> define('WP_SITEURL', getenv('DEVELOPMENT_URL')); in in wp-config.php & wp-config.example.php to prevent confusion.
  2. Activate plugins you had to deactivate in step 6.
  3. At this time, in path-based installs you cannot remove the /blog slug without manual configuration to the network options in a non-obvious place. Make sure your permalinks are set as wanted with custom structure (e.g. /articles/%postname%) or you can remove the /blog which is not recommended.
  4. Update your database dump once you have created network and added sub blogs with $ make db-commit. Remember to commit all your changes.

In production my WordPress home is located in a subdir (e.g. mysite.com/myhome). How to make it work?

  1. In wp-config.php
    • Change define('WP_SITEURL', 'mysite.com/wp'); to define('WP_SITEURL', 'mysite.com/myhome/wp');
    • Change define('WP_CONTENT_URL', 'https://' . $_SERVER['HTTP_HOST'] . '/wp-content'); to define('WP_CONTENT_URL', 'https://' . $_SERVER['HTTP_HOST'] . '/myhome/wp-content');
    • Change define('ABSPATH', dirname( __FILE__ ) . '/wp/'); to define('ABSPATH', dirname( __FILE__ ) . '/myhome/wp/');
    • If using WPMS change define('PATH_CURRENT_SITE', getenv('WORDPRESS_ENV') == 'development' ? '/' : '/'); to define('PATH_CURRENT_SITE', getenv('WORDPRESS_ENV') == 'development' ? '/' : '/myhome/');
  2. In .env add your home dir to PRODUCTION_WP_HOME (e.g. PRODUCTION_WP_HOME=/myhome) so that replacing databases works correctly
  3. In .htaccess make sure rewritebase is RewriteBase /myhome (not needed in WPMS)

I'm getting the error the input device is not a TTY

Try to add export COMPOSE_INTERACTIVE_NO_CLI=1 to your shell and if it works you should add it to your bash profile. https://github.com/docker/compose/issues/5696