Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wordpress: Bash Install Script -- Downloads latest WP version, updates wp-config with user supplied DB name, username and password, creates and CHMOD's uploads dir, copies all the files into the root dir you run the script from, then deletes itself!
#!/bin/bash -e
clear
echo "============================================"
echo "WordPress Install Script"
echo "============================================"
echo "Database Name: "
read -e dbname
echo "Database User: "
read -e dbuser
echo "Database Password: "
read -s dbpass
echo "run install? (y/n)"
read -e run
if [ "$run" == n ] ; then
exit
else
echo "============================================"
echo "A robot is now installing WordPress for you."
echo "============================================"
#download wordpress
curl -O https://wordpress.org/latest.tar.gz
#unzip wordpress
tar -zxvf latest.tar.gz
#change dir to wordpress
cd wordpress
#copy file to parent dir
cp -rf . ..
#move back to parent dir
cd ..
#remove files from wordpress folder
rm -R wordpress
#create wp config
cp wp-config-sample.php wp-config.php
#set database details with perl find and replace
perl -pi -e "s/database_name_here/$dbname/g" wp-config.php
perl -pi -e "s/username_here/$dbuser/g" wp-config.php
perl -pi -e "s/password_here/$dbpass/g" wp-config.php
#set WP salts
perl -i -pe'
BEGIN {
@chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
}
s/put your unique phrase here/salt()/ge
' wp-config.php
#create uploads folder and set permissions
mkdir wp-content/uploads
chmod 775 wp-content/uploads
echo "Cleaning..."
#remove zip file
rm latest.tar.gz
#remove bash script
rm wp.sh
echo "========================="
echo "Installation is complete."
echo "========================="
fi
@bgallagh3r

This comment has been minimized.

Show comment
Hide comment
@bgallagh3r

bgallagh3r Mar 3, 2014

Add this to your ~/.bashrc
alias wpinstall="curl -L -o 'wp.sh' https://gist.githubusercontent.com/bgallagh3r/2853221/raw/f3e2f2fa3048bbeb6d35799af068965bc5fd9b26/wp.sh && bash wp.sh" then source ~/.bashrc Go into a dir you want to install WP in and just type wpinstall It's that easy!

Update:
I've updated the URL to the gist in this comment, WP changed the latest.tar.gz to use HTTPS (finally) as such trying to grab a copy from http::// broke the script

Update: July 8 2015
I've modified the script to add the salts automatically now thanks to @emirpprime's fork.
the new command should be alias wpinstall="curl -L -o 'wp.sh' https://gist.githubusercontent.com/bgallagh3r/2853221/raw/eb5070c1a4f06dc106847f2e53f1b207f8ec7cad/wp.sh && bash wp.sh"

Note that my script does NOT create the MySQL database for you as I currently use WHM/cPanel on our server to manage databases. If you want that functionality please use @emirpprime's fork here: https://gist.github.com/emirpprime/37ef1f355ec5a7ecbb8f.

Owner

bgallagh3r commented Mar 3, 2014

Add this to your ~/.bashrc
alias wpinstall="curl -L -o 'wp.sh' https://gist.githubusercontent.com/bgallagh3r/2853221/raw/f3e2f2fa3048bbeb6d35799af068965bc5fd9b26/wp.sh && bash wp.sh" then source ~/.bashrc Go into a dir you want to install WP in and just type wpinstall It's that easy!

Update:
I've updated the URL to the gist in this comment, WP changed the latest.tar.gz to use HTTPS (finally) as such trying to grab a copy from http::// broke the script

Update: July 8 2015
I've modified the script to add the salts automatically now thanks to @emirpprime's fork.
the new command should be alias wpinstall="curl -L -o 'wp.sh' https://gist.githubusercontent.com/bgallagh3r/2853221/raw/eb5070c1a4f06dc106847f2e53f1b207f8ec7cad/wp.sh && bash wp.sh"

Note that my script does NOT create the MySQL database for you as I currently use WHM/cPanel on our server to manage databases. If you want that functionality please use @emirpprime's fork here: https://gist.github.com/emirpprime/37ef1f355ec5a7ecbb8f.

@faddah

This comment has been minimized.

Show comment
Hide comment
@faddah

faddah Sep 12, 2014

hi,

i would like to use your bash shell script above, please, if that would be o.k., to run a wordpress install during a Vagrant/PuPHPet script of installing a VM on an AWS/EC2 server?

however, i do have a question, and please pardon my shell script ignorance here — i all ready know the db name, user name & password, have that all set-up, and Vagrant/PuPHPet will install the correct versions of PHP & MySQL for me. so i would like to just have the db, user name & and password in the script without any of the echo & read requests, and just have it do the install. so to do that, would i, instead of running...

...
echo "Database Name: "
read -e dbname
...

...etc., would i do it as variables like this —

...
$dbname = my_mysql_wordpress_db_name
...

...etc.? would that be how to do it?

or would i just delete all the echo & read stuff and put it somewhere in these statements —

#set database details with perl find and replace
perl -pi -e "s/database_name_here/[my_mysql_wordpress_db_name]/g" wp-config.php
perl -pi -e "s/username_here/[my_mysql_wordpress_db_user]/g" wp-config.php
perl -pi -e "s/password_here/[my_mysql_wordpress_db_password]/g" wp-config.php

if you could please advise on this, i would appreciate it. thank you in advance.

best,

— faddah wolf
portland, oregon, u.s.a.
https://github.com/faddah

faddah commented Sep 12, 2014

hi,

i would like to use your bash shell script above, please, if that would be o.k., to run a wordpress install during a Vagrant/PuPHPet script of installing a VM on an AWS/EC2 server?

however, i do have a question, and please pardon my shell script ignorance here — i all ready know the db name, user name & password, have that all set-up, and Vagrant/PuPHPet will install the correct versions of PHP & MySQL for me. so i would like to just have the db, user name & and password in the script without any of the echo & read requests, and just have it do the install. so to do that, would i, instead of running...

...
echo "Database Name: "
read -e dbname
...

...etc., would i do it as variables like this —

...
$dbname = my_mysql_wordpress_db_name
...

...etc.? would that be how to do it?

or would i just delete all the echo & read stuff and put it somewhere in these statements —

#set database details with perl find and replace
perl -pi -e "s/database_name_here/[my_mysql_wordpress_db_name]/g" wp-config.php
perl -pi -e "s/username_here/[my_mysql_wordpress_db_user]/g" wp-config.php
perl -pi -e "s/password_here/[my_mysql_wordpress_db_password]/g" wp-config.php

if you could please advise on this, i would appreciate it. thank you in advance.

best,

— faddah wolf
portland, oregon, u.s.a.
https://github.com/faddah

@bgallagh3r

This comment has been minimized.

Show comment
Hide comment
@bgallagh3r

bgallagh3r Nov 20, 2014

@faddah I have no issue with you using this, as this is a script I found and altered to suit my needs.

Owner

bgallagh3r commented Nov 20, 2014

@faddah I have no issue with you using this, as this is a script I found and altered to suit my needs.

@bgallagh3r

This comment has been minimized.

Show comment
Hide comment
@bgallagh3r

bgallagh3r Nov 20, 2014

@faddah sorry I didn't see your comment until now... weird I wasn't notified, but you were correct in doing it the last way by just replacing the "s/database_name/" lines with the actual user/password info. I don't really recommend it, it would likely be better to use an env variable or something instead but to each their own.

Owner

bgallagh3r commented Nov 20, 2014

@faddah sorry I didn't see your comment until now... weird I wasn't notified, but you were correct in doing it the last way by just replacing the "s/database_name/" lines with the actual user/password info. I don't really recommend it, it would likely be better to use an env variable or something instead but to each their own.

@brunogui81

This comment has been minimized.

Show comment
Hide comment
@brunogui81

brunogui81 Apr 9, 2015

Hi are you able to create the sql database in this script as well ?
Thanks and congrats works very nice.

Hi are you able to create the sql database in this script as well ?
Thanks and congrats works very nice.

@emirpprime

This comment has been minimized.

Show comment
Hide comment
@emirpprime

emirpprime Apr 9, 2015

@bgallaghr3 - really useful gist, thanks!

@brunogui81 - that's exactly what I wanted in too so added it in my fork https://gist.github.com/emirpprime/37ef1f355ec5a7ecbb8f
You'll probably need to modify it for your use (and that wasn't the only change), but it should get you going.

@bgallaghr3 - really useful gist, thanks!

@brunogui81 - that's exactly what I wanted in too so added it in my fork https://gist.github.com/emirpprime/37ef1f355ec5a7ecbb8f
You'll probably need to modify it for your use (and that wasn't the only change), but it should get you going.

