I've never had too much of an issue developing on Windows, and as a sysadmin I'm accustomed to using various operating systems. I previously used Windows on the desktop, Linux on the laptop, before tossing all of that out for a "tablet" as a workstation. Never thought I'd say that.
Anyway, I figured I'd throw a basic set of instructions out there for anyone having trouble with the typical Laravel setup on Windows. The Laragon thing looks pretty cool, but I've always felt that if Laravel is your framework of choice, Homestead is the way to go. Taylor goes through great lengths to make the ecosystem easy to work with. Admittedly there was a Homestead bug not too long ago that broke on Windows, but had an easy workaround. All of that is of course resolved.
I'm also well aware that the steps below are far more lengthy than the "apt-get" or "brew" methods, thus "why the heck are you developing on Windows?" Honestly, it takes about 20 minutes to setup vs the 5 on other operating systems. And if you're going through this setup more than twice a year (if that), something is definitely wrong. Really nothing to fuss about.
OK, enough jabber. I'm on Windows 8.1, but nothing will be different on Windows 7. If you're on Vista or XP, well, no wonder why the setup is giving you so much grief.
Grab PHP
- Go to http://windows.php.net/download/ and grab the latest version of PHP, threaded or non-threaded is fine.
- Extract contents to C:\php
- Add path as system environment variable by going to Control Panel > System > Advanced System Settings > Environment variables. Highlight Path and click Edit. Go to the end of Variable value and add: C:\php. Click OK to close all windows.
- You may need to edit the php.ini and uncomment some modules needed, depending what you plan on doing locally, but hopefully not much.
- Ever need to upgrade/downgrade to another version? Just overwrite the files in this directory with that build. Cake.
Git and a REAL Terminal
- Grab Git, and run the install with defaults. This will also give us the wonderful GitBash. No, it's not quite a full Bash or Linux shell, but it gives us exactly what we need and is way less messy than Cygwin.
- The default Windows terminal is absolutely awful. Do yourself a favor and install ConEmu (https://code.google.com/p/conemu-maximus5/wiki/Downloads?tm=2) and put that default "terminal" away for good. You can set default shells to open when the terminal is run. Naturally you want to select GitBash here, which ConEmu will automatically pick up on install.
Composer
Forget the Windows installer here and just download the latest phar and save it to C:\php\composer (no phar extension). We already added that path, so you can pop open ConEmu (in GitBash of course) and run composer. You should see the familiar list of composer commands.
Remember to always run composer commands from your native machine, not a VM!
VM Stuff and Node
Very basic and default installs here, just download and run.
Be sure your machine/processor has virtualization turned on in your BIOS.
Add the global node goodies since we want to run these on our machine, again, not within the slow virtual machine.
npm install bower -g
npm install ember-cli -g # if that's your thing :)
Global PHARs and Bash Aliases
You can install Homestead and the Laravel installer easily, as documented, with:
composer global require "laravel/installer=~1.1"
composer global require "laravel/homestead=~2.0"
Once again in GitBash, it's useful to setup command aliases. For example, I don't like installing Gulp globally, so I throw it in here. I also do not like the Composer Windows installer, or putting too much in the PATH env, so I use aliases for the global composer installs that are on my native machine.
Run vim .bashrc to open the editor. If you're not familiar with Vim (give it a try), then just use notepad .bashrc. Enter and save the following, or add/remove what works for you.
alias vm="ssh vagrant@localhost -p 2222"
alias homestead="~/AppData/Roaming/Composer/vendor/bin/homestead"
alias laravel="~/AppData/Roaming/Composer/vendor/bin/laravel"
alias gulp="node_modules/gulp/bin/gulp.js"
alias pspec="vendor/bin/phpspec"
Now you can run npm install and gulp from the shell on your machine, nice and fast, without issue. The only thing I tend to run in the VM are artisan commands.
PhpStorm
If an IDE is your thing, you can setup your project to read your local installs easily.
- In File > Settings > Language and Frameworks > PHP select 5.6 (or whatever) as the PHP language level and then click the ... next to Interpreter to add a new one. For the PHP executable, select C:\php\php.exe. You'll only have to do that once.
- In File > Settings > Language and Frameworks > PHP > Composer set Path to composer.phar to C:\php\composer and Path to composer.json to the project composer file in the root.
Other stuff
If you work with Ember CLI you should always run the ember serve command "as admin" (can be selected as a tab in ConEmu). For whatever reason running it this way speeds things up.
Be sure to exclude your workspace and other directories with a lot of files or writes (particularly where gulp is watching things) from both Windows Defender and the operating system indexer (Control Panel items).
As far as the "file name is too long" and 255 character thing, I rarely run into this, but when I do, it's trying to rm -rf node_modules; those directories run deep. Simply run the following to easily trash the folder. Someday they'll fix that in NTFS...
mkdir C:\empty
robocopy C:\empty C:\workspace\proj\node_modules /mir
rmdir C:\empty C:\workspace\proj\node_modules
Hope this helps!