Last active
April 19, 2024 22:41
-
-
Save stoffl6781/ec9048f1aa381acb6e10d7ad91ca8276 to your computer and use it in GitHub Desktop.
WordPress BAT XAMPP Installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal enabledelayedexpansion | |
echo Checking if XAMPP is installed... | |
if exist "C:\xampp\xampp-control.exe" ( | |
set XAMPP_DIR=C:\xampp | |
) else ( | |
echo XAMPP not found at the default location. | |
set /p XAMPP_DIR="Please enter your XAMPP installation path (e.g., D:\xampp): " | |
if not exist "!XAMPP_DIR!\xampp-control.exe" ( | |
echo Invalid XAMPP path. The script will now exit. | |
goto end | |
) | |
) | |
echo XAMPP installation detected at !XAMPP_DIR! | |
echo ******************************************************************************* | |
echo * * | |
echo * WordPress Setup Automation Script * | |
echo * * | |
echo * Version: 1.0.0 * | |
echo * Author: Christoph Purin * | |
echo * www.purin.at - [email protected] * | |
echo * Date: 2024-04-20 * | |
echo * * | |
echo * This script automates the setup of WordPress including database creation, * | |
echo * configuration adjustments, and server restarts for immediate deployment. * | |
echo * * | |
echo ******************************************************************************* | |
set WP_Download_Dir=!XAMPP_DIR!\wordpress_temp | |
set WP_Local_Zip="!WP_Download_Dir!\wordpress.zip" | |
set WP_Download_URL=https://de-at.wordpress.org/latest-de_AT.zip | |
set WP_Version_File="!XAMPP_DIR!\htdocs\wordpress_version.txt" | |
set MySQL_Path=!XAMPP_DIR!\mysql\bin | |
set Current_Version=0 | |
set Latest_Version=0 | |
if not exist "!WP_Download_Dir!" ( | |
mkdir "!WP_Download_Dir!" | |
) | |
if exist "!WP_Version_File!" ( | |
set /p Current_Version=<"!WP_Version_File!" | |
) | |
echo Checking for latest WordPress version... | |
powershell -command "$response = Invoke-WebRequest -Uri 'https://api.github.com/repos/WordPress/WordPress/tags'; $latest = ($response.Content | ConvertFrom-Json)[0].name; Write-Output $latest" > "%temp%\latest_wp_version.txt" | |
set /p Latest_Version=<"%temp%\latest_wp_version.txt" | |
if "!Latest_Version!" neq "!Current_Version!" ( | |
echo New WordPress version available: !Latest_Version! | |
echo Downloading WordPress... | |
powershell -command "Invoke-WebRequest -Uri '!WP_Download_URL!' -OutFile !WP_Local_Zip!" | |
echo Extracting WordPress... | |
powershell -command "Expand-Archive -Path !WP_Local_Zip! -DestinationPath '!WP_Download_Dir!' -Force" | |
echo !Latest_Version!>"!WP_Version_File!" | |
) else ( | |
echo WordPress is up-to-date with version !Current_Version!. | |
) | |
:input | |
set /p ProjectName="Bitte geben Sie den Projektnamen ein: " | |
if exist "C:\xampp\htdocs\%ProjectName%\" ( | |
echo Ein Projekt mit diesem Namen existiert bereits. | |
set /p UserChoice="Möchten Sie das vorhandene Verzeichnis überschreiben (J/N)? " | |
if /I "!UserChoice!"=="J" ( | |
echo Löschen und Neuerstellen des Verzeichnisses... | |
rd /s /q "C:\xampp\htdocs\%ProjectName%\" | |
mkdir "C:\xampp\htdocs\%ProjectName%\" | |
) else ( | |
echo Vorgang abgebrochen. | |
goto input | |
) | |
) else ( | |
echo Preparing target directory... | |
mkdir "C:\xampp\htdocs\%ProjectName%\" | |
) | |
echo Checking if WordPress files are ready to move... | |
if not exist "!WP_Download_Dir!\wordpress\" ( | |
echo WordPress files not found, redownloading... | |
echo Downloading WordPress... | |
powershell -command "Invoke-WebRequest -Uri '!WP_Download_URL!' -OutFile !WP_Local_Zip!" | |
echo Extracting WordPress... | |
powershell -command "Expand-Archive -Path !WP_Local_Zip! -DestinationPath '!WP_Download_Dir!' -Force" | |
) | |
echo Moving WordPress files... | |
xcopy /E /I "!WP_Download_Dir!\wordpress\" "C:\xampp\htdocs\%ProjectName%\" | |
if %errorlevel% neq 0 ( | |
echo Error moving WordPress files. Check if the source and target paths are correct. | |
goto end | |
) | |
echo Checking hosts file... | |
find /c "127.0.0.1 %ProjectName%.local" C:\Windows\System32\drivers\etc\hosts > nul | |
if %errorlevel%==0 ( | |
echo Host entry already exists, skipping... | |
) else ( | |
echo Adding entry to hosts file... | |
echo 127.0.0.1 %ProjectName%.local >> C:\Windows\System32\drivers\etc\hosts | |
) | |
echo Checking Apache VirtualHost... | |
set VHOST_FILE="C:\xampp\apache\conf\extra\httpd-vhosts.conf" | |
findstr /c:"ServerName %ProjectName%.local" %VHOST_FILE% > nul | |
if %errorlevel%==0 ( | |
echo VirtualHost already exists, skipping... | |
) else ( | |
echo Adding VirtualHost to Apache... | |
( | |
echo ^<VirtualHost *:80^> | |
echo ServerName %ProjectName%.local | |
echo DocumentRoot "C:/xampp\htdocs/%ProjectName%" | |
echo ^</VirtualHost^> | |
) >> %VHOST_FILE% | |
) | |
echo Configuring WordPress... | |
copy "C:\xampp\htdocs\%ProjectName%\wp-config-sample.php" "C:\xampp\htdocs\%ProjectName%\wp-config.php" > nul | |
set /p DBName="Datenbankname: " | |
set /p DBUser="Datenbank Benutzer (default 'root'): " || set DBUser=root | |
set /p DBPassword="Datenbank Passwort: " || set DBPassword= | |
powershell -command "(Get-Content 'C:\xampp\htdocs\%ProjectName%\wp-config.php') -replace 'database_name_here', '%DBName%' -replace 'username_here', '%DBUser%' -replace 'password_here', '%DBPassword%' | Set-Content 'C:\xampp\htdocs\%ProjectName%\wp-config.php'" | |
echo Creating MySQL Database... | |
"%MySQL_Path%\mysql" -u %DBUser% -p%DBPassword% -e "CREATE DATABASE IF NOT EXISTS %DBName%;" | |
echo Checking if Apache service is installed... | |
sc query Apache2.4 > nul 2>&1 | |
if %errorlevel% == 1060 ( | |
echo Apache service is not installed. Please start Apache manually via the XAMPP Control Panel. | |
) else ( | |
echo Apache service is detected. Attempting to restart... | |
net stop Apache2.4 | |
net start Apache2.4 | |
) | |
echo Done! | |
pause | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment