Skip to content

Instantly share code, notes, and snippets.

@leandroribeiro
Created October 14, 2016 15:45
Show Gist options
  • Save leandroribeiro/8676528c5c08c2c7d211f6368a23cca4 to your computer and use it in GitHub Desktop.
Save leandroribeiro/8676528c5c08c2c7d211f6368a23cca4 to your computer and use it in GitHub Desktop.
Automatic WordPress installation powered by wp-cli
@echo off
:: Source: https://indigotree.co.uk/automated-wordpress-installation-cmd/
:: STEPS:
:: 1. Install wp-cli
:: 2. Install composer
:: 3. Install MySQL
:: 4. Configure wp-cli at System PATH
:: 5. Configure composer at System PATH
:: 6. Configure MySQL at System PATH
:: 7. Save this script as a BATCH file
:: 8. Configure this script PATH at System PATH
:: 9. FOR THIS SCRIPT TO GENERATE PRETTY URLS YOU MUST ADD WP_CLI_CONFIG_PATH=%USERPROFILE%\.wp-cli\config.yml to your user/system environment variables
:: 10. in config.yml you must specify apache_modules: - mod_rewrite
:: Important variables
SET ROOT=C:\www
SET DBUSER=root
SET DBPASS=#123qwe
SET USER=7commdev
SET PASSWORD=123#aasp7comm
SET [email protected]
:: Password Generator
Setlocal EnableDelayedExpansion
Set _RNDLength=10
Set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Set _Str=%_Alphanumeric%987654321
:_LenLoop
IF NOT "%_Str:~18%"=="" SET _Str=%_Str:~9%& SET /A _Len+=9& GOTO :_LenLoop
SET _tmp=%_Str:~9,1%
SET /A _Len=_Len+_tmp
Set _count=0
SET _RndAlphaNum=
:_loop
Set /a _count+=1
SET _RND=%Random%
Set /A _RND=_RND%%%_Len%
SET _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1!
If !_count! lss %_RNDLength% goto _loop
:: GENERATE PASSWORD???
:: Set PASSWORD=!_RndAlphaNum!
:: Was an argument passed?
IF [%1] == [] GOTO fatal
echo.
echo.
echo __ __ __ ____
echo /\ \ __/\ \ /\ \/\ _`\
echo \ \ \/\ \ \ \ ___ _ __ \_\ \ \ \ \ \_ __ __ ____ ____
echo \ \ \ \ \ \ \ / __`\/\`'__\/'_` \ \ ,__/\`'__\/'__`\ /',__\ /',__\
echo \ \ \_/ \_\ \/\ \L\ \ \ \//\ \L\ \ \ \/\ \ \//\ __//\__, `\/\__, `\
echo \ `\___x___/\ \____/\ \_\\ \___,_\ \_\ \ \_\\ \____\/\____/\/\____/
echo '\/__//__/ \/___/ \/_/ \/__,_ /\/_/ \/_/ \/____/\/___/ \/___/
echo.
echo --------------------------------------------------------------------------------
echo Install WordPress 4.0
echo.
:: Navigate to the local project folder
cd %ROOT%
:: Set the name of the new install
SET NAME=%1
SET URL=%2
:: Set the name of the new install
SET DBNAME=wp_%NAME%
echo.
echo --------------------------------------------------------------------------------
echo Installing WordPress..
echo.
:: Create directory
mkdir %NAME%
:: Go into directory
cd %NAME%
:: Download WordPress
call wp core download --locale=pt_BR
:: Generate wp-config
:: We need to escape the php we pass in to the wp-config or we will get syntax errors
(echo define^^^('WP_DEBUG', true^^^);^
& echo define^^^('DISALLOW_FILE_EDIT', true ^^^);) | wp core config --dbname=%DBNAME% --dbuser=%DBUSER% --dbpass=%DBPASS% --extra-php
:: Create DB
call wp db create
:: Install wordpress
:: call wp core install --url="http://localhost/%NAME%" --title="%NAME%" --admin_user="%USER%" --admin_password="%PASSWORD%" --admin_email="%EMAIL%"
:: call wp core install --url="http://localhost:8080/%NAME%" --title="%NAME%" --admin_user="%USER%" --admin_password="%PASSWORD%" --admin_email="%EMAIL%"
call wp core install --url="%URL%" --title="%NAME%" --admin_user="%USER%" --admin_password="%PASSWORD%" --admin_email="%EMAIL%"
echo.
echo --------------------------------------------------------------------------------
echo Cleaning Plugins
echo.
:: Discourage search engines
call wp option update blog_public 0
:: show only 6 posts on an archive page
call wp option update posts_per_page 6
:: Delete akismet and hello dolly
call wp plugin delete akismet
call wp plugin delete hello
:: Add our own plugins here
echo.
echo --------------------------------------------------------------------------------
echo Installing Lt-theme
echo.
:: set pretty urls
:: we set pretty urls here to give it some time to complete before flushing the permalinks later
:: unfortunatly call does not work on this command so we have to open and run in a seperate cmd window
start cmd /c wp rewrite structure /%%postname%%/ --hard
:: Add and activate your own themes here
:: Clear Window
cls
:: ASCII ART
echo.
echo.
echo.
echo __ __ __ ____
echo /\ \ __/\ \ /\ \/\ _`\
echo \ \ \/\ \ \ \ ___ _ __ \_\ \ \ \ \ \_ __ __ ____ ____
echo \ \ \ \ \ \ \ / __`\/\`'__\/'_` \ \ ,__/\`'__\/'__`\ /',__\ /',__\
echo \ \ \_/ \_\ \/\ \L\ \ \ \//\ \L\ \ \ \/\ \ \//\ __//\__, `\/\__, `\
echo \ `\___x___/\ \____/\ \_\\ \___,_\ \_\ \ \_\\ \____\/\____/\/\____/
echo '\/__//__/ \/___/ \/_/ \/__,_ /\/_/ \/_/ \/____/\/___/ \/___/
echo.
echo --------------------------------------------------------------------------------
echo Installation is complete. Your username/password have been added to your clipboard and are listed below.
echo.
echo Username: %USER%
echo Password: %PASSWORD%
echo.
echo have a nice day :)
echo.
:: Add to clipboard
echo Username: %USER% Password: %PASSWORD% | clip
:: start the project in browser
:: start http://localhost/%NAME%
start %URL%
:: unfortunatly call does not work on this command so we have to open and run in a seperate cmd window
start cmd /c wp rewrite flush --hard
pause
goto:eof
:fatal
echo.
echo --------------------------------------------------------------------------------
echo Please specify a name for your WordPress Install
echo.
goto:eof
:END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment