ideas icon indicating copy to clipboard operation
ideas copied to clipboard

The famous 5 second install

Open danielbachhuber opened this issue 8 years ago • 6 comments

Every time I need a quick test site, it requires:

wp core download
wp core config
wp db create
wp core install

It would be much faster to have wp install, which intelligently performed each step.

Related https://github.com/mattgrshaw/wp-installer

danielbachhuber avatar Jan 19 '17 13:01 danielbachhuber

That would be awesome. I've build an Alfred Workflow for that.

Horttcore avatar Jan 19 '17 13:01 Horttcore

I would prefer this. I am at this point using https://github.com/CodeVigilant/wp_testbed/blob/master/provisioning/webserver.yml ansible flow to get the setup up and running for my testbeds.

anantshri avatar Jan 19 '17 14:01 anantshri

Trivial to write a shell script for all the commands. I currently have a 70-line zshell script that turns an empty directory into a nearly completely configured install. I can also add another dozen lines from a second script to populate all the page and post text content, categories, tags.

I'd hate to see wp-cli begin encroaching on what shell scripts do, because there will inevitably be conflicts, and then I lose my cool tools. Erm, I mean, anyone who's doing all this scripting to automate wp-cli will be tripped up.

joeldcanfield avatar Nov 20 '22 19:11 joeldcanfield

it would be greatly appreciated if the wp-cli bundle could include this script. It streamlines the process of installing and downloading WordPress, making it much faster and easier.

The script automates the installation of WordPress in the current working directory by downloading WordPress core, prompting the user to enter necessary installation details, updating the wp-config.php file, creating the MySQL database and user, and finally installing WordPress. Additionally, the script generates default values for the user to accept or modify for the installation details. These details include the MySQL username and password, database host, database name, table prefix, site URL, site title, admin username and password, and admin email.

If there is any further room for improvement, we would be happy to work on enhancing the script. The primary goal is to simplify the process of WordPress downloading and installation, making it possible with a single command.

wp-install sh file

# Define the installation directory as the current working directory
INSTALL_DIR=$(pwd)
DIR_NAME=$(basename "$PWD")
DOMAIN_NAME=$(echo "$DIR_NAME" | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:]-')
DOMAIN_NAME="$DOMAIN_NAME.com"

# Download WordPress core
wp core download

# Prompt the user to enter necessary installation details
echo "WordPress installation:"
read -p "Enter your MySQL username (default: root): " DB_USER
DB_USER=${DB_USER:-root}
read -p "Enter your MySQL password: " DB_PASS
read -p "Enter your database host (default: localhost): " DB_HOST
DB_HOST=${DB_HOST:-localhost}
read -p "Enter your database name (default: ${DIR_NAME//-/_}): " DB_NAME
DB_NAME=${DB_NAME:-${DIR_NAME//-/_}}
read -p "Enter your table prefix (default: wp_): " TABLE_PREFIX
TABLE_PREFIX=${TABLE_PREFIX:-wp_}
read -p "Enter your site URL (default: http://localhost/$DIR_NAME): " SITE_URL
SITE_URL=${SITE_URL:-http://localhost/$DIR_NAME}
read -p "Enter your site title (default: $(echo "$DIR_NAME" | tr '-' ' ' | tr '_' ' ' | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1')): " SITE_TITLE
SITE_TITLE=${SITE_TITLE:-$(echo "$DIR_NAME" | tr '-' ' ' | tr '_' ' ' | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1')}
read -p "Enter the admin username (default: admin): " ADMIN_USER
ADMIN_USER=${ADMIN_USER:-admin}
read -p "Enter the admin password (default: 12345): " ADMIN_PASS
ADMIN_PASS=${ADMIN_PASS:-12345}

# Delete wp-config.php file if it exists
if [ ! -f "$INSTALL_DIR/wp-config.php" ]; then
  cp "$INSTALL_DIR/wp-config-sample.php" "$INSTALL_DIR/wp-config.php"

  # Update the configuration file with the user-entered details
  sed -i "s/database_name_here/$DB_NAME/g" "$INSTALL_DIR/wp-config.php"
  sed -i "s/username_here/$DB_USER/g" "$INSTALL_DIR/wp-config.php"
  sed -i "s/password_here/$DB_PASS/g" "$INSTALL_DIR/wp-config.php"
  sed -i "s/localhost/$DB_HOST/g" "$INSTALL_DIR/wp-config.php"
  sed -i "s/wp_/$TABLE_PREFIX/g" "$INSTALL_DIR/wp-config.php"
fi

# Create MySQL database and user
if [ -z "$DB_PASS" ]; then
  mysql -u "$DB_USER" -h "$DB_HOST" <<MYSQL_SCRIPT
  CREATE DATABASE IF NOT EXISTS \`$DB_NAME\`;
  GRANT ALL PRIVILEGES ON \`${DB_NAME}\`.* TO '$DB_USER'@'$DB_HOST';
  FLUSH PRIVILEGES;
MYSQL_SCRIPT
else
  mysql -u "$DB_USER" -p"$DB_PASS" -h "$DB_HOST" <<MYSQL_SCRIPT
  CREATE DATABASE IF NOT EXISTS \`$DB_NAME\`;
  GRANT ALL PRIVILEGES ON \`${DB_NAME}\`.* TO '$DB_USER'@'$DB_HOST' IDENTIFIED BY '$DB_PASS';
  FLUSH PRIVILEGES;
MYSQL_SCRIPT
fi

# Install WordPress
wp core install --url="$SITE_URL" --title="$SITE_TITLE" --admin_user="$ADMIN_USER" --admin_password="$ADMIN_PASS" --admin_email="admin@$DOMAIN_NAME" --skip-email --path="$INSTALL_DIR"

echo "WordPress installation completed!"

wp-install.bat (in same directory).

@echo OFF setlocal DISABLEDELAYEDEXPANSION SET BIN_TARGET=%~dp0/../wp-cli/wp-cli/bin/wp-install SET COMPOSER_RUNTIME_BIN_DIR=%~dp0 sh "%BIN_TARGET%" %*

owaisahmed5300 avatar Mar 16 '23 18:03 owaisahmed5300

So from a code editor, we just write a single command and that would download WordPress, Install WordPress, Create MySQL Tables, Create a WordPress admin user, and Set the Site title, and email address based on the prompt user has provided.

Maybe we can have included some commands to integrate jetpack or install WordPress as headless CMS with react integration and so on.

owaisahmed5300 avatar Mar 16 '23 18:03 owaisahmed5300

First, since wp cli already has all the tools, and can be scripted easily (as @owaisahmed5300 and I have already shown) it seems like unnecessary duplication of effort to create and maintain additional pieces to wp cli.

However, if a script is made part of wp cli, it's much better to include a non-interactive version using a config file. I hate automation that makes me participate, since that's not really automated, it's only mostly automated.

Also, a Windows batch file has, erm, limited value. As in, limited to Windows.

joeldcanfield avatar Mar 16 '23 18:03 joeldcanfield