Tuesday, June 23, 2015

PhpStorm settings

I like to use the following custom PhpStorm settings:

Global IDE Settings

  • Appearance & Behavior
    • System Settings
      - DONT reopen last project on startup
      - DONT confirm application exit
      - Open project in new window
  • Editor
    • Colors & Fonts
      • Font: Consolas 22pt (I have a 4K high DPI monitor)
    • Code Style
      Line separator: Unix
      Right margin (columns): 80
    • File Encodings
      Project Encoding: UTF-8
  • Languages & Frameworks
    • PHP
      PHP Executable: C:\dev\php\php.exe
      • Composer
        Path to composer.phar: C:\dev\bin\composer.phar

Per-Project Settings

For every project, it's also necessary to set up PHPUnit.

Note that I configure PHPUnit as a composer dependency, so each project has its own local copy and version of PHPUnit.

This removes the requirement that PHPUnit be installed on the system externally, but it also means that we have to configure PhpStorm when we first open the project.  That is the lesser of 2 evils IMO so that's what I'm doing.

Project Settings

  • Languages & Frameworks
    • PHP
      • PHPUnit
        Use custom autoloader
        Path to script: (current_dir)/vendor/autoload.php
        Default config file: (current_dir)/phpunit.xml.dist
        Default bootstrap file: (current_dir)/test/bootstrap.php

 Run > Edit Configurations

  • Defaults
    • PHPUnit
      • Test scope: Defined in the configuration file
      • Use alternative configuration file: (current_dir)/phpunit.xml.dist
      • Custom working directory: (current_dir)/test

HowTo: Set up Win 10 as a Unix-like Dev Workstation

I recently installed a brand new Win 10 preview and set up my Unix-like dev environment on it.

This post basically ties together some of the other posts I've made in the past.  I'll keep this updated as I add steps when I install stuff again in the future.

When you're done with this, you'll have a MinTTY window (like xterm) that looks and acts cool.  Here is mine:




Setup Procedure:

  1. Install MinGW-W64+MSYS
  2. Reboot (May or may not be needed; I couldn't get MsysGit to install without rebooting, but I have Win 10 Preview which is probably buggy).
  3. Install PuTTY/Pageant on Win 10
    1. Configure MinGW-W64+MSYS to use PuTTY Plink/Pageant
  4. Install MsysGit for source control
  5. Install SourceTree
  6. DISABLE anti-virus from running in your source code directories, otherwise when you change branches, it's slower than molasses as your AV is scanning every one of your 1000s of "changed" files every time you switch.
    1. My AV has a way to add directory exceptions, if yours doesn't, you should upgrade
  7. Set up home directory dotfiles
    1. See this Github repo which contains my files.  I recommend you copy these to your homedir and then make whatever changes you want.

Make Git play nicely with Unix/Mac


We MUST ensure that Git does NOT try to auto-convert line endings.

Auto-fuck-up-line-endings has all kinds of horrible side effects, and it is totally unnecessary as long as you use modern text editors that don't care what the line endings of a file are.  (JetBrains has awesome IDEs, pay for a good one and call it a day).

In a MinTTY window run these commands:

git config --global core.autocrlf false
git config --global core.ignorecase false

The second command, core.ignorecase = false, means that if we rename a file from "foo" to "FOO", we will commit that name change to Git.  Usually Windows ignores that since its file system is case-insensitive, but that is the exception rather than the rule, as far as OSes go.

PHP Development Setup


  1. Install PHP
    1. Install PHP YAML extension
  2. Install PhpStorm
    1. I installed it to D:\Apps\PhpStorm
    2. Customize PhpStorm default settings

Python Development Setup


  1. Install Python 2.7.x
    1. Install to C:\dev\python
    2. MANUALLY add to SYSTEM path, if the Installer didn't do it:
      1. C:\dev\python
      2. C:\dev\python\Scripts
    3. Install PyYAML
    4. Install Jinja2
    5. Install setuptools
  2. [optional] Install PyCharm GUI
    1. I installed it to D:\Apps\PyCharm

Google Cloud Setup


  1. Install Google Cloud SDK via Windows Installer
    1. Install to C:\dev\gcloud
    2. Start the SDK shell
      1. Run: gcloud auth login

Edits


12-May-2016 - Install PuTTY before msysGit

10-May-2016 - Updated Python install instructions.

06-May-2016 - Added post specific to SourceTree.  Added pertinent homedir dotfiles to a public Github repo so you can copy them.

Install PuTTY\Pageant on Win 10

Install PuTTY/Pageant on Win 10


[Optional] Copy existing .ssh directory from Mac or Unix.


If you already have an .ssh directory from Mac or Unix (or another Windows machine), then copy it to your home directory now, if you haven't already.

You should include your SSH keys, configs, etc.

It's a pain getting Windows to name a directory ".ssh" with a leading dot, but if you have installed MinTTY already then you can just open a MinTTY terminal and rename it to ".ssh" which is required before we move forward.

Install PuTTY


Download the PuTTY installer from the official (if strangely 1995 looking) site

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Install it into C:\tools\PuTTY

Set up Pageant to run at Startup


Open Windows Explorer and navigate to
%appdata%\Microsoft\Windows\Start Menu\Programs\Startup

Create a new Shortcut:

  • Target: "C:\tools\PuTTY\pageant.exe" id_rsa.ppk second.ppk third.ppk
  • Start In: "%HOMEPATH%\.ssh"

Notice:

  • You can pre-load as many keys as you want.
    • In the example above, id_rsa.ppk is the primary key, and it also loads 2 more keys: second.ppk and third.ppk.
    • Remove second.ppk and third.ppk from the Target line, and replace them with whatever other keys you want loaded (if any).

Make sure it works by executing the shortcut.  You should see Pageant start, and it should prompt you to enter the password for you SSH key.

Edits


06.May.16 - Changed the install location to C:\tools which is more reasonable to use in the path if so desired.

Install MsysGit on Win 10 (for Unix Developers)

Download Msysgit.

Install to C:\dev\git

Keep all the default installation options

Choose "Use Git from the Windows Command Prompt"


Have Git use Plink from PuTTY



Make sure Windows does NOT mess with line endings.  Leave them alone.


The reason for this, is sometimes we compute file hashes, like PHP Composer for example, and if there are \r characters in the file then Windows computes the hashes differently than Unix, which is stupid.

For this to work, you must use a decent text editor that understands that there are many ways to end a line, not just \n\r.

Voila!  You now have Git, and it is configured correctly for cross-platform development.

Updates


10-May-16: Updated line endings option - NEVER automatically change line endings!  This way you get full control over line endings from your editor.  So if your line endings are messed up, it's your own fault, and you can easily fix it.

Monday, May 11, 2015

Installing MinGW-W64 + MSYS on Win 10 x64 (or Win 8.1 or Win 7)

(This is a repost of something I did last year, I accidentally deleted it from Blogger).

Update:  I installed this on Windows 10, and updated the procedure based on experience since the original post.

I'm a Unix/Mac guy.  I use Windows for gaming but I've never really developed on it before, because why.

When I did transition to windows relatively recently for development, I used cygwin, which worked pretty well and was Unix-like enough for me to be OK with it.  However I can't make Windows apps in cygwin, and now needing to do some prototyping for cross-platform Windows tools, I need MSYS instead of Cygwin.

After a few attempts at doing this, reading various blogs that all say to do it different ways, and not really knowing which pre-compiled code I can trust versus not trust, here is a methodology I'm happy with and generally feel is relatively safe to install.

After following this procedure:

  • MinGW (64-bit) will be installed to C:\MinGW-W64
  • MSYS (32-bit) will be installed to C:\msys

    • MSYS will use your Windows Home directory as its own.

  • You'll have a "MinTTY" shortcut to start a mintty terminal running a bash shell
  • (Windows will now feel very similar to Mac/Linux)

Download/install MinGW-W64

Go to http://sourceforge.net/projects/mingw-w64/

Download the latest installer and run it.  Choose these options:

Version: (choose the highest)
Architecture: x86_64
Threads: win32
Exceptions: seh
Build revision: (choose the highest)

Install path: C:\MinGW-W64

Note here we're using win32 threads, NOT posix threads.  On Windows, win32 threads apparently run much faster than posix.  This means that when you compile things from MinGW you must ensure that you choose the win32 thread options or you'll likely have problems compiling.

NOTE: If it fails to install (sometimes it cannot download the toolchain) then that's fine, just ignore it for now and move on to below, updating the toolchain.

Download/install MSYS

Go to http://sourceforge.net/projects/mingwbuilds/files/external-binary-packages

Download the latest revision.

Unzip to C:\

This creates the location C:\msys

Create a directory for mingw

Using Windows Explorer, navigate to C:\msys and create a new folder named mingw.

The full path of the new folder you created will be C:\msys\mingw

Don't put anything in this folder.  Leave it intentionally empty.

Mount /mingw for MSYS

Edit C:\msys\etc\fstab

It should contain (at the very least) these lines:

#Win32_Path           Mount_Point
C:/MinGW-W64/mingw64  /mingw


I also recommend that you mount your Windows homedir to /home/yourname, so that your total fstab will look like this:

#Win32_Path           Mount_Point
C:/MinGW-W64/mingw64  /mingw
C:/Users              /home

Make sure there is an empty line at the end of the file.

* If you opened any msys consoles, close them now and reopen them.

Download/install YASM


Download the latest "Win64.exe" file, for example something like http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe

Move the downloaded yasm-1.3.0-win64.exe to C:\msys\bin\yasm.exe

Configure a decent Terminal

You now have a standard Windows cmd terminal (aka Shit).  To get a nice Unix-like terminal we'll install Git for Windows which has a nice MinTTY terminal that acts similar to xterm.

Continue on in HowTo: Set up Win 10 as a Unix-like Dev Workstation until you get PuTTY/Pageant set up and Git.

Once you have Git installed you will have Git Bash, which uses MinTTY, and is a pretty nice terminal that works well with msys.

What next?

Now you have a bare-bones terminal.

You need to set up your %HOMEPATH%\.bashrc and related dotfiles to really start customizing it to look and feel the way you want.

Check out my Github home dir to see an example of how I set mine up.

References

qt-project.org has nice info about MinGW and MinGW-W64, including info RE threading and exception models, pros/cons of each, etc.

EDITS

14.Aug.16 - Removed instructions for installing old school mintty; I now suggest using Git for Windows since their mintty is much newer/nicer.

27.Jul.16 - Fixed /etc/fstab mount point.  Added empty C:\msys\mingw folder so that /mingw is visible to filesystem search utilities.

06.May.16 - Updated based on new MinGW-W64 version. No longer need to manually create MSYS shortcut.

23.Jun.15 - Removed Win 8.1 specific stuff.  Updated instructions per new MinGW-W64 v5.1.0.  Confirmed that updating the toolchain is not necessary, at least for v5.1.0 and removed that part of the instructions. Moved msys to C:\msys

11.May-15 - Updated for Windows 10. Added Windows home directory mount. Moved MSYS directory inside MinGW-W64 as we no longer need easy access to it with the Windows home diretory mounted.

17.Sep.14 - Added some clarifications. Added mingw64 toolchain update.  Added references.

Friday, March 13, 2015

Install php-yaml on Windows 8.1

Install php-yaml on Win 10 (or 8.1)

Related to my previous post Install PHP 5.6 on Win 8.1 x64, I needed to work with YAML from PHP.  The instructions for how to do this are confusing, at best.

Simplified instructions:


  1. Go to http://pecl.php.net/package/yaml
  2. Download the zip file for the latest version (as of the time of writing this, 1.2,0).  There is a little Windows Icon and the word DLL is linked to the zip.
  3. Download the 5.6 Thread Safe (TS) x86 version
    1. Thread Safe
    2. x86 (32-bit), NOT the x64 (64-bit), since we're running 32-bit PHP
  4. Copy yaml.dll to C:/dev/php (or wherever you installed PHP)
  5. Copy php_yaml.dll to C:/dev/php/ext (or the ext directory under your PHP install location)
  6. Edit C:/dev/php/php.ini
    1. Add this line:
      extension=C:/dev/php/ext/php_yaml.dll
  7. Confirm that it works:
    1. php --re yaml