Skip to content

Instantly share code, notes, and snippets.

@ahmad-mushtaq
Forked from petertwise/wp-cli-oneclick-install.sh
Last active April 3, 2020 18:00
Show Gist options
  • Save ahmad-mushtaq/09407eaee7ec254153121be6715c6f61 to your computer and use it in GitHub Desktop.
Save ahmad-mushtaq/09407eaee7ec254153121be6715c6f61 to your computer and use it in GitHub Desktop.
Setup Wordpress Automatically after creating a virtual server using VirtualMin

Setup Wordpress Automatically after creating a virtual server using VirtualMin

This is a bash script to create a Wordpress Site ready to be developed after creating a Virtual Server using VirtualMin

This is very helpful for me since most of websites we develop are using wordpress and there is so many repetetive tasks that we can automate and save a lot of time.

I am still not able to automate some stuff such as downloading WPML directly from the official website and generating a site key. If someonne can do it that would be great.

Resources

Have a look at this: https://www.virtualmin.com/documentation/developer/prepost

#!/bin/bash
# Install Wordpress using WP CLI
#Check if its a new server and template is 'Wordpress'
if [ "$VIRTUALSERVER_ACTION" = "CREATE_DOMAIN" ] && [ "$VIRTUALSERVER_TEMPLATE" = 158588449513541 ]; then
#Getting into home directory
cd "$VIRTUALSERVER_HOME/public_html"
url=$VIRTUALSERVER_DOM
title=$VIRTUALSERVER_OWNER
admin_user=$VIRTUALSERVER_USER_admin
admin_password=$VIRTUALSERVER_PASS
admin_email=$VIRTUALSERVER_EMAILTO
dbname=$VIRTUALSERVER_DB
dbuser=$VIRTUALSERVER_USER
dbpass=$VIRTUALSERVER_PASS
dbprefix=$VIRTUALSERVER_DB
themeslug=$VIRTUALSERVER_DB
themename=$VIRTUALSERVER_DB
echo Ok. Starting installation of $title on $url.
# download, configure and install
wp --allow-root core download
wp --allow-root core config --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpass --dbprefix=$dbprefix
wp --allow-root core install --url=$url --title="$title" --admin_user=$admin_user --admin_password=$admin_password --admin_email=$admin_email
# delete default installed plugins and themes we don't need
wp --allow-root plugin delete hello-dolly akismet
wp --allow-root theme delete twentyfourteen twentyfifteen twentysixteen twentynineteen twentyseventeen
# install our favorite plugins - activate the ones usually used in development
wp --allow-root plugin install contact-form-7 duplicate-post maintenance really-simple-ssl ssh-sftp-updater-support svg-support updraftplus w3-total-cache worker wp-smushit advanced-custom-fields all-in-one-seo-pack contact-form-7-dynamic-text-extension custom-css-js folders mailgun simple-local-avatars wordfence wp-file-manager wps-hide-login
wp --allow-root plugin activate contact-form-7 duplicate-post really-simple-ssl ssh-sftp-updater-support svg-support updraftplus w3-total-cache worker wp-smushit advanced-custom-fields all-in-one-seo-pack contact-form-7-dynamic-text-extension custom-css-js folders mailgun simple-local-avatars wordfence wp-file-manager wps-hide-login
#Downloading WPML
mkdir "$VIRTUALSERVER_HOME/wpml"
cp /home/sohoby/public_html/downloads/wpml/* $VIRTUALSERVER_HOME/wpml
wp --allow-root plugin install $VIRTUALSERVER_HOME/wpml/*
wp theme activate twentytwenty
#--allow-root delete all the default sidebar widgets
wp --allow-root widget delete search-2 recent-posts-2 archives-2 categories-2 meta-2
# delete the example post and example page
wp --allow-root post delete 1 2 --force
# create pages
wp post create --post_type=page --post_title="Home" --post_status='publish'
wp--allow-root post create --post_type=page --post_title="About" --post_status='publish'
wp --allow-root post create --post_type=page --post_title="Services" --post_status='publish'
wp --allow-root post create --post_type=page --post_title="Contact" --post_status='publish'
# make those two pages the default for Home and Blog
wp --allow-root option update show_on_front "page"
wp --allow-root option update page_on_front "4"
# clear out "Just Another WordPress Blog" BS
wp --allow-root option delete blogdescription
# set the timezone
#wp --allow-root option update timezone_string "America/New_York"
# we're usually starting with a development site - hide it from search engines
wp --allow-root option update blog_public "on"
# update the permalink structure
wp --allow-root rewrite structure '/news/%postname%/' --hard
# make all comments disabled
wp --allow-root option update disable_comments_options --format=json '{"disabled_post_types":["post","page","attachment"],"remove_everywhere":true,"permanent":false,"extra_post_types":false,"db_version":6}'
# create the main menu and assign it to the primary menu slot
wp --allow-root menu create "Main Menu"
wp --allow-root menu location assign main-menu primary
wp --allow-root menu item add-post main-menu 4 --title="Home"
wp --allow-root menu item add-post main-menu 5 --title="About"
wp --allow-root menu item add-post main-menu 6 --title="Services"
wp --allow-root menu item add-post main-menu 7 --title="Contact"
#Activate SSL
wp --allow-root rsssl activate_ssl
chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER .s
chmod -R +x $VIRTUALSERVER_HOME
echo "Wordpress Installed"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment