Install WordPress using bash shell without visiting /wp-admin/install.php? Install WordPress using bash shell without visiting /wp-admin/install.php? wordpress wordpress

Install WordPress using bash shell without visiting /wp-admin/install.php?


Check out wp-cli, based on Drush for Drupal.

wp core install --url=url --title=site-title [--admin_name=username] --admin_email=email --admin_password=password

All commands:

wp core [download|config|install|install_network|version|update|update_db]wp db [create|drop|optimize|repair|connect|cli|query|export|import]wp eval-filewp evalwp export [validate_arguments]wp generate [posts|users]wp homewp option [add|update|delete|get]wp plugin [activate|deactivate|toggle|path|update|uninstall|delete|status|install]wp post-meta [get|delete|add|update]wp post [create|update|delete]wp theme [activate|path|delete|status|install|update]wp transient [get|set|delete|type]wp user-meta [get|delete|add|update]wp user [list|delete|create|update]


I was having the same problem as you are. I tried Victor's method and it didn't quite work.I made a few edits and it works now!You have to add php tags inside of the script to make the code work, otherwise it just echoes to the terminal.

My script directly calls the wp_install function of upgrade.php, bypassing install.php completely (no edits to other files required).

I made my script named script.sh, made it executable, dropped it in the wp-admin directory, and ran it from the terminal.

#!/usr/bin/php<?phpfunction get_args(){        $args = array();        for ($i=1; $i<count($_SERVER['argv']); $i++)        {                $arg = $_SERVER['argv'][$i];                if ($arg{0} == '-' && $arg{1} != '-')                {                        for ($j=1; $j < strlen($arg); $j++)                        {                                $key = $arg{$j};                                $value = $_SERVER['argv'][$i+1]{0} != '-' ? preg_replace(array('/^["\']/', '/["\']$/'), '', $_SERVER['argv'][++$i]) : true;                                $args[$key] = $value;                        }                }                else                        $args[] = $arg;        }        return $args;}// read commandline arguments$opt = get_args();define( 'WP_INSTALLING', true );/** Load WordPress Bootstrap */require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );/** Load WordPress Administration Upgrade API */require_once( dirname( __FILE__ ) . '/includes/upgrade.php' );/** Load wpdb */require_once(dirname(dirname(__FILE__)) . '/wp-includes/wp-db.php');$result = wp_install($opt[0], $opt[1], $opt[2], false, '', $opt[3]);?>

I called the file like this: # ./script.sh SiteName UserName email@address.com Password


Maybe you need to modify the Wordpress original installer a bit.

First, create a wrapper php CLI script, let's say its name is wrapper.sh:

#!/usr/bin/php -qCfunction get_args(){        $args = array();        for ($i=1; $i<count($_SERVER['argv']); $i++)        {                $arg = $_SERVER['argv'][$i];                if ($arg{0} == '-' && $arg{1} != '-')                {                        for ($j=1; $j < strlen($arg); $j++)                        {                                $key = $arg{$j};                                $value = $_SERVER['argv'][$i+1]{0} != '-' ? preg_replace(array('/^["\']/', '/["\']$/'), '', $_SERVER['argv'][++$i]) : true;                                $args[$key] = $value;                        }                }                else                        $args[] = $arg;        }        return $args;}// read commandline arguments$opt = get_args();require "install.php";

This will allow you to invoke the script from the command line, and pass arguments to it directly into the $opt numeric array.

You can then pass the needed vars in a strict order you define, for instance:

./wrapper.sh <admin_email> <admin_password> <weblog_title> <user_name>

In the install.php you need to change the definition of the before mentioned vars, as it follows:

global $opt;$admin_email = $opt[0];$admin_password = $opt[1];$weblog_title = $opt[2];$user_name = $opt[3];

Then let the install script do its job.

This is an untested method, and also very open to any modifications you need. It's mainly a guideline for using a wrapper php/cli script to define the needed variable w/out having to send them via a HTTP REQUEST / query string. Maybe it's rather a weird way to get things done, so please, feel free to give any constructive/destructive feedback :-)