Easy WordPress Installation Script using XAMPP/Cygwin
Here’s a script I wrote for myself to quickly create new WordPress installs using a XAMPP installation. This requires Cygwin to run and make sure to download the package for clear screen keyword as well. Everything will work if you have a default XAMPP installation, otherwise you’ll have to edit the directories throughout the script to ensure that everything is installed in the correct place.
To run the script just place both files in the htdocs folder then double click on the .bat file. This script will download and install the latest version of WordPress including setting up your hosts and vhosts files. In addition, it will also install a set of default plugins if you have subversion installed with Cygwin. If you’d rather have a clean install without any plugins simply delete the Install Default Plugins section of the script. If you’d like to have any other plugins installed automatically you can find the correct svn paths at http://svn.wp-plugins.org/.
This has been tested on a few computers running Windows 7 so let me know if anything doesn’t work on your end.
Here are the packages in Cygwin that are needed for this script to work:
- ncurses
- unzip
- wget
- subversion
File: create-new-wp.bat
cls c:\cygwin\bin\bash --login "C:\xampp\htdocs\create-new-wp.sh"
File: create-new-wp.sh
#!/bin/bash
#wp-install script
EXPECTED_ARGS=3
E_BADARGS=65
MYSQL="/cygdrive/c/xampp/mysql/bin/mysql.exe"
clear;
#------------------------------------------------------------------------------
# Script Prompts
#------------------------------------------------------------------------------
echo "#----------------------------------------------------------------
#
# WordPress Creation Script
# Automates the creation of a new wordpress installation in XAMPP
# Created By: Justin Myers
#
#----------------------------------------------------------------"
echo -e "\nInstall directory name:"
read installdir
echo -e "\nDatabase Name:"
read dbname
echo -e "\nDatabase User:"
read dbuser
echo -e "\nDatabase Password:"
read dbpass
echo -e "\nDomain (without http,www):"
read domain
clear;
echo "Directory: $installdir
Database: $dbname
User: $dbuser
Password: $dbpass
Domain: $domain
Create WordPress Installation with these details? (y/n)"
read confirm
if [ $confirm != "y" ];
then
exit
fi
#------------------------------------------------------------------------------
# Check to make sure we have the latest version of wordpress
#------------------------------------------------------------------------------
echo -e "\r\nChecking for the latest wordpress version..."
rm -r /cygdrive/c/xampp/htdocs/wp-latest/*
wget -O /cygdrive/c/xampp/htdocs/wp-latest/wordpress.zip "http://wordpress.org/latest.zip";
unzip -q /cygdrive/c/xampp/htdocs/wp-latest/wordpress.zip -d /cygdrive/c/xampp/htdocs/wp-latest/
rm /cygdrive/c/xampp/htdocs/wp-latest/wordpress.zip
cp -r /cygdrive/c/xampp/htdocs/wp-latest/wordpress/* /cygdrive/c/xampp/htdocs/wp-latest/
rm -r /cygdrive/c/xampp/htdocs/wp-latest/wordpress/
echo -e "Retreived the lastest version of WordPress"
echo -e "\r\nCreating MYSQL database and user..."
#------------------------------------------------------------------------------
# Create MySQL Database and User
#------------------------------------------------------------------------------
Q1="CREATE DATABASE IF NOT EXISTS $dbname;"
Q2="GRANT ALL ON *.* TO '$dbuser'@'localhost' IDENTIFIED BY '$dbpass';"
Q3="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}"
$MYSQL -uroot -e "$SQL"
echo -e "\r\nCreating install directory..."
#------------------------------------------------------------------------------
# Create WordPress Directory
#------------------------------------------------------------------------------
mkdir /cygdrive/c/xampp/htdocs/$installdir
#------------------------------------------------------------------------------
# Copy WordPress Files
#------------------------------------------------------------------------------
echo -e "\r\nCopying wordpress files..."
cp -R /cygdrive/c/xampp/htdocs/wp-latest/* /cygdrive/c/xampp/htdocs/$installdir
#------------------------------------------------------------------------------
# Install Default Plugins
#------------------------------------------------------------------------------
cd /cygdrive/c/xampp/htdocs/$installdir/wp-content/plugins
#All-In-One SEO Pack
PLUGIN_NAME="all-in-one-seo-pack"
mkdir $PLUGIN_NAME
cd $PLUGIN_NAME
svn checkout http://svn.wp-plugins.org/$PLUGIN_NAME/trunk .
rm -r .svn
cd ..
#Contact Form 7
PLUGIN_NAME="contact-form-7"
mkdir $PLUGIN_NAME
cd $PLUGIN_NAME
svn checkout http://svn.wp-plugins.org/$PLUGIN_NAME/trunk .
rm -r .svn
cd ..
#Dean's fCKEditor for WordPress
PLUGIN_NAME="fckeditor-for-wordpress-plugin"
mkdir $PLUGIN_NAME
cd $PLUGIN_NAME
svn checkout http://svn.wp-plugins.org/$PLUGIN_NAME/trunk .
rm -r .svn
cd ..
#Fluency Admin
PLUGIN_NAME="fluency-admin"
mkdir $PLUGIN_NAME
cd $PLUGIN_NAME
svn checkout http://svn.wp-plugins.org/$PLUGIN_NAME/trunk .
rm -r .svn
cd ..
#Fluency Admin Addons
#Google XML Sitemaps
PLUGIN_NAME="google-sitemap-generator"
mkdir $PLUGIN_NAME
cd $PLUGIN_NAME
svn checkout http://svn.wp-plugins.org/$PLUGIN_NAME/trunk .
rm -r .svn
cd ..
#WP Super Cache
PLUGIN_NAME="wp-super-cache"
mkdir $PLUGIN_NAME
cd $PLUGIN_NAME
svn checkout http://svn.wp-plugins.org/$PLUGIN_NAME/trunk .
rm -r .svn
cd ..
#VideoJS
PLUGIN_NAME="videojs-html5-video-player-for-wordpress"
mkdir $PLUGIN_NAME
cd $PLUGIN_NAME
svn checkout http://svn.wp-plugins.org/$PLUGIN_NAME/trunk .
rm -r .svn
cd ..
#------------------------------------------------------------------------------
# Updating Hosts File
#------------------------------------------------------------------------------
echo -e "\r\nUpdating Hosts file..."
HOSTS="\r\n127.0.0.1 $domain\r\n127.0.0.1 www.$domain"
echo -e -n $HOSTS >> /cygdrive/c/Windows/System32/drivers/etc/hosts
#------------------------------------------------------------------------------
# Updating VHosts
#------------------------------------------------------------------------------
echo -e "\r\nUpdating Apache vhosts file..."
VHOSTS="\r\n\r\n<virtualhost :80="">\r\n ServerName $domain\r\n ServerAlias www.$domain\r\n\r\n DocumentRoot \"C:/xampp/htdocs/$installdir\"\r\n\r\n <directory c:="" htdocs="" xampp="">\r\n AllowOverride All\r\n Allow from All\r\n </directory>\r\n </virtualhost>"
echo -e -n $VHOSTS >> /cygdrive/c/xampp/apache/conf/extra/httpd-vhosts.conf
#------------------------------------------------------------------------------
# Restart Apache
#------------------------------------------------------------------------------
RESTART="/cygdrive/c/xampp/xampp_cli.exe restart apache"
$RESTART
read -p "
Completed: Press enter key to quit..."

Congruent Style
Diggity Digital
Whole Kids Adventure