For each site, WordPress core files are separated from wp-content into their own subfolder. That subfolder is actually a symbolic link to a single copy of the WordPress core files.
A pointer wp-config file sits next to this single copy of core files and dynamically points to the correct wp-config file within the directory for each site.
First, clone the repository into a folder on your local development server. Be sure to initialize submodules.
$ git clone https://github.com/creativecoder/wordpress-local-dev.git wp-sites
$ cd wp-sites
$ git submodule update --init --recursive
The project has the following structure
Project root ..
- wp-config.php file (used for local development only; points to each site folder dynamically, depending on which site is being loaded)
- wordpress (git submodule of the official WordPress git repository )
- sample.local (sample site folder)
- index.php (which looks in the /wordpress folder to run wordpress)
- wp-content folder (for themes and plugins)
- wp-config.php (site configuration, except for database credientials, which go in files below)
- local-config.php (database credentials for local environment)
- dev-config.php (database credentials for local environment)
- staging-config.php (database credentials for local environment)
- production-config.php (database credentials for local environment)
Important: create a symlink to the WordPress core files for each site (this is where the magic happens)
$ cd sample.local
$ ln -s /absolute/path/to/wordpress/directory wordpress
Each site should have its own separate database. The specifics are listed in the various *-config.php files. Put these files in the .gitignore file for your project so that credentials are not stored in version control.
Remove the files not needed on each development environment. For example, your production server should only have production-config.php (local-config.php, staging-config.php, and dev-config.php should be deleted from the production server).
For *-config.php files on your dev, staging, and production servers, you can place these one directory above the root directory of your site. (This won't work for the local-config.php file, however.)
Check your httpd.conf file
<Directory "/root/of/local/development/server">
Options All
or
Options FollowSymLinks
</Directory>
<VirtualHost *>
DocumentRoot "/absolute/path/to/sample.local"
ServerName sample.local
</VirtualHost>
Modify your system host file to redirect to localhost when that server name is entered into a browser
127.0.0.1 sample.local
$ cd wordpress
$ git pull
$ git checkout 3.5-branch
Check that each site folder has the following:
require('./wordpress/wp-blog-header.php');
)Make sure that the ServerName of your virtual host and the directory for your site have the same name.
This repo is meant to show the structure of how to set this system up, not for version controlling each site. To put your site code under version control, you should:
.git
and .gitmodules
folder/file from the project directorygit init
within the folder for each siteThanks to David Winter, Duane Storey, and ashfame for leading the way