:: This is for spinning up installs for dev work, so don't consider this for :: production applications. It creates everything off a single entry variable :: so that you don't have to mess with unnecessary details. The site name and :: username are the same (a single input), as are the database and db user. :: The passwords for the initial WP user and the db user are generic "pass". :: PHP, WP-CLI, and MYSQL all need to be path environment variables. :: If you get errors that indicate something is not recognized as an internal :: or external command, make sure you have these in your PATH. @echo off :: Start in the XAMPP folder, assumes XAMPP is in the root (i.e. "c:/xampp/) :: (use PUSHD to get into the dir instead of "cd" so we can use POPD to get back into the original dir). PUSHD "C:/XAMPP/htdocs" :: Ask for package folder. Everything is built off this: subfolder name, WP user, db user, db name. echo WordPress site name (use a single term as this is used echo for all terms: user, database, folder name, etc.) set /p wp_name=Name: :: Create Database (uses MySQL CLI) echo Creating database and db user call mysql -e "CREATE USER '%wp_name%'@'localhost' IDENTIFIED BY 'pass';" -u root call mysql -e "GRANT ALL PRIVILEGES ON *.* TO '%wp_name%'@'localhost';" -u root call mysql -e "FLUSH PRIVILEGES;" -u root call mysql -e "CREATE DATABASE %wp_name%;" -u root :: Create folder in XAMPP/htdocs folder. echo Creating C:/XAMPP/htdocs/%wp_name%/ folder mkdir %wp_name% cd %wp_name% :: Download WordPress (uses WP-CLI) call wp core download :: Use WP-CLI to create the wp-config.php file echo Creating wp-config.php file call wp config create --dbname="%wp_name%" --dbuser=root --dbpass="" --dbhost=localhost --dbprefix="%wp_name%_" :: Install WordPress using WP-CLI echo Installing WordPress call wp core install --url="localhost/%wp_name%" --title="%wp_name%" --admin_user="%wp_name%" --admin_password=pass --admin_email=admin@localhost.com --skip-email :: We're done, print out access details. echo Done installing WordPress. echo Access at http://localhost/%wp_name%/ echo Log in at http://localhost/%wp_name%/wp-admin echo username: %wp_name% echo password: pass :: Go back to original folder (when using PUSHD to get into the dir, POPD takes us back). POPD @pause
Batch file to create WP site in XAMPP
This post brought to you by RocketGeek, ButlerBlog, and the following: