I've done some heavy updates to Primary Vagrant to utilize Ubuntu 14.04 as well as a few other goodies. If you don't want to or can't update for some reason you can find the old version in the Precise branch.
Primary Vagrant is intended for WordPress plugin, theme, and core development, as well as general PHP development, and can be used as a replacement for local development stacks such as MAMP, XAMPP, and others.
Although Varying Vagrant Vagrants by 10up is great (and I still use it for NGINX work), I wanted a few major changes. First, I wanted Apache instead of NGINX and, second, I wanted to use Puppet instead of Bash. Using VVV and Puppet as a base, this repository attempts to address their shortcomings for my own work with a Vagrant configuration that is ready to go for WordPress plugin or theme development.
The repository contains a basic Vagrant configuration that will configure the following goodies:
- Ubuntu 14.04 LTS
- Apache
- PHP 5.6
- MySQL
- Xdebug
- PHP_CodeSniffer
- WordPress Coding Standards for PHP_CodeSniffer
- PHPUnit
- Postfix
- wp-cli
- phpMyAdmin
- WordPress (Last, Stable, Core, and Dev)
- wp-debug plugin
- Search Replace DB
- webgrind
- oh-my-zsh
- MailCatcher
- Test data from WP Test
- Composer
- node.js
- Git
- Subversion
If you find any issues, please don't hesitate to submit a pull request.
Current development of the project is focusing on instituting multiple PHP versions using (at least for now) phpbrew. It needs a lot of work, so if you have a few minutes head on over to the phpbrew puppet module and dig in.
- pv - Default menu
- phpmyadmin.pv - phpMyAdmin
- replacedb.pv - Search Replace DB
- core.wordpress.pv - WordPress development (for core dev)
- legacy.wordpress.pv - Last version of WordPress (currently 4.2.x)
- stable.wordpress.pv - Latest WordPress stable (currently 4.3.x)
- trunk.wordpress.pv - WordPress trunk
- webgrind.pv - webgrind
- mailcatcher.pv - MailCatcher
Install Vagrant, VirtualBox, and the VirtualBox extensions for your environment.
Once Vagrant is installed you'll want three plugins to update your local hosts, and update the VirtualBox Guest additions in the Ubuntu install and handle various tasks like backing up your databases when you're done for the day.
vagrant plugin install vagrant-vbguest
vagrant plugin install vagrant-ghost
vagrant plugin install vagrant-triggers
-
Download or clone this repo onto your local machine:
$ git clone --recursive [email protected]:ChrisWiegman/Primary-Vagrant.git PV
-
In a command prompt, change into the new directory with
cd PV
-
Start the Vagrant environment with
vagrant up
- Be patient as the magic happens. This could take a while on the first run as your local machine downloads the required files.
- Watch as the script ends, as an administrator or
su
password may be required to properly modify the hosts file on your local machine.
The following websites come pre-configured in the system:
- Default menu
- WordPress (last major release) at http://legacy.wordpress.pv
- WordPress (latest stable release) at http://stable.wordpress.pv
- WordPress Trunk at http://trunk.wordpress.pv
- WordPress Core Development at http://core.wordpress.pv
- Search Replace DB https://replacedb.pv
*Note: WordPress Core dev is taken from git://develop.git.wordpress.org/. Only the src folder is mapped. You can manually set up a build site if desired.
First, create a file called mappings in the www directory. This will map any sites you create to the appropriate folder on PV.
Example Mapping:
config.vm.synced_folder "/Users/MyUser/Sites/Mysite/htdocs", "/var/www/mysite.pv", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774"]
*Note that if you're working on a WordPress plugin or theme I would recommend to simply map it to the three pre-installed WordPress sites. This will make it easy for you to test it on multiple versions of WordPress.
Example:
config.vm.synced_folder "/Users/MyUser/my-awesome-plugin", "/var/www/legacy.wordpress.pv/htdocs/content/plugins/my-awesome-plugin", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774"]
config.vm.synced_folder "/Users/MyUser/my-awesome-plugin", "/var/www/stable.wordpress.pv/htdocs/content/plugins/my-awesome-plugin", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774"]
config.vm.synced_folder "/Users/MyUser/my-awesome-plugin", "/var/www/trunk.wordpress.pv/htdocs/content/plugins/my-awesome-plugin", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774"]
Next Edit manifests/sites/``[your-site-domain].pp. This is where you define virtualhosts and databases. Copy what is below and ask me if you have any questions. Of course these aren't the only configuration options you have either. You can find a full list of Apache configuration options here and a full list of mysql configuration options here.
Example:
apache::vhost { 'mysite.pv':
docroot => '/var/www/mysite.pv',
directory => '/var/www/mysite.pv',
directory_allow_override => 'All',
ssl => true,
template => '/var/vagrant/conf/vhost.conf.erb',
}
mysql_database { 'mysite.pv':
ensure => 'present',
charset => 'utf8',
collate => 'utf8_general_ci',
require => Class['mysql::server'],
}
*Note: I've provided a top-level wildcard SSL certificate. No further SSL certificate should be needed.
Finally, and you can do this two ways... If you've created your site as a folder in the Primary Vagrant www folder just add a file callend pv-hosts to it that includes the domain name(s) (one per line) for your project. If your site is outside of the Primary Vagrant folder I would recommend creating www/my-sites/pv-hosts to hold the domain names. This will make sure you can access your sites by whatever domain names you need.
After the configuration above has been added, simply run vagrant halt
and then vagrant up
to trigger the changes and host file updates.
The default installation configuration is found in manifests/init.pp. While you could edit this if you like I would, instead, recommend adding any additional configuration to manifests/sites/custom.pp
To change from PHP 5.6 I recommend using a PGP package from https://launchpad.net/~ondrej/+archive/php5. You can do so by adding apt::ppa { 'ppa:ondrej/php5': }
to manifests/php.pp. Make sure to choose the correct repository for the PHP version you want to use.
Note: this file can also be used to change any php.ini value following the example included in the file.
You can access the database via ssh tunnel into the machine using the local.vagrant hostname, the username vagrant, the password vagrant for ssh, and the username root without a password for MySQL.
In addition to the root MySQL account the account username with the password password has also been created and has been granted all privileges.
Postfix is configured and set to use your host computer as a mail relay. To receive messages you can use the built in MailCatcher installation (this will prevent your real SMTP mail server and mailbox from getting too much abuse).
WP Test can be installed via the instructions at (https://github.com/manovotny/wptest). Test data is found in [Primary Vagrant Folder]/sites/wordpress/wptest on your host machine.
The latest stable node.js version is installed, if you want to pre-install packages just add them to manifests/nodejs.pp.
Example:
package { 'ungit':
provider => npm,
require => Class['nodejs']
}
Primary Vagrant comes pre-configured with two awesome tools for helping debug your code. The first is Xdebug and the second is PHP_Codesniffer (which comes complete with the WordPress coding standards already pre-configured). While configuration is dependant on the code editor you use here are some notes that might help you get started with them.
- Xdebug uses VAGRANT_DEBUG as its IDE key
- Many modern tools will let you access both of these tools easily with just a bit of configuration. For example, here's a great post on using remote debugging in PhpStorm.
###Keep your fork up to date with the PV upstream/master
repo
- Configure a remote that points to the upstream repository in Git:
git remote add upstream https://github.com/ChrisWiegman/Primary-Vagrant.git
See: https://help.github.com/articles/configuring-a-remote-for-a-fork
The following commands should bring you up to speed:
git checkout <localbranch>
git stash
-- save local changesgit pull https://github.com/ChrisWiegman/Primary-Vagrant.git upstream/master
git submodule update --recursive
git stash pop
-- saved local changes are available to be committed- Use
git merge tool
if you have any conflicts
See: https://www.atlassian.com/git/tutorials/syncing/git-pull
Now, you will be free to PR against Primary Vagrant.
Contributions are more than welcome. Please read our current guidelines for contributing to this repository. Many thanks in advance!
Some ideas I'm working on for future features:
- PHPBrew or a similar script that will allow you to change PHP versions on the fly.
- A site builder script that will let you avoid having to edit any text to add a new site.
- Anything else (applicable to the project) that the community would like to contribute.
This server configuration is designed for development use only. Please don't put it on a production server as some of these settings would cause serious security issues.