Batch installing Magento 1.4 through 1.9 + custom git module

Installing all Magento versions to test your custom module

When testing a Magento module, it's of course necessary to test the module on several Magento versions, ensuring backward compatibility.
Many times you will find smaller changes in some code sections in each Magento release, creating the need to adapt your code for each version, often using version_compare conditional statements.

Manually installing Magento is a lot of work, especially when doing it a couple of times a day. Luckily n98-magerun solves most of these issues by letting you install Magento + sample data through the command line.

I have previously described how to add your own local repository of Magento versions to N98 Magerun, this can be a real time saver when using a slow internet connection (especially handy when travelling and working for example). I would recommend checking out that post first in case you haven't yet!

 

Doing it manually

I personally don't work with Modman, but prefer to add the extension GIT repo directly to the Magento root directory. In order to work this way, using the manual method, you'd first have to install Magento using N98 Magerun, then add your git repo through the command line or using your IDE (I use PHPStorm). Of course one install is no problem, but doing this for 5 different Magento versions, and for multiple extensions a day, surely adds up to your RSI.

 

The better alternative - Using a batch installer script

I'm a programmer, so I don't like repetitive work :) To make the above process a lot less painful, I wrote a script to automatically install Magento 1.4 through 1.9 and add your extension Git repo on the fly. To use the script, it is necessary that n98-magerun.phar is added to your ~/bin/ directory and that Git is installed with SSH keys set up properly.

You can find the script below. Change the details between the '#user data' comments to suit your needs:

#!/bin/bash
#user data 
DBUSER=yourusername                                     #add your mysql user name here
DBPASSW=yourpassword                                    #add your mysql password here
URL='http://test.dev/'                                  #your local www-data URL
GITBASEURL='git@gitlab.com:magento-extensions/'         #the 'root' url of your git provider / project group
#end user data
INST=$1
ssh-add;
echo 'magento batch install...';
n98-magerun.phar install --dbHost="localhost" --dbUser="${DBUSER}" --dbPass="${DBPASSW}" --dbName="${INST}14" --installSampleData=yes --useDefaultConfigParams=yes --magentoVersionByName="magento-local-1.4.2.0" --installationFolder="./${INST}14" --baseUrl="${URL}${INST}14/";
n98-magerun.phar install --dbHost="localhost" --dbUser="${DBUSER}" --dbPass="${DBPASSW}" --dbName="${INST}15" --installSampleData=yes --useDefaultConfigParams=yes --magentoVersionByName="magento-local-1.5.1.0" --installationFolder="./${INST}15" --baseUrl="${URL}${INST}15/";
n98-magerun.phar install --dbHost="localhost" --dbUser="${DBUSER}" --dbPass="${DBPASSW}" --dbName="${INST}16" --installSampleData=yes --useDefaultConfigParams=yes --magentoVersionByName="magento-local-1.6.2.0" --installationFolder="./${INST}16" --baseUrl="${URL}${INST}16/";
n98-magerun.phar install --dbHost="localhost" --dbUser="${DBUSER}" --dbPass="${DBPASSW}" --dbName="${INST}17" --installSampleData=yes --useDefaultConfigParams=yes --magentoVersionByName="magento-local-1.7.0.2" --installationFolder="./${INST}17" --baseUrl="${URL}${INST}17/";
n98-magerun.phar install --dbHost="localhost" --dbUser="${DBUSER}" --dbPass="${DBPASSW}" --dbName="${INST}18" --installSampleData=yes --useDefaultConfigParams=yes --magentoVersionByName="magento-local-1.8.1.0" --installationFolder="./${INST}18" --baseUrl="${URL}${INST}18/";
n98-magerun.phar install --dbHost="localhost" --dbUser="${DBUSER}" --dbPass="${DBPASSW}" --dbName="${INST}19" --installSampleData=yes --useDefaultConfigParams=yes --magentoVersionByName="magento-local-1.9.1.0" --installationFolder="./${INST}19" --baseUrl="${URL}${INST}19/";
echo 'magento batch install done.';
if [ -z ${2+x} ]; then echo "no git repo specified, done.";exit 0; 
else 
        echo "adding ${2} to magento 1.4...";
        cd ./${INST}14/
        git init
        git remote add origin ${GITBASEURL}${2}
        git fetch --progress --prune origin
        git checkout -b master origin/master
        echo "adding ${2} to magento 1.5...";
        cd ../${INST}15/
        git init
        git remote add origin ${GITBASEURL}${2}
        git fetch --progress --prune origin
        git checkout -b master origin/master
        echo "adding ${2} to magento 1.6...";
        cd ../${INST}16/
        git init
        git remote add origin ${GITBASEURL}${2}
        git fetch --progress --prune origin
        git checkout -b master origin/master
        echo "adding ${2} to magento 1.7...";
        cd ../${INST}17/
        git init
        git remote add origin ${GITBASEURL}${2}
        git fetch --progress --prune origin
        git checkout -b master origin/master
        echo "adding ${2} to magento 1.8...";
        cd ../${INST}18/
        git init
        git remote add origin ${GITBASEURL}${2}
        git fetch --progress --prune origin
        git checkout -b master origin/master
        echo "adding ${2} to magento 1.9...";
        cd ../${INST}19/
        git init
        git remote add origin ${GITBASEURL}${2}
        git fetch --progress --prune origin
        git checkout -b master origin/master
        cd ../
