Tag: Windows

The Windows Subsystem for Linux (WSL) seems to be mature enough now to give it another shot. Copy and paste, and other simple annoyances that kept me away before are working better. Also, I’ve been reading that nvm (Node Version Manager) works now, so here goes.

As a precursor, note that my system is Windows 10 Professional (version 1709, build 16299.309) and is fully up to date with WSL enabled and Ubuntu installed from the Windows Store.

Ubuntu Update

If it has been a while, first thing I like to do with the Ubuntu app is update and upgrade the ubuntu Linux packages. First update the package database with apt-get update, then upgrade with apt-get upgrade or apt-get dist-upgrade. I prefer apt-get dist-upgrade since it will remove obsolete packages and add new ones as needed.

Oh My Zsh

Oh My Zsh will spruce up your Ubuntu bash and add some additional functionality. Here is a screenshot of my Ubuntu app to illustrate.

Then load as a plugin in your .zshrc profile. Note that plugins need to be added before oh-my-zsh.sh is sourced. For example, here is a snippet from my .zshrc profile.

.zshrc

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
plugins+=(zsh-nvm)
source $ZSH/oh-my-zsh.sh

After updating your .zshrc profile to load the nvm plugin, close and re-open the Ubuntu app and to install nvm when the plugin is loaded for the first time.

One the install has completed, you can verify by running nvm which should output the nvm --help contents.

Install the latest LTS version of Node.js which at the time of this writing is version 8.11.1

PowerShell modules can enhance functionality and the user interface. In this example, the profile is updated to use git over an SSH connection, readline settings for a bash like experience, custom color output and a custom prompt.

PowerShell Profile

If there is not an existing profile for the current logged in user, create one with the New-Item cmdlet. To check if a profile exists, use Test-Path $profile. $profile is an environmental variable for the path to the CurrentUserCurrentHost profile.

Test-Path $profile

If the test returns false, use the New-Item cmdlet to create the profile script. For example:

New-Item $profile -ItemType File -Force

There should now be a WindowsPowerShell\Microsoft.PowerShell_profile.ps1 file in the Documents folder.

PowerShell screenshot with the updated profile loaded using the ls command alias to list files.

Custom Prompt

Add these two functions to the top of the Microsoft.PowerShell_profile.ps1 script. The first function checks to see if PowerShell is running with Administrator privileges. This check is used to add (Elevated) to the prompt as needed. The second function, aptly named prompt modifies it’s output.

SSH Agent

We will use Mark Embling’s ssh-agent-utils Powershell script with functions for starting and managing ssh-agent. Download the ssh-agent-utils.ps1 Gist and place the script into the WindowsPowerShell folder for current logged in user, for example, %UserProfile%\Documents\WindowsPowerShell. In this example, both Microsoft.PowerShell_profile.ps1 and ssh-agent-utils.ps1 should be in the same WindowsPowerShell folder.

Install these modules into the default PSModulePath for the current logged in user, for example, %UserProfile%\Documents\WindowsPowerShell\Modules. PowerShellGet is required, which is included in Windows 10 and WMF 5.

Resources

PowerShell modules can enhance functionality and the user interface. In this example, the profile is updated to use git over an SSH connection, readline settings for a bash like experience, custom color output and a custom prompt.

{script path} cannot be loaded.
The file {script path} is not digitally signed.
You cannot run this script on the current system.
For more information about running scripts and setting execution policy,
see about_Execution_Policies at
http://go.microsoft.com/fwlink/?LinkID=135170.

You can set a Bypass execution policy for the current session.

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Menu Example

This PowerShell script contains a menu to execute various tasks using functions.

Choose A Download Site: http://mirrors.xmission.comThis mirror was reliable for me. They should generally all be up to date. It is recommended that you select a mirror site that is closest to you. Visit the Cygwin Mirror Sites page for more information.

Select Packages:

curl: Muti-protocol file transfer tool

fzf-zsh: fzf key bindings for Z shell

fzf-zsh-completion: fzf completion for Z shell

git: Distributed version control system

gitk: Git repository browser

zsh: The Z-Shell

Configure Cygwin Home Directory

Make your Cygwin home directory the same as your Windows User profile.

Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc
Copying your current PATH and adding it to the end of ~/.zshrc for you.
I can't change your shell automatically because this system does not have chsh.
Please manually change your default shell to zsh!

Mintty Configuration

This section documents some additional personalization preferences. Access the options by selecting the Cygwin application icon in the Title bar. For Looks, I have medium transparency selected.

Options – Looks

For text, I have the Fira Code fonts installed on my system so have elected to use them and since my display is UHD, I am using the retina version. I have also set the font smoothing to full which is equivalent to subpixel anti-aliasing (“ClearType”).

