9

I am looking for a way to quickly and repeatedly set up testing / debugging environment for our plugin, most probably using Vagrant. Projects like VVV focus on a single-environment setup (or, a couple of environments like stable / trunk) while what I'm looking for is a script that would setup environments like:

  • wp39-php52.local
  • wp40-php52.local
  • wp41-php52.local
  • wp39-php53.local
  • wp40-php53.local
  • etc. (you get the idea)

Is there such thing? The closest I found is WordPress Vagrant Boxes which at least does PHP versions but maybe there is something more complete that also adds WordPress versions to the mix. Thanks.

4
1

On the WordPress side of things, Basic WordPress Vagrant Environment is ready to work with any WordPress version (with a little help). You would still need to find a way to configure the PHP but there is a hint in https://github.com/ideasonpurpose/basic-wordpress-box/blob/master/ansible/roles/php/tasks/php.yml.

To use it out of the box; Download or clone the project to wplatest-php55.dev/ and run vagrant up

Installing Vagrant Host Manager will automatically link the IP to your folder http://wplatest-php55.dev/

Generate multiple environments from WP versions via install-wp.sh

Check the archive for possible WordPress versions https://wordpress.org/download/release-archive/

# PWD (script directory)
# ├── common_folder
# ├── wp39-php55.dev
# │   └── site/common_folder
# ├── wp42-php55.dev
# │   └── site/common_folder
# └── wp431-php55.dev
#     └── site/common_folder

Here is a script that pulls the Vagrant environment master to the bash script's directory, clones a site for each version in the array, configures the install task to use that WP version and allows you to specify a file/folder to copy to all sites before you vagrant up.

Put this in a file install-wp.sh then run chmod +x install-wp.sh to make it executable. Find a folder where you want to create all these boxes and run ./install-wp.sh. It'll generate the structure above.

Since you want to test your plugin in all versions make a folder in the same directory as the script wp-content/plugins/your-plugin then run install-wp.sh wp-content. The file/folder is copied to each site's root which is why I suggest wp-content.

install-wp.sh

#!/bin/bash
#
# Author: Jesse Graupmann @jgraup - http://www.justgooddesign.com - 2015
#
# Create multiple WordPress sites based on version numbers in array.
#
# ( OPTIONAL )
#   Copy common file/folder to all sites - Pass as parameter $1
#
# Each site runs in a Vagrant Environment:
#   https://github.com/ideasonpurpose/basic-wordpress-vagrant
#
# Best if used with:
#   https://github.com/smdahlen/vagrant-hostmanager
#
# PWD (script directory)
# ├── common_folder
# ├── wp39-php55.dev
# │   └── site/common_folder
# ├── wp42-php55.dev
# │   └── site/common_folder
# └── wp431-php55.dev
#     └── site/common_folder

# WordPress Versions
versions=( 3.9 4.2 4.3.1 )

# Move to the current directory
base=$(pwd); cd $base

# Vagrant Environment
remote_master="https://github.com/ideasonpurpose/basic-wordpress-vagrant/archive/master.zip"
vagrant_master_zip=$base/basic-wordpress-vagrant.zip

# Download Latest Environment - overwrite file for latest
wget -v -O $vagrant_master_zip $remote_master

# Loop through version #s
for VERSION in "${versions[@]}" ; do

flatv="${VERSION//.}"
dirname=wp$flatv-php55.dev

# Clone Environment
echo -e "\nCloning to: $base/$dirname\n"
mkdir -p $base/$dirname
tar -zxvf $vagrant_master_zip -C $base/$dirname --strip-components=1

# WordPress Versions
# Archives:  https://wordpress.org/download/release-archive/
# Version:  https://wordpress.org/wordpress-{{ wp-version }}.tar.gz
# Latest: https://wordpress.org/latest.tar.gz

# Path to Ansible task
yml=$(cat $base/$dirname/ansible/roles/wordpress/tasks/install.yml)

### REPLACE THE ANSIBLE WP VERSION w/OUR VERSION
wp_url_latest="https:\/\/wordpress.org\/latest.tar.gz"
wp_url_version="https://wordpress.org/wordpress-$VERSION.tar.gz"

echo "${yml/$wp_url_latest/$wp_url_version}" > $base/$dirname/ansible/roles/wordpress/tasks/install.yml

# (OPTIONAL) Copy common file/folder to all sites!
# pass as argument to .sh
#
# Example Folder:
# Make a common wp-content folder, then run install with
#
#   ./install-wp.sh wp-content
#
# Example File:
# Make a text file, then run install with
#
#   ./install-wp.sh my_file.txt
#
common_dest=$base/$dirname/site/

