Skip to content

A Vagrant configuration with Ubuntu 14.04, Apache, MySQL, PHP 5.5 and more

Notifications You must be signed in to change notification settings

heliopsis/Primary-Vagrant

 
 

Repository files navigation

Primary Vagrant

Note

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.

About

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:

Contributors

Want to help?

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.

Getting Started

Default domains

  • 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 the software

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

Launch your VM

  1. Download or clone this repo onto your local machine:

    $ git clone --recursive [email protected]:ChrisWiegman/Primary-Vagrant.git PV

  2. In a command prompt, change into the new directory with cd PV

  3. 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.

Preconfigured Sites

The following websites come pre-configured in the system:

*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.

Configure Additional Sites

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.

Changing configuration options

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

Change PHP Versions

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.

Database Access

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 Configuration

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 Data

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.

node.js

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']
}

Debugging Code

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.

###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 changes
  • git 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

Contributions are more than welcome. Please read our current guidelines for contributing to this repository. Many thanks in advance!

Future Development

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.

Note

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.

About

A Vagrant configuration with Ubuntu 14.04, Apache, MySQL, PHP 5.5 and more

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 47.6%
  • Puppet 23.7%
  • Shell 13.8%
  • HTML 13.0%
  • ApacheConf 1.9%