We used to install new wordpress website through “Softaculous Auto installer” or “MOJO” Tool on shared webhosts like HostGator or Bluehost. All we need to do is enter website url and few more details then we have brand new wordpress website ready. We loved it because, it takes less than 2 minutes to create a new wordpress website.

As lot of people move to Cloud hosting servers like Digital Ocean, creating new wordpress websites becomes little bit boring task. Lets say if you need to create 5 new wordpress websites in 5 different servers, either you need download wordpress source code and upload it to all 5 servers or use wget to fetch wordpress source code on each servers. Unarchive it and create configuration files and directories then complete the installation by visiting “your-website.com/wp-admin/install.php”. This really takes lot of our time and we don’t want to waste our time, doing same stuff again and again.

Lets Automate WordPress Installation

Well, We can automate this repeated process of downloading, unzipping files and creating configuration files and setting up folder permissions. You can install new wordpress simply by running this shell script install_wp.sh

This shell script downloads latest wordpress source from wordpress.org and extracts it to your directory and creates uploads directory inside wp-content and sets proper permission to it. And YES It updates wordpress security salt and deletes readme.html as basic security measures.

Why delete readme.html?

Well, You don’t want some random hacker to see your wordpress version and use exploits against your website.

How to use install_wp.sh?:

  1. First Create database using phpmyadmin or mysql commandline and keep the database name, user and passwords ready.
  2. Copy install_wp.sh script and copy it to your your webroot (ex: /var/www/your-website)


#!/bin/bash -e
echo "============================================"
echo "WordPress Install Script"
echo "============================================"
echo "Database Name: "
read -e dbname
echo "Table prefix: "
read -e tableprefix
echo "Database User: "
read -e dbuser
echo "Database Password: "
read -s dbpass
echo "run install? (y/n)"
read -e run
if [ "$run" == n ] ; then
echo "============================================"
echo "A robot is now installing WordPress for you."
echo "============================================"
#download wordpress
curl -O https://wordpress.org/latest.tar.gz
#unzip wordpress
tar -zxvf latest.tar.gz
#change dir to wordpress
cd wordpress
#copy file to parent dir
cp -rf . ..
#move back to parent dir
cd ..
#remove files from wordpress folder
rm -R wordpress
#create wp config
mv wp-config-sample.php wp-config.php
#set database details with perl find and replace
perl -pi -e "s/database_name_here/$dbname/g" wp-config.php
perl -pi -e "s/'wp_'/'$tableprefix'/g" wp-config.php
perl -pi -e "s/username_here/$dbuser/g" wp-config.php
perl -pi -e "s/password_here/$dbpass/g" wp-config.php

#set WP salts
perl -i -pe'
    @chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
    push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
    sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
  s/put your unique phrase here/salt()/ge
' wp-config.php

#create uploads folder and set permissions
mkdir wp-content/uploads
chmod 775 wp-content/uploads
echo "Cleaning..."
#remove zip file
rm latest.tar.gz
# remove readme file
rm readme.html
#remove bash script
rm install_wp.sh
echo "========================="
echo "Installation is complete."
echo "========================="

Fork this script on github

3. Make the script executable by running chmod +x install_wp.sh
4. Run the script by ./install_wp.sh
5. Enter Database Name
6. Enter Table prefix
7. Enter Database User
8. Enter Database Password
9. Type 'y' to continue to installation
10. Complete the installation by continuing to your-website.com/wp-admin/install.php


Thats it!! Happy coding!!