# Copy Folder
if [ -d "$1" ]; then
  echo "Copying $1 --> $common"
  # Directory must exist
  if [ -d "$1" ]; then
    folder_name=$(basename $1)
    mkdir -p $common_dest/$folder_name;
  fi
  cp -r $1 $common_dest

# or File
elif [ -f "$1" ]; then
  echo "Copying $1 --> $common_dest"
  file_name=$(basename $1)
  cp $1 $common_dest/$file_name
fi

## Create doc for quick glance at version number
dest="$base/$dirname"
remotewpzip="https://wordpress.org/wordpress-$VERSION.tar.gz"
txt=$dest/download-wp-$VERSION.txt
touch $txt
printf "WordPress Version: $VERSION - https://wordpress.org/download/release-archive/\n\nDownload Zip: $remotewpzip\n" > $txt

done

# The rest is just for show

echo -e "\nDone!\n\nNow just run 'vagrant up' in any of these:\n"

for VERSION in "${versions[@]}" ; do
  flatv="${VERSION//.}"
  dirname=wp$flatv-php55.dev
  echo -e "\t"$base/$dirname "\thttp://"$dirname
done

echo -e "\nMore Vagrant env info @ https://github.com/ideasonpurpose/basic-wordpress-vagrant"
echo -e "Best if used with https://github.com/smdahlen/vagrant-hostmanager\n\nENJOY!"

Update:

It turns out the Basic WordPress Vagrant Environment isn't really setup to handle multiple php versions but the Basic Wordpress Box might be if you adjust the PHP task. I figured I'd leave a shell of a script that would have handled multiple php versions.

#!/bin/bash
############################################
#
# PWD (script directory)
# ├── wp39-php55.dev
# ├── wp42-php55.dev
# └── wp431-php55.dev
#
############################################

# WordPress Versions

versions=( 3.9 4.2 4.3.1 )

# PHP Versions

pversions=( 5.4 5.5 5.6 )

############################################

# Move to the current directory

base=$(pwd); cd $base

############################################

# PHP Loop
for PVERSION in "${pversions[@]}" ; do
    pflatv="${PVERSION//.}"

    echo -e "==> PHP: $PVERSION\n"

    # WordPress loop
    for VERSION in "${versions[@]}" ; do
        flatv="${VERSION//.}"

        ############################################
        dirname=wp$flatv-php$pflatv.dev 
        ############################################

        # Environment
        echo -e "\t"$base/$dirname "\thttp://"$dirname 

        mkdir -p $base/$dirname

        ############################################

        # WordPress Versions
        # Archives:  https://wordpress.org/download/release-archive/
        # Version:  https://wordpress.org/wordpress-{{ wp-version }}.tar.gz
        # Latest: https://wordpress.org/latest.tar.gz

        ############################################

        wp_url_latest="https:\/\/wordpress.org\/latest.tar.gz"
        wp_url_version="https://wordpress.org/wordpress-$VERSION.tar.gz"

        # Download WP

        echo -e "\tDownload WP: $wp_url_version"

        ############################################

        # PHP Packages at https://launchpad.net/~ondrej
        # You can get more information about the packages at https://deb.sury.org
        # For PHP 5.6 use: ppa:ondrej/php5-5.6
        # For PHP 5.5 use: ppa:ondrej/php5
        # For PHP 5.4 use: ppa:ondrej/php5-oldstable

        ############################################

        # Config PHP

        echo -e "\tConfigure PHP: $PVERSION\n"

    done # WordPress version
done # PHP version

exit 1
0

Have you looked at this?

puphpet

If appears to help you create config files. Looks like you can set up multiple vhosts and have it execute custom commands post-init. So you could have it set up all the folders, hosts and databases and then copy your desired versions over with associated wp-config files? A little bit of set up initially, but might work.

I use a shell script, myself. wp-install www.domain.com

Currently only works for one install but would not be impossible to configure it take some arguments or an additional 'config' file so set up multiple vhosts. As you mentioned Vagrant, I shall assume the above is closer to meeting your needs.

Good luck!

1
  • If I'm not mistaken PuPHPet cannot do PHP 5.2 and 5.3 so it will always be limited as a testing environment. Apr 10 '15 at 21:06
0

It all depends on what you're wanting to use and what type of OS you will be developing with...

For vagrant, here's automation for setting up with VVV: https://github.com/bradp/vv

And a couple of others built on vagrant:
https://github.com/vagrantpress/vagrantpress
https://github.com/tierra/wp-vagrant

However, I suggest trying out pantheon. It lets you do all of this for free and has integration with wp-cli, git, behat, etc. There are other hosted platforms that have these features such as https://www.appfog.com/ and even wpengine I believe.

It also depends though on how much you want set up from the start. If you're only looking for a quick way to set up wordpress there are tons of scripts on github like this or just use wp-cli.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.