I wrote this little BASH script that creates a folder,unzips WordPress and creates a database for a site.
The final step is actually installing WordPress, which usually involves pointing your browser to install.php and filling out a form in the GUI.
I want to do this from the BASH shell, but can’t figure out how to invoke wp_install() and pass it the parameters it needs:
-admin_email
-admin_password
-weblog_title
-user_name
(line 85 in install.php)
Here’s a similar question, but in python
#!/bin/bash
#ask for the site name
echo "Site Name:"
read name
# make site directory under splogs
mkdir /var/www/splogs/$name
dirname="/var/www/splogs/$name"
#import wordpress from dropbox
cp -r ~/Dropbox/Web/Resources/Wordpress/Core $dirname
cd $dirname
#unwrap the double wrap
mv Core/* ./
rm -r Core
mv wp-config-sample.php wp-config.php
sed -i 's/database_name_here/'$name'/g' ./wp-config.php
sed -i 's/username_here/root/g' ./wp-config.php
sed -i 's/password_here/mypassword/g' ./wp-config.php
cp -r ~/Dropbox/Web/Resources/Wordpress/Themes/responsive $dirname/wp-content/t$
cd $dirname
CMD="create database $name"
mysql -uroot -pmypass -e "$CMD"
How do I alter the script to automatically run the installer without the need to open a browser?
Check out wp-cli, based on Drush for Drupal.
All commands:
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.
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
: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: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 🙂
It’s incredible how little discussion there is on this topic. I think it’s awesome that WP-CLI was released and now acquired by Automattic, which should help to keep the project going long-term.
But relying on another dependency is not ideal, esp. when dealing with automated deployment…
This is what we came up with for SlickStack…
First, we save a MySQL “test” query and grep for e.g. wp_options as variables:
…doing it this way helps to avoid false positives like when queries/grep might spit out warnings etc.
And the if statement that will populate the WordPress database conditionally:
The
-q
keeps it quiet to avoid parsing conflicts and the-r
tells it to execute the following code. I’m pretty sure we don’t really need the-C
flag here, but I added it anyways just in case.Note: I had to play around with the if statement a few times, because the
wp_install
array is sensitive and I found that wrapping the password variable in single quotes resulted in a broken MD5 hash code, so if any issues try adding/removing quotation marks…