Install PHP7 and Composer on Windows 10

PHP7 is a general purpose scripting language well suited for web development. Composer is the defacto package manager for PHP7. This tutorial will show you how to install PHP7 and Composer on Windows 10 for use in a command prompt.

A common misconception is that you need a web server like IIS, Apache, or Nginx to work with PHP7. In fact, PHP7 has it’s own built in web server that you can invoke at the command prompt. Modern PHP frameworks such as Opulence support this.

Installing PHP7

Download the latest PHP7 (non-thread safe version) zip file from http://windows.php.net/

Extract the contents of the zip file into C:\PHP7

Copy C:\PHP7\php.ini-development to C:\PHP7\php.ini

Open the newly copied C:\PHP7\php.ini in a text editor.

Scroll down to “Directory in which the loadable extensions (modules) reside.” and uncomment: extension_dir = “ext”

Notepad++ is great.

Scroll down to the DLL extensions section and uncomment the extensions you want to use.

My current setup.

Tweak other settings as needed.

Note: Don’t forget to keep your php.ini file in a safe place when you upgrade in the future!

Add C:\PHP7 to the Windows 10 system path environment variable.

Windows 10 has finally improved this interface, yay!

In a command prompt test that the installation is successful by typing php -v

ConEmu is great.

Installing Composer

On my computer I’ve created a C:\Users\dac514\bin directory where I keep miscellaneous executables. This directory is in my user path.

Use a search engine to find a tutorial and do something similar. Optionally install composer in the C:\PHP7 directory you just created as it’s already in your path.

To get composer.phar, drop to a command prompt, cd into your target directory, and run:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

(Important! Click here for a more secure and up-to-date install snippet.)

Next, create a new composer.bat file alongside the composer.phar file so that Windows 10 can execute it more easily. (Source)

echo @php "%~dp0composer.phar" %*>composer.bat

Test that it’s working by typing composer -V

ConEmu is still great.

Crapware At Every Turn

I have a Cannon PowerShot camera. When I take videos it records .MOV files.

On Windows 10 I use Picasa to organize my pictures. To import and view MOV files in Picasa I need to install QuickTime.

Regrettably, the QuickTime installer doesn’t work on Windows 10.

One “recommended workaround”  is to install the K-Lite Codec pack. When I tried to install it I was prompted by this crap:

This is malware. Always click Decline.

This is the primary reason why the Windows software ecosystem sucks. Searching for straightforward solutions lands you on the worst snake oil and sleaze bag sites. They embed their garbage in “next next” dialogue hell.

Always pay attention when installing software because often, a Windows software installer includes optional installs, such as this MyStart toolbar which is essentially a Trojan horse.

PS: The K-Lite Codec pack did not solve my problem. I uninstalled and opted for QuickTime alternative instead. 

Forbidden File Names on Windows 10

When I switched from Linux/OSX  to Windows 10, I encountered problems with “disappearing files.”

First time it happened:

I have a web application with a directory  named “aux.” When copying over the project from Linux to Windows this folder and its contents silently disappear.

Second time it happened:

Pulling the textmate.ruby bundle from GitHub:

$ git clone git@github.com:textmate/ruby.tmbundle.git
Cloning into 'ruby.tmbundle'...
remote: Counting objects: 4012, done.
remote: Total 4012 (delta 0), reused 0 (delta 0), pack-reused 4012
Receiving objects: 100% (4012/4012), 1001.74 KiB | 0 bytes/s, done.
Resolving deltas: 100% (2061/2061), done.
Checking connectivity... done.
error: unable to create file Commands/@variable ||= memoized.tmCommand (Invalid argument)
error: unable to create file Commands/Enclose in * (RDoc comments).tmCommand (Invalid argument)
error: unable to create file Macros/class .. < DelegateClass .. initialize .. end (class).plist (Invalid argument)
error: unable to create file Macros/each_char { |chr| .. } (eac).plist (Invalid argument)
error: unable to create file Macros/each_cons(..) { |group| .. } (eac).plist (Invalid argument)
error: unable to create file Macros/each_slice(..) { |group| .. } (eas).plist (Invalid argument)
// ... snip ...

Argh…

List of reserved file names on Windows 10:

The following are (case insensitive) reserved names which cannot be assigned to a directory or file in Windows 10 :

  • CON
  • PRN
  • AUX
  • NUL
  • COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
  • LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9

List of invalid file characters on Windows 10:

The following are special characters which cannot be assigned to a directory or file in Windows 10 :

  • < (less than)
  • > (greater than)
  • : (colon)
  • (double quote)
  • / (forward slash)
  • \ (backslash)
  • | (vertical bar or pipe)
  • ? (question mark)
  • * (asterisk)

Sources:

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx

Get cwRsync Working With Vagrant On Windows 10

Getting cwRsync to work with Vagrant on Windows 10 is a pain.

This tutorial is for people who have:

Reading comprehension 101:

cwRsync is a standalone version of rsync for Windows that doesn’t require Cygwin to be installed. I don’t have Cygwin installed because Git For Windows includes Git Bash and this is “good enough.” With a regular standalone cwRsync installation Cygwin will never be in the PATH and Vagrant will never add the required /cygdrive prefix.

Howto fix:

Add `C:\Program Files (x86)\cwRsync` (or wherever you installed) to your path. To avoid problems make sure this string is placed before `C:\Program Files\Git\cmd` and/or `C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin`

Add cwRsync to your path.
Add “C:\Program Files (x86)\cwRsync” to your path.

Add the following system variable: `CYGWIN = nodosfilewarning`

CYGWIN = nodosfilewarning
Add “CYGWIN = nodosfilewarning” as a system variable.

Edit (hack!)`C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.4\plugins\synced_folders\rsync\helper.rb`

Change line ~43 from:

hostpath = Vagrant::Util::Platform.cygwin_path(hostpath)

To:

hostpath = "/cygdrive" + Vagrant::Util::Platform.cygwin_path(hostpath)
Edit rsync\helper.rb
Edit Vagrant’s rsync\helper.rb file

Restart your shells to apply changes. Fiddle with your Vagrantfile. Tada!

Troubleshooting:

Git for Windows is based on MinGw. cwRsync is based on Cygwin. You cannot run Vagrant & cwRsync from Git Bash because cwRsync includes it’s own incompatible SSH binary. If you try you will get the following error:

rsync error: error in rsync protocol data stream (code 12) at io.c(226) [Receive r=3.1.0]

Instead, when launching Vagrant use Microsoft PowerShell.

Sources:

[1] http://auxmem.com/2010/03/17/how-to-squelch-the-cygwin-dos-path-warning/
[2] https://github.com/mitchellh/vagrant/issues/3230
[3] https://github.com/mitchellh/vagrant/issues/4586

Top 3 LAMP Developer Frustrations Switching From Linux/OSX to Windows 10

Two weeks ago I drank the cool-aid and switched my laptop to Windows 10.

I haven’t used Windows on my personal computer for twelve years. This is a big deal for me. I ran Ubuntu and OSX before that.

As a LAMP developer the switch has been painful. Here are my top 3 pain points:

SSH:

PuTTY , an app released in 1998, is still the best option for SSH on Windows. Actually, KiTTY is but you need to run PuTTy tools like Pageant or Key Generator do anything useful. I spend too much time painstakingly converting perfectly good SSH keys into strange PPK files. I squint click through a tree of options to do the most basic of tasks like login without password.

A better SSH for Windows might be GIT-SCM. When you install this you get Git Bash which has SSH. To be honest the Git Bash terminal is open 100% of the time I am sitting at my desktop. An unfortunate island of isolation that my other Windows tools are constantly fighting against…

SSH toolkits are BSD licensed. The fact that Microsoft hasn’t included SSH in Powershell by now is simply unacceptable. If Microsoft seriously wants web developers checking out Windows 10 then this is the biggest road block or, more to the point, this is the road that will lead me back to Linux when I can’t take it anymore.

Configuration Dialogues:

As a developer my monitor resolution is 1920 x 1080 (or higher!). In Windows 10 no matter where I start I’m pretty much guaranteed that three clicks in I time travel back to Windows NT. Tiny, ugly, anti-responsive dialogues that require toothpick like clicking to change every day web developer configurations. Come on Microsoft, even Linux isn’t this ugly in 2015!

From Windows 10, To Windows 7, To Windows NT. In three clicks!
From Windows 10, to Windows 7, to Windows NT. In three clicks!

Hyper-V:

Hyper-V support in Vagrant! This is actually the main reason I switched. Hyper-V is Microsoft’s competition to Virtualbox. Conclusion? Don’t believe the hype.

I spent days trying to get Vagrant to provision a LAMP stack using Hyper-V. I even spent $159.82 CAD to upgrade from Windows 10 Home to Pro so that I could activate this feature.

Hours wasted. I failed. Or more specifically I succeeded and it sucked for web development as I know it. I went back to Virtualbox. On the plus side at least SMB shares work (with caveats!).

Here is a list of URLs for anyone who dares try this themselves. Maybe you’ll have better luck than me?

Hello World 10

I’m still a LAMP developer at heart, with all the Stockholm Syndrome that comes from making a living with PHP, but Microsoft is changing.

Most notably  C# is now open source. In 2014 I worked a job where I coded C# and, well, I liked it. For desktop, for tablet, for command line, I actually think the .NET ecosystem is pretty great. For web? For backend? Absolutely not. That said, all things considered, I decided I could no longer simply put my fingers in my ears singing “Na na na na I can’t hear you!” 

Yes, I understand the distinction between Libre and Open and at this point in my life I am willing to make the trade off. I think Microsoft is setting up for the next decade and by me switching my laptop I am making a bet.

For this to pay off Microsoft needs to accept that .NET is not the dominant web development platform and attract those developers anyways. If they make life easier for the eclectic ecosystem that is the *NIX backend, then mobile and desktop will follow.

But most of all, SSH out-of-the-box for fux sake!