Title: Regarding wp-cli
Last modified: March 27, 2023

---

# Regarding wp-cli

 *  [raghavan2004](https://wordpress.org/support/users/raghavan2004/)
 * (@raghavan2004)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/regarding-wp-cli/)
 * I want to install wordpress using shell script, idea is like a one click installer,
   where I need to create automatically create database with username and password
   and also admin login and password. I found wp-cli as the best practice. 
   I used
   as per the direction as mentioned in the website [https://wp-cli.org/](https://wp-cli.org/)
   and till completing.
 * After that I am not sure how to proceed need guidance.
 * vijey,

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [karolinapan](https://wordpress.org/support/users/karolinapan/)
 * (@karolinapan)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/regarding-wp-cli/#post-16513447)
 * Hi,
 * Would suggest referring to this page for the available commands you can use via
   WP-CLI to develop your script:
 * [https://developer.wordpress.org/cli/commands/](https://developer.wordpress.org/cli/commands/)
 *  Thread Starter [raghavan2004](https://wordpress.org/support/users/raghavan2004/)
 * (@raghavan2004)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/regarding-wp-cli/#post-16513502)
 * Hi Karolinapan,
 * Thanks for the link.. Will check and getback. 
   I have a basic doubt. Will this
   work with bash script in ubuntu shellscript
 * Regards,
 * Vijey
 *  [Colin Stewart](https://wordpress.org/support/users/costdev/)
 * (@costdev)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/regarding-wp-cli/#post-16520986)
 * Hi [@raghavan2004](https://wordpress.org/support/users/raghavan2004/), WP-CLI
   can indeed be used inside a bash script. Here’s an example:
 *     ```wp-block-code
       #!/usr/bin/env bash
   
       # Output the WP-CLI version.
       wp --version
       ```
   
 *  Thread Starter [raghavan2004](https://wordpress.org/support/users/raghavan2004/)
 * (@raghavan2004)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/regarding-wp-cli/#post-16521328)
 * Hi thanks for the update, I write the code as below,
   I created a directory inside
   html folder and then created a file wp-install.sh. pasted the below code and 
   my wp-cli is working correctly and got the message successfull. I am trying to
   generate the username, password for the admin automatically and then the DB username
   and password is hardcoded. I am trying to create a one step installer, where 
   the entire wordpress is setup including the username password and the db and 
   also installed the plugin as mentioned below.
 *     ```wp-block-code
       <code>
   
       #!/bin/bash
   
       curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
   
       php wp-cli.phar --info
   
       chmod +x wp-cli.phar
   
       sudo mv wp-cli.phar /usr/local/bin/wp
   
       wp cli update
   
       # Variables
   
       # Download and extract WordPress
   
       # Get the parent directory of the current working directory
   
       # sub_dir=$(dirname "$PWD")
   
       # Get the name of the parent directory
   
       # parent_dir=$(basename "$sub_dir")
   
       wp_domain="$(dirname $PWD)"
   
       # read -rp "{WP_DOMAIN}";
   
       wp_title="My WordPress Site"
   
       db_name=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9+*$@#' | fold -w 10 | head -n 1)
   
       # DB_USER=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9+*$@#' | fold -w 10 | head -n 1)
   
       # DB_PASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9+*$@#' | fold -w 10 | head -n 1)
   
       db_user="sammy"
   
       db_pass="password"
   
       admin_email="your_admin_email@example.com"
   
       DB_HOST="localhost"
   
       # WP_DOMAIN="example.com"
   
       WP_TITLE="My WordPress Site"
   
       wp_admin_user=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9+*$@#' | fold -w 10 | head -n 1)
   
       wp_admin_pass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9+*$@#' | fold -w 10 | head -n 1)
   
       DB_COLLATE="utf8mb4_unicode_ci"
   
       # Define WordPress site credentials
   
       # Download WordPress core files
   
       wp core download --locale=en_US
   
       # Create wp-config.php file
   
       wp config create --dbname=$db_name --dbuser=$db_user --dbpass=$db_pass
   
       # Install WordPress
   
       wp core install --url=$wp_domain --title="$wp_title" --admin_user=$wp_admin_user --admin_password=$wp_admin_pass --admin_email=$admin_email
   
       # Update WordPress permalink structure
   
       wp rewrite structure '/%postname%/'
   
       # Install default WordPress theme and plugins
   
       wp theme install twentysixteen --activate
   
       wp plugin install akismet --activate
   
       wp plugin install jetpack --activate
   
       </code>
       ```
   
 * Attached the link for the screenshot
   [https://prnt.sc/foz0qwJiu1BF](https://prnt.sc/foz0qwJiu1BF)
    -  This reply was modified 3 years, 2 months ago by [raghavan2004](https://wordpress.org/support/users/raghavan2004/).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Regarding wp-cli’ is closed to new replies.

## Tags

 * [wp-cli](https://wordpress.org/support/topic-tag/wp-cli/)

 * In: [Installing WordPress](https://wordpress.org/support/forum/installation/)
 * 4 replies
 * 3 participants
 * Last reply from: [raghavan2004](https://wordpress.org/support/users/raghavan2004/)
 * Last activity: [3 years, 2 months ago](https://wordpress.org/support/topic/regarding-wp-cli/#post-16521328)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
