Install Php Windows Git Bash



  1. Uninstall Git Bash Windows
  2. Install Php Windows Git Bash Linux
  3. Install Php Windows Git Bash Tutorial
-->

Browse other questions tagged php windows environment-variables git-bash or ask your own question. The Overflow Blog Podcast 307: Owning the code, from integration to delivery. In this video we use the new bash shell / linux subsystem under Windows-10 and install Apache and MySQL (lamp-server) to write hand test PHP applications und.

Visual Studio Code, along with the Remote - WSL extension, enables you to use WSL as your full-time development environment directly from VS Code. You can:

  • develop in a Linux-based environment
  • use Linux-specific toolchains and utilities
  • run and debug your Linux-based applications from the comfort of Windows while maintaining access to productivity tools like Outlook and Office
  • use the VS Code built-in terminal to run your Linux distribution of choice
  • take advantage of VS Code features like Intellisense code completion, linting, debug support, code snippets, and unit testing
  • easily manage your version control with VS Code's built-in Git support
  • run commands and VS Code extensions directly on your WSL projects
  • edit files in your Linux or mounted Windows filesystem (for example /mnt/c) without worrying about pathing issues, binary compatibility, or other cross-OS challenges

Install VS Code and the Remote WSL extension

  • Visit the VS Code install page and select the 32 or 64 bit installer. Install Visual Studio Code on Windows (not in your WSL file system).

  • When prompted to Select Additional Tasks during installation, be sure to check the Add to PATH option so you can easily open a folder in WSL using the code command.

  • Install the Remote Development extension pack. This extension pack includes the Remote - WSL extension, in addition to the Remote - SSH, and Remote - Containers extensions, enabling you to open any folder in a container, on a remote machine, or in WSL.

Important

In order to install the Remote-WSL extension, you will need the 1.35 May release version or later of VS Code. We do not recommend using WSL in VS Code without the Remote-WSL extension as you will lose support for auto-complete, debugging, linting, etc. Fun fact: this WSL extension is installed in $HOME/.vscode/extensions (enter the command ls $HOME.vscodeextensions in PowerShell).

Update your Linux distribution

Some WSL Linux distributions are lacking libraries that are required by the VS Code server to start up. You can add additional libraries into your Linux distribution by using its package manager.

For example, to update Debian or Ubuntu, use:

To add wget (to retrieve content from web servers) and ca-certificates (to allow SSL-based applications to check for the authenticity of SSL connections), enter:

Open a WSL project in Visual Studio Code

From the command-line

To open a project from your WSL distribution, open the distribution's command line and enter: code .

From VS Code

You can also access more VS Code Remote options by using the shortcut: CTRL+SHIFT+P in VS Code to bring up the command palette. If you then type Remote-WSL you will see a list of the VS Code Remote options available, allowing you to reopen the folder in a remote session, specify which distribution you want to open in, and more.

Extensions inside of VS Code Remote

The Remote-WSL extension splits VS Code into a “client-server” architecture, with the client (the user interface) running on your Windows machine and the server (your code, Git, plugins, etc) running remotely.

When running VS Code Remote, selecting the 'Extensions' tab will display a list of extensions split between your local machine and your WSL distribution.

Installing a local extension, like a theme, only needs to be installed once.

Install git for windows

Some extensions, like the Python extension or anything that handles things like linting or debugging, must be installed separately on each remote WSL distributions. VS Code will display a warning icon ⚠, along with a green 'Install in WSL' button, if you have an extension locally installed that is not installed on your WSL Remote.

For further information, see the VS Code docs:

  • When VS Code Remote is started in WSL, no shell startup scripts are run. See this advanced environment setup script article for more info on how to run additional commands or modify the environment.

  • Having problems launching VS Code from your WSL command line? This troubleshooting guide includes tips on changing path variables, resolving extension errors about missing dependencies, resolving Git line ending issues, installing a local VSIX on a remote machine, launching a browser window, blocker localhost port, web sockets not working, errors storing extension data, and more.

Install Git (optional)

Uninstall Git Bash Windows

If you plan to collaborate with others, or host your project on an open-source site (like GitHub), VS Code supports version control with Git. The Source Control tab in VS Code tracks all of your changes and has common Git commands (add, commit, push, pull) built right into the UI.

To install Git, see set up Git to work with Windows Subsystem for Linux.

Install Windows Terminal (optional)

The new Windows Terminal enables multiple tabs (quickly switch between Command Prompt, PowerShell, or multiple Linux distributions), custom key bindings (create your own shortcut keys for opening or closing tabs, copy+paste, etc.), emojis ☺, and custom themes (color schemes, font styles and sizes, background image/blur/transparency). Learn more in the Windows Terminal docs.

  1. Get Windows Terminal in the Microsoft Store: By installing via the store, updates are handled automatically.

  2. Once installed, open Windows Terminal and select Settings to customize your terminal using the profile.json file.

Additional Resources

A few additional extensions you may want to consider include:

  • Keymaps from other editors: These extensions can help your environment feel right at home if you're transitioning from another text editor (like Atom, Sublime, Vim, eMacs, Notepad++, etc).
  • Settings Sync: Enables you to synchronize your VS Code settings across different installations using GitHub. If you work on different machines, this helps keep your environment consistent across them.
  • Debugger for Chrome: Once you finish developing on the server side with Linux, you'll need to develop and test the client side. This extension integrates your VS Code editor with your Chrome browser debugging service, making things a bit more efficient.

This article has been updated to reflect Git for Windows version 2.13.2 and a new version of posh-git; the PowerShell scripts have been changed to address issues raised by commenters. The previous version was posted on 12 March 2016, and any comments on this page that were written prior to 22 July 2017 are referencing that older version.

How to install Git on Windows 10 systems and run Git from a PowerShell command line.

Installing Git

On modern Windows systems, the best way to get Git is to use the installers produced by the Git for Windows project.

Download the install kit from https://git-for-windows.github.io/. This will download the installer for the latest release, and that will install 64-bit software. If you want 32-bit software, or a specific Git for Windows version, then visit the release section of the git-for-windows project: https://github.com/git-for-windows/git/releases.

Launch the installer as the administrator1 and walk through the installation2 dialog panels as follows:

  1. License. Next.

  2. Install path. If this isn’t installing in Program Files then you probably didn’t run the installer with elevated privilege1. Next.

  3. Select options to be installed. Because the goal is to minimize the impact on the Windows system, and to run Git from a PowerShell command line, I recommend only checking the Git LFS (Large File Support).

    Only Git LFS. Next.

  4. Start menu folder name. Next.

  5. Adjusting the PATH. Leave the default option, the one that does not modify the path. Next.

  6. Choose a trusted store for TLS certificate authorities (CAs). Unless you know you need the OpenSSL CA bundle, select “Use the native Windows Secure Channel library”.

    Use the native Windows Secure Channel library.Next.

  7. Line ending conversion. Leave the default option, the one that checks out Windows-style line endings and commits Unix-style line endings. Next.

  8. Select the terminal emulator. On a Windows 8.1 (or Server 2012 R2) or earlier system, leave the default selection (MinTTY).

    On a Windows 10 system, change to use the Windows’ default console window. Next.

  9. Extra options. Don’t select anything. Next.

  10. Watch the install proceed.

  11. Install completed. Click Finish and read the release notes. Really. Especially the known issues section.

Adjusting the installed shortcuts

The installer will have laid down three shortcuts in the start menu.

These shortcuts are of secondary importance; the primary goal is to use Git from a PowerShell command line. However, you may find reasons to use either Git Bash or Git CMD. So configure them now; launch each3 and configure the window properties4 to enable Quick Edit and set the scroll buffer to 9999 lines.

  1. Go to the “Options” tab.

  2. Make sure QuickEdit Mode is checked.

  3. Go to the “Layout” tab.

  4. Change the Height property of the Screen Buffer Size to 9999.

  5. Click the “OK” button.

It’s worth launching a command window and checking to see that the expected version of Git is installed and running.

Configure a simple Git PowerShell command window

Install Php Windows Git Bash Linux

Use the file explorer to navigate to :WindowsSystem32WindowsPowerShellv1.0 and right-click on powershell.exe to create a shortcut on the desktop. Rename that shortcut to “Windows PowerShell (bootstrap)” and then move it to the Start Screen folder.5

Edit shortcut properties to change the shortcut target to:

The -NoProfile argument is important. It prevents any default profiles from loading; and that will avoid introducing issues and injecting kruft that can send you down a troubleshooting rat hole. Yep, I speak from experience.

While you are in properties dialog, you might as well set the scroll buffer to 9999 and enable QuickEdit.

Now, using your favorite programming editor, create the PowerShell profile script %USERPROFILE%DocumentsWindowsPowerShellbootstrap-git.profile.ps1 with this content:

Launch the shortcut. Enter the command git --version. You should see the expected Git version.

Great! You’ve got Git running in PowerShell. :-).

Get useful CLI sugar with posh-git

posh-git is a PowerShell module that adds tab completion for Git commands and also a very helpful colorized command prompt that shows the branch and status of the current repo, including remote repo status. You will want to install posh-git.

I recommend using the manual install method so that you can keep posh-git up to date with the latest patches.

  1. In your new PowerShell window, check the execution policy with Get-ExecutionPolicy. It should be RemoteSigned or Unrestricted.6
  2. cd ~Documents and create a directory GitHub.
  3. cd GitHub
  4. git clone https://github.com/dahlbyk/posh-git.git
  5. cd posh-git

In the current directory you should now see a file called example.profile.ps1. That is an example of how to load the posh-get module and start the ssh-agent (used to avoid repeated password prompts from SSH—more on that in the next section).

I’ve taken that example and tweaked it a bit to have better colorization in the command prompt and to work from any working directory. I put it in a script file that can be included (via the source command, “.”) in any profile. The script is called posh-git.src.ps1, and it looks like this:

Also create a simple script that sets up the session transcript, called transcript.src.ps1. Something like this:

Now we can create a new profile script, posh-git.profile.ps1 and use that to launch a PowerShell window that has Git and posh-git activated. My example of that script looks like:

Create another shortcut similar to the “Windows PowerShell (bootstrap)” shortcut you created before, but name it “Windows PowerShell (posh-git)” and set the Target to:

Pin that shortcut to the Start Screen and the Task Bar and you are good to go.

ssh-agent

Install Php Windows Git Bash Tutorial

The script above will launch an ssh-agent process (if one is not already running). ssh-agent caches private key passphrases and supplies them to Git when needed. This is helpful for avoiding a passphrase prompt every time you execute a Git command that touches the remote repo. You will want to use ssh-agent.

To store your passphrase with the ssh-agent process, use the ssh-add command to cache the passphrase for a private key, like so:

That command will prompt you for the passphrase. If you enter the correct one, then all further use of that private key by Git will not again prompt for the passphrase.

Other tweaks

I like slightly different colors in my Git command output, so I set my Git global config7 to include these colorization overrides:

I also like to use Sublime Text 3 as my editor, so:

And I have a custom commit message template, referenced via:

It just has column numbering so I can see how long my lines are, and keep the first line under 50 characters (to make git commit history looking pretty). The template looks like this:

Upgrading Git

To upgrade Git for Windows to a new version, just run the new installer (making sure to run it as administrator). The installer will remember the configuration choices you made during the last install, so it should just be a matter of repeatedly clicking “Next”. It is probably a good idea to close any command windows that might have activated Git. And you may get prompted to kill any running ssh-agent.exe processes.

  1. Right click on the file and select “Run as administrator”. Or open a command using using “Run as administrator” and run the installer EXE from that command line. ↩↩2

  2. I downloaded the 2.13.2 installer, Git-2.13.2-64-bit.exe, and ran it (as administrator) on my Windows 10 box. ↩

  3. You may need to launch the command windows using “Run as administrator” to have the privileges needed to save the window property changes. ↩

  4. Edit window properties by pulling down the window’s System Menu (click on the icon in the upper left of the title bar) and selecting “Properties”. You enable QuickEdit Mode from the “Options” tab. You set the scroll buffer size on the “Layout” tab by setting the Height property of the “Screen Buffer size” to 9999. ↩

  5. On my system, the Start Menu folder is C:Usersheind.CORPAppDataRoamingMicrosoftWindowsStart MenuPrograms. You can find the location of your own Start Screen by right-clicking on any Start Screen shortcut, selecting “More” and then “Open file location”. ↩

  6. If not RemoteSigned or Unrestricted then run PowerShell as administrator and call Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm. ↩

  7. To set the global config use a command like git config --global color.status.add 'green bold'. ↩