How to Install WordPress using Bash Script & WP CLI

Steps to Install WordPress using Bash Script & WP CLI

Most of us know steps to install wordpress through browser which is easy but what if we don’t have Xserver or only shell access. When we want to install wordpres using Bash Script & WP CLI on linux server as backend service automatically by providing some details through command so below steps will help you to install through script.

What is WordPress ?

WordPress is a free and open source blogging tool and a content management system (CMS) based on PHP and MySQL.[5] Features include a plugin architecture and a template system. Under most circumstances, installing WordPress is a very simple process and takes less than five minutes to complete. Many web hosts now offer tools to automatically install WordPress for you. However, if you wish to install WordPress yourself, the following guide will help.

Previously we explained how to install WordPress on linux. Also you can install WordPress on linux in an easier way, using the script provided in this article. This script will download and configure the latest WordPress version. So you just need to do is to create a file on your WordPress VPS with the content shown below, make the file executable, execute it and enter a few parameters.

First you need to install wp-cli latest from the official wp-cli Website. or you can proceed with the following.

Download the wp-cli.phar using curl by running following command.

root@linuxtweaks ~]#curl -O

Check if wp-cli.phar is working.

root@linuxtweaks ~]php wp-cli.phar --info

To be able to type just wp, instead of php wp-cli.phar, you need to make the file executable and move it to somewhere in your PATH. e.g.

root@linuxtweaks ~]#chmod +x wp-cli.phar
root@linuxtwaeks ~]#mv wp-cli.phar /usr/local/bin/wp

Now, trying running if it is working.

root@linuxtweaks ~]#wp --info

Bash Script to install WordPress.

Create a file named with the following command.

root@linuxtweaks ~]vi

And paste the following code in the file.

echo "============================================"
echo "          WordPress Install Script          "
echo "============================================"
echo "=============Database details==============="
echo -n "Database Host (e.g localhost) : "
read dbhost
echo -n "Database Name : "
read dbname
echo -n "Database User : "
read dbuser
echo -n "Database Password : "
read dbpass
echo "=============Admin details=================="
echo -n "Site url (e.g : "
read siteurl
echo -n "Site Name (e.g linuxtweaks) : "
read sitename
echo -n "Email Address (e.g [email protected]) : "
read wpemail
echo -n "Admin User Name : "
read wpuser
echo -n "Admin User Password : "
read wppass
echo -n "run install? (y/n) : "
read run
if [ "$run" == n ] ; then
echo "============================================"
echo "A robot is now installing WordPress for you."
echo "============================================"
echo "Downloading wordpress latest version..."
curl -O
echo "Extracting tarball wordpress..."
tar -zxvf latest.tar.gz
#copy file to parent dir
cp -rf wordpress/* .
#remove files from wordpress folder
rm -R wordpress
#create wp config
echo "Creating database configuration file..."
cp wp-config-sample.php wp-config.php
#set database details with perl find and replace
perl -pi -e "s/localhost/$dbhost/g" wp-config.php
perl -pi -e "s/database_name_here/$dbname/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
#create uploads folder and set permissions
mkdir wp-content/uploads
chmod 777 wp-content/uploads
echo "Installing wordpress..."
wp core install --url="$siteurl" --title="$sitename" --admin_user="$wpuser" --admin_password="$wppass" --admin_email="$wpemail"
#remove zip file
#rm latest.tar.gz
#remove bash script
echo "========================="
echo "Installation is complete."
echo "========================="
echo ""

Directly download this script by clicking Here.

View more posts in this category !!!

Magento Installation Bash Script.

Balvinder Singh

Hello, I am Balvinder Singh - DevOps Engineer with 2.5+ year of working experience with different server environments. Tag Line:-Linux | AWS| WHM |Monitoring | Virtualization | Optimization | Performance | Security | Release & Deployment. I love helping companies / clients to deploy their code / applicateions to well managed, optimized, secure server and can go extra mile to satisfy.

You may also like...

2 Responses

  1. Luk says:

    Nice script. Do you have any idea how to replace Salt Keys automaticly from ?
    It is possible to do with this bash script?

Leave a Reply

Your email address will not be published. Required fields are marked *