Bah Script Install/Upgrade WordPress

Valic —  October 4, 2011 — 1 Comment

I always had problems when i upgraded my wordpress.
So I made ​one script that automatically does this for me and i’ll share that with you.
With this script you can install or upgrade your wordpress install.


# Homepage:
# Email:
# Bash script to download and install or upgrade wordpress to specified directory.
install_wp ()
cd ~</pre>
mkdir wordpress
cd wordpress
wget –no-check-certificate;
echo "Where would you like your new WordPress install to be located? Please Type the location(Eg:/var/www/) and press [ENTER]: "
read wordpress_dir
echo "Installing WordPress to $wordpress_dir";
if [ ! -d "$wordpress_dir" ]; then
mkdir $wordpress_dir
tar -zxvf latest.tar.gz -C $wordpress_dir

clean_up ()
cd ~/wordpress
rm latest.tar.gz
cd ~
rmdir wordpress
cd $wordpress_dir/wordpress
mv *.* $wordpress_dir
mv wp-admin $wordpress_dir
mv wp-content $wordpress_dir
mv wp-includes $wordpress_dir/
rmdir $wordpress_dir/wordpress
cd $wordpress_dir/wp-content
mkdir uploads
chmod 777 uploads -R
cd $wordpress_dir
touch $wordpress_dir/.htaccess
chmod -v 666 .htaccess
echo "Wordpress is now Installed to" . $wordpress_dir . "Enjoy!"

update_wp ()
day=`date +%Y_%m_%d`
cd ~
mkdir wordpress_tmp
cd wordpress_tmp
wget –no-check-certificate;
echo "In what directory does WordPress already exist, that you would like updated? Please Type the location(Eg:/var/www/) and press [ENTER]: "
read update_dir
tar -zxvf latest.tar.gz -C $update_dir
cd ~/wordpress_tmp
rm latest.tar.gz
cd ~
rmdir wordpress_tmp

cd $update_dir
cp $update_dir/ $update_dir/../wordpress_backup_$day -R
cp $update_dir/../wordpress_backup_$day/wp-config.php $update_dir

# Go to backup directory and remove the new install of WP
cd $update_dir/../wordpress_backup_$day
rm wordpress -rf

# back to the update directory
cd $update_dir/wordpress

#remove wp-admin and wp-includes
cd $update_dir
rm wp-admin -rf
rm wp-includes -rf

cd $update_dir/wordpress
mv wp-admin $update_dir
mv wp-includes $update_dir
#remove the extra updated directoroies
rm $update_dir/wordpress/ -rf

echo "Upgrade complete! Backup can be found in $update_dir/../$update_dir_backup_$day"
if ["$(id -u)" = "0"]; then {
echo "You are root we will continue" 2>&1

read -p "If the location you want to install wordpress to requires Root access, Please press ‘N’ and run this script again as root, or ‘Y’ to run the script without root (y/n)? "
[ "$REPLY" == "n" ] & exit ||
[ "$REPLY" == "y" ] &
echo "Do you wish to install WordPress [Yes] or update [No]? Type 1 or 2 and press [ENTER]"
select yn in "Yes" "No"; do
case $yn in
Yes ) install_wp && clean_up && break;;
No ) update_wp && break;;
exit 1;


You can download the script from here: Install or Upgrade wordpress bash script



Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

One response to Bah Script Install/Upgrade WordPress

  1. Good tutorial.
    Thank you!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.