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 https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
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 wp-install.sh with the following command.
root@linuxtweaks ~]vi wp-install.sh
And paste the following code in the wp-install.sh file.
#!/bin/bash clear echo "============================================" echo " WordPress Install Script " echo "============================================" 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 echo "=============Admin details==================" echo -n "Site url (e.g https://www.linuxtweaks.in/) : " 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 exit else echo echo "============================================" echo "A robot is now installing WordPress for you." echo "============================================" echo "Downloading wordpress latest version..." curl -O https://wordpress.org/latest.tar.gz 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 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 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 #rm wp-install.sh echo "=========================" echo "Installation is complete." echo "=========================" echo echo "Thankyou...linuxtweaks.in" fi
Directly download this script by clicking Here.
View more posts in this category !!!
Magento Installation Bash Script.
Nice script. Do you have any idea how to replace Salt Keys automaticly from https://api.wordpress.org/secret-key/1.1/salt/ ?
It is possible to do with this bash script?
Yes offcourse !