Options – Text

Lastly, I wanted to add some spacing between the window borders and command text. I discovered that this could be done by editing the mintty configuration file in my home directory. I added the following line to the file, Padding=16. The entire configuration file is shown below.

This post documents installing PHP 7, PHP Manager and Laravel 5.3 on Internet Information Services (IIS) Manager version 10 which ships with Windows 10 Pro. This Laravel Installation will also be configured to connect to a SQLite database.

Internet Information Services (IIS) Manager

IIS needs to be installed, open the Windows Features dialog to check the installation. One way to do this is by selecting the start button and type Windows Features to bring up a list where “Turn Windows features on or off” can be selected. Another way to get to this Control Panel app is Windows + R key combination and run appwiz.cpl. Turn Windows features on or off link should be in the upper left panel.

Windows Features

Notice that under .NET Framework 3.5 that both Windows Communication Foundation features are enabled. This may be needed in order for a successful install of PHP Manager. Installation of PHP Manager for IIS requires .NET 3.5 to work properly.

PHP and PHP Manager

Install PHP 7 for Windows using the Microsoft Web Platform Installer. It’s an easy way to get both PHP and the PHP Manager installed and takes some of the guess work out of getting PHP up and running on Windows and IIS.

If PHP Manager Fails to install after confirming that .NET 3.5 is installed and enabled, this is likely due to the installer throwing an error when checking the IIS version. Change the W3SVC MajorVersion value to 7 (decimal) in the registry. After the install is completed, change the value back to 10. More info is available at the PHP Manager – Refuses to install for WTP10 view issue page.

* YMMV, I am not responsible if you hose your system when editing the registry.

PHP Extensions

In the Internet Information Services (IIS) Manager, Open PHP Manager and select the Enable or disable an extension link. Ensure that the extensions needed for Laravel are enabled. If you want to be able to connect to a SQLite database, enable the php_sqlite3.dll PHP extension. The figure below shows the PHP extensions I have enabled for a working Laravel 5 installation.

PHP Manager – PHP Extensions

Composer for Windows

Download and run Composer-Setup.exe Windows Installer. The installer will download Composer and set up the PATH environment variable.

Using the Windows Command Prompt, make sure Composer for Windows is installed by running the composer –version command.

composer --version

Git for Windows

Git for Windows is needed so Composer for Windows can download packages. During the installation process, Adjusting your PATH environment, make sure the option, Use Git from the Windows Command Prompt is enabled.

Using the Windows Command Prompt, make sure Git for Windows is installed by running the git –version command.

git --version

Create Laravel Project

Bring up the Adminstrator Command Prompt. One way to do this is by selecting the start button and type command to bring up a list where “Command Prompt” can be selected. Right click on Command Prompt and select Run as administrator
.

cd c:/intepub
composer create-project laravel/laravel laravel "5.3.*"

Add Website

Open Internet Information Services (IIS) Manager. Right click on the server and select Add Website. Fill out the form as follows:
Site name: Laravel
Application pool: DefaultAppPool
Physical path: C:\inetpub\laravel\public
Host name: laravel.win

Select “Test Settings” and then “OK” if successful.

IIS – Add Website

Hosts Mapping

Since the Host name laravel.win was entered for the website, the hosts file needs to be updated. Open Notepad as an administrator. One way to do this is by selecting the start button and type Notepad to bring up a list where it can be selected. Right click on Notepad and select Run as administrator.

Select File | Open, or Ctrl + O and change the File type from Text Documents (*.txt) to All Files (*.*). Browse to C:\Windows\System32\drivers\etc and select the hosts file. Add an entry to map localhost to laravel.win as follows.

hosts

127.0.0.1 localhost
127.0.0.1 laravel.win

Laravel Storage Permissions

In File Explorer, right click on the storage folder in C:\inetpub\laravel and select Properties. Under the Security tab, grant full control of the storage folder to IUSR as shown in the figure below.

Permissions for storage

Laravel web.config

Since IIS does not have an .htaccess file like Apache, create a web.config file in C:\inetpub\laravel\public as follows. *

This post documents how to install Laravel locally using XAMPP. When you are developing with Laravel on an older computer or one with limited resources, using XAMPP for your local PHP and MySQL development server works well on Windows.

Laravel PHP Requirements

This table shows the minimum PHP version requirements for the latest versions of Laravel.

Laravel

PHP

5.3

5.6.4

5.1, 5.2

5.5.9

5.0 *

5.4

* PHP 7 not supported in this version

Head over to the Apache Freinds site to download the version of XAMPP that meets the minimum PHP requirements for the version of Laravel you are supporting. If you are developing in Laravel 5.2 currently and also want to be able to support Laravel 5.3, get the XAMPP version that includes PHP 7.

