Skip to content

Instantly share code, notes, and snippets.

@skoskie
Created July 20, 2019 03:09
Show Gist options
  • Save skoskie/0d775b1519cad30726c0f1da07e4c08f to your computer and use it in GitHub Desktop.
Save skoskie/0d775b1519cad30726c0f1da07e4c08f to your computer and use it in GitHub Desktop.
A terminal script to quickly spin up an instance of wordpress. It's not really a fork, but it was fully inspired by another gist I commented on here: https://gist.github.com/BFTrick/11294357#gistcomment-2975609

Here's the file structure I use, and the script "kinda sorta" assumes a similar hierarchy; i.e. with the git root one level above the web root.

ProjectName/Repo/.git/
                /public/

To start out, just create the Repo directory in your project directory. The Repo directory should be empty when you run the script. Then cd ProjectName/Repo, and run the wp-up.sh script, or maybe just copy the pieces that work for you.

I should note that I keep wp-config.php one level above the web root. If that's not your thing, just remove (or skip) the line that reads mv ./public/wp-config-sample.php ./wp-config.php.

Disclaimer: Do not copy things you do not understand from the internet into your terminal. I am not available for support. And if it all goes south because you made a mistake, you are on your own. Good luck.

Credit to the gist that inspired me to throw this together ... https://gist.github.com/BFTrick/11294357#gistcomment-2975609

# Starting in `NewProject/Repo`, an empty directory...
# Create a new git repo
git init
# Grab a generic gitignore file. Alternatively, keep a template you prefer and copy it to this directory.
curl https://raw.githubusercontent.com/github/gitignore/master/WordPress.gitignore > .gitignore
# Get the current version of WordPress, zipped. It would be awesome if there were some kind of version file we could reference.
curl -LO https://wordpress.org/latest.zip
# Extract the files and then trash the zip file.
unzip latest.zip && rm latest.zip
# rename the "wordpress" directory so it becomes our web root.
mv wordpress public
# make your first commit.
git add --all && git commit -sq -m "Initial commit of Wordpress core files. Hello World!!"
# Depending on your git configuration, you might have seen a few warnings about line endings. That's okay.
# We are about to fire up the WP install screen in your web browser. If you prefer to just edit the config file in a text editor, `GOTO: JustAnother;`, or copy your finely tuned wp-config.php file from wherever you keep it to this (yes, the current) directory, and then `GOTO: JustAnother;`
open http://localhost:9000/wp-admin/install.php
# Didn't work? That's because we have to start the server, but it blocks command prompt, so we opened the webpage first.
php -S localhost:9000
# Now refresh that webpage and it should come right up. Time to enter your database details. I can't help you there. But when you are done, setting it up, meet me back here.
###
# Turn off the PHP server by pressing "ctrl+C".
# JustAnother:
# We are almost done. Just need to get rid of that sample config file...
rm ./public/wp-config-sample.php
# And I prefer to keep my config file above the webroot.
mv ./public/wp-config.php ./wp-config.php
# You're all done. Although if you do bundle this up into a nice little script, be sure to give yourself some words of encouragement.
echo "Well done. Now it's time to build something amazing. Good luck with the project!"
# See? Don't you feel better now?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment