|
| 1 | +# WordPress Local Development Environment # |
| 2 | + |
| 3 | +### Run multiple sites using one copy of WordPress core (without using multisite) ### |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +The wp-config.php file is configured to use different database settings for each site, by looking for a unique db-config.php file within the folder for each different site. |
| 8 | + |
| 9 | +## Requirements ## |
| 10 | + |
| 11 | +* Local Apache, PHP, and mySQL development environment |
| 12 | +* A filesystem that can create symbolic links |
| 13 | +* The virtual host ServerName and directory name for each site must be the same |
| 14 | +* Apache must be configured to follow symbolic links |
| 15 | + |
| 16 | +## Installation ## |
| 17 | + |
| 18 | +First, clone the repository into a folder on your local development server. Be sure to initialize submodules. |
| 19 | + |
| 20 | + $ git clone https://github.com/creativecoder/wordpress-local-dev.git wp-sites |
| 21 | + $ cd wp-sites |
| 22 | + $ git submodule update --init --recursive |
| 23 | + |
| 24 | +The project has the following structure |
| 25 | + |
| 26 | + Project root .. |
| 27 | + - wp-config.php file (used for all sites) |
| 28 | + - wordpress (git submodule of the official WordPress git repository ) |
| 29 | + - sample.local (sample site folder) |
| 30 | + - wp-content folder (for themes and plugins) |
| 31 | + - db-config.php (database name, user, password, and prefix unique to each site) |
| 32 | + - index.php (which looks in the /wordpress folder) |
| 33 | + |
| 34 | +**Important:** create a symlink to the WordPress core files for each site (this is where the magic happens) |
| 35 | + |
| 36 | + $ cd sample.local |
| 37 | + $ ln -s /absolute/path/to/wordpress/directory wordpress |
| 38 | + |
| 39 | +## Database Configuration ## |
| 40 | + |
| 41 | +Each site should have its own database. The specifics are listed in the db-config.php file within each unique site folder. |
| 42 | + |
| 43 | +## Apache Configuration ## |
| 44 | + |
| 45 | +### Be sure that Apache is configured to follow symbolic links ### |
| 46 | + |
| 47 | +Check your httpd.conf file |
| 48 | + |
| 49 | + <Directory "/root/of/local/development/server"> |
| 50 | + Options All |
| 51 | + or |
| 52 | + Options FollowSymLinks |
| 53 | + </Directory> |
| 54 | + |
| 55 | +### Setup a Virtual host in Apache ### |
| 56 | + |
| 57 | + <VirtualHost *> |
| 58 | + DocumentRoot "/absolute/path/to/sample.local" |
| 59 | + ServerName sample.local |
| 60 | + </VirtualHost> |
| 61 | + |
| 62 | +Modify your system host file to redirect to localhost when that server name is entered into a browser |
| 63 | + |
| 64 | + 127.0.0.1 sample.local |
| 65 | + |
| 66 | +##### Be sure that your virtual host name and the directory for the site are the same, or this will not work ##### |
| 67 | + |
| 68 | +## Create additional sites ## |
| 69 | + |
| 70 | +* Make a copy of your first site |
| 71 | +* Set up a new database for the site |
| 72 | +* Modify the db-config.php file to connect your new database |
| 73 | +* Set up another virtual host |
| 74 | + |
| 75 | +## Tips ## |
| 76 | + |
| 77 | +### Update all your local WordPress sites at once ### |
| 78 | + |
| 79 | + $ cd wordpress |
| 80 | + $ git pull |
| 81 | + |
| 82 | +### Revert to a previous WordPress version |
| 83 | + |
| 84 | + $ git checkout 3.4-branch |
| 85 | + |
| 86 | +## Troubleshooting ## |
| 87 | + |
| 88 | +Check that each site folder has the following: |
| 89 | + |
| 90 | +* index.php (which reads `require('./wordpress/wp-blog-header.php');`) |
| 91 | +* db-config.php with correct database information |
| 92 | +* wp-content folder |
| 93 | +* symbolic link to wordpress directory |
| 94 | + |
| 95 | +**Make sure that the ServerName of your virtual host and the directory for your site have the same name.** |
| 96 | + |
| 97 | +Thanks to [David Winter](http://davidwinter.me/articles/2012/04/09/install-and-manage-wordpress-with-git/) and [Duane Storey](http://www.duanestorey.com/uncategorized/one-wordpress-install-multiple-sites/) for leading the way |
0 commit comments