Skip to content

Instantly share code, notes, and snippets.

@bgallagh3r
Last active October 2, 2024 09:42
Show Gist options
  • Save bgallagh3r/2853221 to your computer and use it in GitHub Desktop.
Save bgallagh3r/2853221 to your computer and use it in GitHub Desktop.
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
@maiorano84
Copy link

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
Copy link

buluma commented Sep 2, 2015

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

@enoch85
Copy link

enoch85 commented Aug 16, 2016

@sm0k3net
Copy link

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
Copy link

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
Copy link

Great script thank you

@zorbsOne
Copy link

zorbsOne commented Oct 6, 2017

Mint script, thanks.

@dariushzamani
Copy link

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
Copy link

اه

@FeChagas
Copy link

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

@cconversion
Copy link

cconversion commented Oct 25, 2018

Another installer for Shell perspective: https://github.com/cconversion/wp-installer
Inspired by, not forked from, this here @bgallagh3r gist.

@bajpangosh
Copy link

Here is High Traffic wordpress server configuration bash script
https://github.com/bajpangosh/High-Traffic-wordpress-server-configuration

@jessuppi
Copy link

jessuppi commented Jul 1, 2019

Wow, this Gist is still at the top of Google for "WordPress installer script" after 5+ years...

A simpler way to generate the salts via OpenSSL (albeit slightly less secure, but less chance of conflict due to symbols):

sed -i "s/put your unique phrase here/$(openssl rand -hex 48)/g"

Please check out SlickStack (any feedback appreciated):

https://github.com/littlebizzy/slickstack

@rjekic
Copy link

rjekic commented Jan 13, 2020

Great gist :). Inspired me to fork it and modify it by adding support for wp-cli

https://gist.github.com/rjekic/2d04423bd167f8e7afd26f8982609378

@chandra10207
Copy link

Hi,
I am new to Perl and I want to change the table prefix as well.
Can you please tell me, how can I change the table prefix?

@aatayyab
Copy link

Worked like a charm and quickest installation of WordPress I have achieved so far. Thanks

@Urano-Gonzalez
Copy link

Urano-Gonzalez commented Jun 5, 2020

Simple, direct, and reliable

@ericmil87
Copy link

Great work. Thanks!

@carlHandy
Copy link

I took this a step further by allowing it to configure my nginx server block. See here:

https://gitlab.com/snippets/1988869

@onyxcode
Copy link

I wish there was something this simple for bind9 as well haha

@aliwaseem
Copy link

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.

I think the link above for @emirpprime's fork is broken. A google search suggest that he has changed his github handle?
I think the new link is: https://gist.github.com/phlbnks/37ef1f355ec5a7ecbb8f

@levpa
Copy link

levpa commented Sep 29, 2020

Hi pal! I think you must add a database host URL to the script. Usually, it's localhost in wp-config.php and not work for me.

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