How to Have Many WordPress Development Sites with Only One Install
Goals
- Many web hosts. One host for each customer development site.
- Multiple databases. One for each site.
- Multiple upload directories. One for each site.
- Only one WordPress installation.
- Only one plugins and theme directory.
- One PHP installation. Different PHP versions can be used for each web site.
Create a virtual web host for each site.
<VirtualHost *:80>
ServerName "acme-cannons.pondermatic.com"
Redirect "/" "https://acme-cannons.pondermatic.com"
</VirtualHost>
<VirtualHost *:443>
ServerName "acme-cannons.pondermatic.com"
ServerAdmin "webmaster@happycorner.us"
CustomLog "C:/customers/acme-cannons/wordpress-develop/logs/access_%Y-%m-%d.log" common
ErrorLog "C:/customers/acme-cannons/wordpress-develop/logs/error.log"
# WordPress
DocumentRoot "C:/customers/acme-cannons/wordpress-develop/src"
<Directory "C:/customers/acme-cannons/wordpress-develop/src">
Require all granted
AllowOverride FileInfo
Options +ExecCGI
Options -MultiViews
# php FastCGI
FcgidWrapper "${PHP80}/php-cgi-wordpress.exe -c ${PHP80}/php-wordpress.ini -d error_log=\"C:/customers/acme-cannons/wordpress-develop/logs/php_errors.log\"" .php
</Directory>
Alias "/wp-content/uploads" "C:/customers/acme-cannons/wordpress-develop/uploads"
<Directory "C:/customers/acme-cannons/wordpress-develop/uploads">
Require all granted
</Directory>
</VirtualHost>
Install WordPress.
git clone https://github.com/WordPress/wordpress-develop.git C:/wordpress-develop
Checkout and build a WordPress version.
cd c:/wordpress-develop
git checkout --no-track -b Branch_5.9.0 5.9.0 --
composer install
npm install
npm run build:dev
Add and commit the un-versioned assets that were just built from these directories.
- src/wp-admin/css
- src/wp-admin/js
- src/wp-includes/blocks
- src/wp-includes/css
- src/wp-includes/js
There is no need to add the node_modules
or vendor
directories.
Now it is easy to switch between different versions of WordPress.
Create a directory that contains:
- a symlink to the WordPress
src
directorymklink /D src C:\wordpress-develop\src
- an
uploads
directory
Create a src/wp-config.php
file that:
- loads the appropriate config file from
wordpress-develop
based ongetcwd()
or exits with an error message- The config file should define where the WordPress debug log is.
define( 'WP_DEBUG_LOG', 'C:/customers/acme-cannons/wordpress-develop/logs/wp_debug.log' );
require_once( ABSPATH . 'wp-settings.php' );
- The config file should define where the WordPress debug log is.
<?php
$virtual_hosts = array(
'acme-cannons' => 'C:/customers/acme-cannons/wordpress/',
'acme-rockets' => 'C:/customers/acme-rockets/wordpress/',
);
$current_working_directory = str_replace( '\\', '/', getcwd() );
$found = false;
foreach ( $virtual_hosts as $virtual_host => $directory ) {
if ( strpos( $current_working_directory, $directory ) === 0 ) {
require_once dirname( ABSPATH ) . DIRECTORY_SEPARATOR . "wp-config-$virtual_host.php";
$found = true;
break;
}
}
if ( false === $found ) {
exit( "Host directory not found for $current_working_directory." );
}
require_once( ABSPATH . 'wp-settings.php' );
define( 'WP_ENVIRONMENT_TYPE', 'development' );
/* That's all, stop editing! Happy publishing. */
Leave a Reply