Went to my first Wordcamp in NYC this weekend! Funny enough, one of the first people I met upon entering the conference was @karmatosed, whose Buddypress Theme Development book I had just downloaded for offline reading on my Safari Books Online mobile app. (I had *literally* been reading it on the subway just a few minutes before I met her. :D) So many accomplished WordPress developers at this conference.

Anyway, this post is about how I learned to set up multiple local instances of WordPress on my macbook air WITHOUT using MAMP Pro (go Vagrant!), thanks much to @DrewAPicture, a web engineer at 10Up and contributor to WordPress and to VVV. He helped me figure out “what’s next?” after the  setup instructions in https://github.com/Varying-Vagrant-Vagrants/VVV left me hanging.

I thought the instructions in the initial README were great for getting my first http://local.wordpress.dev site set up. But what if I wanted to set up another instance? Below are my notes.

0. Create a new folder in vagrant-local/www. For example: vagrant-local/www/name-of-your-project/

1. In your VVV/database folder, change the file name of init-custom-sample.sql to init-custom.sql.

2. Inside vagrant-local/database/init-custom.sql, create the databases. For example:

GRANT ALL PRIVILEGES ON `name-of-project`.* TO 'wp'@'localhost' IDENTIFIED BY 'wp';CREATE DATABASE IF NOT EXISTS `name-of-project2`;
GRANT ALL PRIVILEGES ON `name-or-project2`.* TO 'wp'@'localhost' IDENTIFIED BY 'wp';

4. In vagrant-local/config/nginx-config/sites/, create servers.conf. This is where you’ll configure your nginx. If you have multiple dev instances, you’ll have multiple server{ } blocks. For example:

server {
listen       80;
listen       443 ssl;
server_name  name-of-project.dev;
root         /srv/www/name-of-project;
include /etc/nginx/nginx-wp-common.conf;
server {
listen       80;
listen       443 ssl;
server_name  name-of-project2.dev;
root         /srv/www/name-of-project2;
include /etc/nginx/nginx-wp-common.conf;

5. In your terminal, make sure the vagrant IPs are added to the bottom of your ~/etc/hosts file.

$ sudo -s
$ cd ~/
$ cd ../../
$ cd etc
$ vim hosts

Make sure: name-of-project.dev name-of-project2.dev

… is added to the bottom of the hosts file.

Type exit to get out.

6. Run vagrant provision in your terminal so that the databases changes are registered.

7. Download wordpress in vagrant using the command line.

$ vagrant ssh
$ cd ../../
$ cd srv/www/name-of-project
$ wp core download

exit to get out of vagrant.

8. Navigate to http://name-of-project.dev in the browser to create a new wp-config.php file, and follow the steps.

Your database host should be localhost, and the user and password should be associated with what you input in step #2. In this example, the user and password are ‘wp’ and ‘wp.’

9. You should now be able to see your local wordpress installation at http://name-of-project.dev/!

10. In practice, it’s better not to use version control on the core WordPress docs. You can git init inside vagrant-local/www/name-of-your-project/wp-content/themes/your-own-wordpress-theme to use version control specifically on your theme.


blog comments powered by Disqus
  • Hi, I'm Linda! I enjoy going to tech meetups, learning web development, and blogging about the learning path. Follow me @LPnotes

Subscribe to The Coding Diaries