fi
echo 'running second re-index round...';
pwd
echo "reindexing magento 1.4...";
cd ./${INST}14/
n98-magerun.phar index:reindex:all
pwd
echo "reindexing magento 1.5...";
cd ../${INST}15/
n98-magerun.phar index:reindex:all
pwd
echo "reindexing magento 1.6...";
cd ../${INST}16/
n98-magerun.phar index:reindex:all
pwd
echo "reindexing magento 1.7...";
cd ../${INST}17/
n98-magerun.phar index:reindex:all
pwd
echo "reindexing magento 1.8...";
cd ../${INST}18/
n98-magerun.phar index:reindex:all
pwd
echo "reindexing magento 1.9...";
cd ../${INST}19/
n98-magerun.phar index:reindex:all
cd ../
echo 'done!';

 

Adding the default parameters

The script uses the following default data, which can be added in the file itself:

DBUSERyour MySQL username
DBPASSWyour MySQL password
URLThe 'base' url, your Magento versions will be available on URL/PREFIX14, URL/PREFIX15 ... etc.
GITBASEURLThe 'base'url of your git repository. The second parameter when calling the bash script will be added to the url specified here.

 

The magentoVersionByName="" parameters in the n98-magerun commands inside the bash script should be changed to the correct version names, corresponding to your N98 Magerun Magento repository. If you have set up a local repository using my previous tutorial, it should be fine as is.

 

Using the batch installer

Save the script in your bin folder, and make it executable using the chmod +x command. Let's say we call it magentoBatchInstall.sh, you can then call it as follows:

Navigate to your public html directory for example (/var/www) and use the following command:

magentoBatchInstall.sh myextension my-custom-extension.git
 
Using the above command, Magento will be installed on the following locations:

DirectoryUrlVersion
/var/www/myextension14/http://test.dev/myextension14/Magento 1.4
/var/www/myextension15/http://test.dev/myextension15/Magento 1.5
/var/www/myextension16/http://test.dev/myextension16/Magento 1.6
/var/www/myextension17/http://test.dev/myextension17/Magento 1.7
/var/www/myextension18/http://test.dev/myextension18/Magento 1.8
/var/www/myextension19/http://test.dev/myextension19/Magento 1.9

 
Each Magento install will have your custom git repo added.
In the example above, the git repo "git@gitlab.com/magento-extensions/my-custom-extension.git" would be added. When opening the project with for example PHPStorm, all the extension files will already be added to the project, and you can easily work with the files, and push changes, without first having to add the repo through the GUI or commandline.

 

Using this script and a local N98 Magerun repository, you will have just enough time to grab a coffee before all Magento versions are installed :)

It would be especially nice to have this integrated in N98 Magerun as a script, if I can find the time, I will create one, but for now this works perfectly.

 

For questions or suggestions, leave a comment below. Next time, my batch uninstaller script!

Leave a Reply