For Windows, I have xampp installed at the root directory on C:\ drive. here is the virtual hosts configuration I am using for Laravel. More information for setting up XAMPP on Windows.

hosts

127.0.0.1 laravel.dev

Install Laravel

This example will install laravel 5.2 into C:/xampp/htdocs/laravel using Composer. Use the create-project command and the laravel/laravel package name followed by the directory to create the project in. The optional third argument is for a version number.

Finally, I can use the Windows Command Prompt like Unix thanks to Clink. This CMD.exe extension adds the powerful Unix Bash-style
functionality of the GNU Readline library to the Windows command line. If you are a Microsoft PowerShell user, there is also a PSReadLine module available
for it. My favorite bash shell for Windows is Cygwin + ZSH + Oh My ZSH.

Git for Windows

Cygwin + ZSH + Oh My ZSH

This is also a great Windows bash shell solution to give you the power of Unix. After launching Cygwin setup and installing git and zsh, install Oh My ZSH. For more info, see my Cygwin Oh My ZSH Recipe.

Microsoft PowerShell

Another command line option is available when using the Microsoft PowerShell task automation and configuration management framework from Microsoft. PowerShell provides access to WMI, COM and the .NET object model in an interactive and scriptable command line environment. Learning PowerShell is made easier by using its console-based help, like man pages in Unix shells, with the Get-Help Cmdlet. Help contents can be downloaded using the Update-Help Cmdlet. Context help is available with the -online switch to Get-Help.

Brackets is a a modern, open source text editor that understands web design. TIP: if you are fairly new to markdown and/or would like a live preview while you edit, checkout this Markdown Preview plugin for Brackets.

Sublime Text is a fast, stable editor with a huge number of features and plugins termed packages.

Visual Studio Code is a free code editor from Microsoft and is available for Linux, Mac OSX, and Windows. This editor has a growing community and new features with each release. One feature I recently discovered is the live markdown preview, Ctrl+Shift+V.

Configuration Considerations

If you’re running under Windows and work with Git, create and edit shell scripts, etc., you may want to consider setting the default line endings to Unix instead of Windows.

Line Endings

Windows

CR LF

Unix

LF

The Windows version of Sublime Text 3 is set to use Windows line endings by default. You can set Unix as the default in Sublime Text 3 as follows:

From the Menu, select Preferences (alt + n)

Select Settings – User

Add the following to the Preferences.sublime-settings file *

{
"default_line_ending": "unix"
}

* If there are pre-existing settings in the Preferences.sublime-settings file, the curly braces are not needed since they already surround the settings. The Sublime Text settings files are in json format.

TIP: Convert line endings from Windows to Unix with the dos2unix command using Cygwin, a Unix like command-line interface for Windows.

Line Ending Plugins

Sublime Text comes with all the tools for handling line endings built in. What about the others?

Atom – As of version 1.0.8 you can change the default line endings for new files. Select File | Settings | Packages | Core Packages | line-ending-selector. Select Settings, Default line ending setting. You can also convert line endings for an open file selecting LF or CRLF at the bottom right hand corner status area.

Brackets – An extension to convert line endings may be needed. The brackets-newline extension worked for me. The default line endings adjusts to the OS it’s running on. There doesn’t seem to be a way to set default line endings for new files.

Visual Studio Code – Use an .editorconfig file and the respective EditorConfig for VS Code extension. Line endings can be converted by selecting LF or CRLF at the bottom right hand corner status area. Like Brackets, the default line endings adjusts to the OS it’s running on and there doesn’t seem to be a way to set default line endings in the core settings.

Sublime Text

Settings

For those of you that are interested and for my own records, my Sublime Text settings file. The Fira Code fonts are a great addition to a developer work station.

How to install the build tools

Go to the same place that has the RubyInstaller for Windows, http://rubyinstaller.org and select Downloads. Download the Development Kit (build tools) that corresponds with your version of Ruby. If you need to install Ruby (required), it is recommended that you use the Ruby 1.9.3 installers. I noticed that a newer version of the Ruby 1.9.3 installers were available, might as well get the updates. To summarize, here are the two packages I downloaded for my Windows 8.1 machine:

Test the DevKit install

C:\RubyDevKit>bash
bash-3.1$ gcc --version
gcc.exe (tdm-1) 4.5.2
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bash-3.1$ exit
exit

›After twenty plus years using Microsoft and Windows dating back to DOS 6.1 and Windows 3.1, I am learning how to make the switch to OS X. One thing I had to get used to was how to bring up context menus that I would always invoke by right clicking an object in Windows. To right click in OS X on the MacBook Pro, use the Multi-Touch trackpad and tap with two fingers at once. Another was the Delete key functions the same as backspace on a PC. No Home and End keys on the Mac took some getting used to as well, command and cursor key combo’s did the trick. A majority of shortcuts can be replicated by simply replacing what was done with the Ctrl key on a PC with the command key in OS X.

