The setup: Windows Server 2019 webserver with XAMPP, hosting a webapp written in PHP with a MySQL DB. The devs push changes to our company's Git repo.
The issue: For reasons unknown to me, when new code is pushed, it needs to be manually Git Pulled on the webserver, then the new/updated PHP files are moved manually to the respective folders of the webapp. I decided to put into practice the little programming knowledge I've got and automate this process.
The first step was to create a batch file that does Git Pull, logs output in a text file, then using PowerShell, moves the latest files to the destination folders. This work beautifully. However, it requires logging into the server to run the batch file.
The next step is to start the batch file using a page in the webapp, let's say, www.mywebapp.com/git_pull_and_move.php. I've created a Start button on this page clicking on which should execute the batch file. The batch file goes as far as creating the text file to log the output of Git Pull, but the text file is empty. Any clues why this could be happening? Please ask if you need more info.
Snippet of the PHP code:
if(isset($_POST["Start"])){
// system("cmd /c C:\\full_path\\to_the_batch_file.bat"); // Doesn't work; Commented out at the moment
exec('C:\\full_path\\to_the_batch_file.bat'); // Doesn't work either
This is what the batch file looks like:
@echo off
cmd /c cd C:\full_path\to_the_local_git_repo
cmd /c git remote remove origin
cmd /c git remote add origin _removed_for_privacy_reasons_ :D
cmd /c git -C C:\full_path\to_the_local_git_repo pull https://github.com/my_company master >> C:\full_path\to_log_git_pull_output.txt
Sorry for writing a novella!