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.