Windows and OS X Keyboard Comparison

Windows/PC Keyboard – Sony VAIO FW290MacBook Pro Keyboard

Here is a table of my frequently used keyboard shortcuts for each OS.

OS X

Windows

Cut

⌘ command+X

Ctrl+X

Copy

⌘ command+C

Ctrl+C

Cycle Tabs

control+tab

Ctrl+Tab

Cycle Windows

⌘ command+tab

Alt+Tab

Cycle WindowsCurrent App

⌘ command+ ~

End of Document

⌘ command+↓

Ctrl+End

End of Line

⌘ command+→or: control+E

Endor: Fn+→

Force QuitApplications

⌘ command+option+esc

Reload Webpage

⌘ command+R

Ctrl+Ror: F5

Start of Document

⌘ command+↑

Ctrl+Home

Start of Line

⌘ command+←or: control+A

Homeor: Fn+←

Page Down

fn+↓

Page Down

Page Up

fn+↑

Page Up

Paste

⌘ command+V

Ctrl+V

Select Words

shift+option+→

Shift+Ctrl+→

Show Desktop

fn+F11

Win+D

Spotlight / Run

⌘ command+space

Win+R

Webkit Dev Tools

⌘ command+option+I

Ctrl+Shift+I

Lock Screen

After enabling the lock screen in System Preferences > Security & Privacy by checking require password after sleep or screensaver begins …

For external keyboards with an Eject key use control + shift + eject

For keyboards without an Eject key, like the MacBook Air and MacBook Pro Retina, use control + shift + power

Screen Capture, OS X

Command (⌘)-Shift-3

Take a picture of part of the screen

Command (⌘)-Shift-4, and then drag the crosshair pointer to select the area. Continue to press the mouse button, release the keys, and then press Shift, Option, or the Space bar while you drag to resize the selection area. When you are ready to take a picture, release the mouse button.

To cancel, press Escape before you release the mouse button.

Terminal

base64 files

To base64 encode a file. Typically a font or image to inline into a CSS file. Add this function into your .bash_profile.

Compress (ZIP) Files

# to create a zip archive of the entire folder named myproject into myproject.zip
# and exclude .DS_Store, node_modules and .git directory
# cd to the directory that has the myproject folder, then
zip -r myproject.zip myproject --exclude "*.DS_Store" --exclude "*.git*" --exclude "*node_modules*"

Command History

Don't search history by grepping ~/.bash_history, or repeatedly hitting the up arrow, instead use control+R - press enter to immediately run the command.

Print Working Directory

Shutdown / Restart

SSH

Ctrl + D to logout of SSH session

Symbolic Links - symlinks

Symbolic link files contain path metadata of the target file or directory. If you move the target file, the symlink will break. Note that ~/ will target the current users home directory. This example creates a symlink to the Photos directory in the Downloads directory.

# /target /symlink
ln -s ~/Dropbox/Photos ~/Downloads

Web Server

Start a simple web server at the root of any folder by navigating to the folder. This example will create a web server with a base URL http://localhost:8000

python -m SimpleHTTPServer 8000

If you want to use port 80, simply leave off the port number that follows the SimpleHTTPServer command. Ctrl+C to stop the server

Other Useful OS X Tips

Activity Monitor

Use Spotlight (command + spacebar) and start typing Activity Monitor, select it to monitor what is going on with your system.

Finding Files

While in Finder, select Edit > Find (command + F). Then click the plus button to the right of the search window to add a filter. Select "other" in the first drop-down menu and select "System files". Now select "System Files" which is now an available option in the first drop-down. Select "are included" in the second drop-down and enter your search term.

I installed Windows 8 on my 2009 SONY VAIO FW series laptop today. Here are a few keyboard shortcuts I found useful.

Windows Key + C – Charms

Windows Key + D – Desktop

Windows Key + F – Search Files

Windows Key + I – Settings

Windows Key + K – Devices

Windows Key + P – Projector options

Windows Key + Q – Search Applications

Windows Key + R – Run

Windows Key + X – Administrator tools

Windows Key + Enter – Narrator

Smart Snap

Windows Key + Right or Left Arrow
Moves the open window to the left or right half of the screen.

Additionally, if you are on the metro screen, and there is not a search input shown, just start typing and one will appear with your query. Tapping the Windows key will cycle you through open screens as well. The ever faithful Alt + F4 (close) and Alt + Tab (cycle windows/apps) shortcuts are indispensable… Ctrl + Tab is handy as well.