@maiorano84

This comment has been minimized.

Show comment
Hide comment
@maiorano84

maiorano84 Aug 19, 2015

This is a fantastic script. One oddity I've noticed:

It seems like the password field being written to wp-config.php is stripping out meta characters. So if I enter a password that looks like: wordpr355u$3r, the dollar sign and the character following it are stripped out becoming:

wordpr355ur

I've tried something like:

perl -pi -e "s/password_here/\\Q${dbpass}/g" wp-config.php

But that doesn't solve the issue, and my Perl isn't very good. Any thoughts?

This is a fantastic script. One oddity I've noticed:

It seems like the password field being written to wp-config.php is stripping out meta characters. So if I enter a password that looks like: wordpr355u$3r, the dollar sign and the character following it are stripped out becoming:

wordpr355ur

I've tried something like:

perl -pi -e "s/password_here/\\Q${dbpass}/g" wp-config.php

But that doesn't solve the issue, and my Perl isn't very good. Any thoughts?

@buluma

This comment has been minimized.

Show comment
Hide comment
@buluma

buluma Sep 2, 2015

I've been looking for such.. need to try it out

buluma commented Sep 2, 2015

I've been looking for such.. need to try it out

@enoch85

This comment has been minimized.

Show comment
Hide comment

enoch85 commented Aug 16, 2016

This script builds a VM: https://github.com/enoch85/wordpress-vm

@sm0k3net

This comment has been minimized.

Show comment
Hide comment
@sm0k3net

sm0k3net Oct 10, 2016

Here is another version with clear installation from scratch.
If you have just clean server on Debian or Ubuntu - than this script will be useful for you :)
It helps to create user, group, install and configure Apache, MySQL, firewall, latest version of WordPress, some popular plugins and some other stuff.
https://github.com/sm0k3net/Useful-Scripts/blob/master/wordpress.sh

Here is another version with clear installation from scratch.
If you have just clean server on Debian or Ubuntu - than this script will be useful for you :)
It helps to create user, group, install and configure Apache, MySQL, firewall, latest version of WordPress, some popular plugins and some other stuff.
https://github.com/sm0k3net/Useful-Scripts/blob/master/wordpress.sh

@vincentkedison

This comment has been minimized.

Show comment
Hide comment
@vincentkedison

vincentkedison Jun 6, 2017

Hello, first I want to thanks for this script!
However, how to deal with password that contain special character?
e.g. when I type "P@$$word" at prompt, then it generate wp-config that contain:

/** MySQL database password */
define('DB_PASSWORD', 'p');

Hello, first I want to thanks for this script!
However, how to deal with password that contain special character?
e.g. when I type "P@$$word" at prompt, then it generate wp-config that contain:

/** MySQL database password */
define('DB_PASSWORD', 'p');
@rodrigobertin

This comment has been minimized.

Show comment
Hide comment
@rodrigobertin

rodrigobertin Oct 5, 2017

Great script thank you

Great script thank you

@zorbsOne

This comment has been minimized.

Show comment
Hide comment
@zorbsOne

zorbsOne Oct 6, 2017

Mint script, thanks.

zorbsOne commented Oct 6, 2017

Mint script, thanks.

@dariushzamani

This comment has been minimized.

Show comment
Hide comment
@dariushzamani

dariushzamani Oct 10, 2017

hi, i want install wordpress after user creat acount in whmcs ? is posible
dbf name, and user and password is not important, just install wordpress account with username, password same whmcs username and password , and email username and pasword wordpress email for user account whmcs .
thank you

dariushzamani commented Oct 10, 2017

hi, i want install wordpress after user creat acount in whmcs ? is posible
dbf name, and user and password is not important, just install wordpress account with username, password same whmcs username and password , and email username and pasword wordpress email for user account whmcs .
thank you

@dariushzamani

This comment has been minimized.

Show comment
Hide comment

اه

@FeChagas

This comment has been minimized.

Show comment
Hide comment
@FeChagas

FeChagas Jun 12, 2018

Hi, another updated version. This one where can create the database and asks to use if it already exists.
https://gist.github.com/FeChagas/54b0cdf354b197dc8e417357d7687e8b

Hi, another updated version. This one where can create the database and asks to use if it already exists.
https://gist.github.com/FeChagas/54b0cdf354b197dc8e417357d7687e8b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment