One place for hosting & domains

      How To Install the Windows Subsystem for Linux 2 on Microsoft Windows 10


      Introduction

      The Windows Subsystem for Linux 2, WSL 2 or WSL for short, is a tool on Microsoft Windows 10 that allows developers to run a Linux environment directly on Windows without any modifications, secondary Virtual Machine software, or dual-boot setups. The WSL natively integrates with most applications on your workstation, allowing for a Linux-like development experience on Windows. The WSL accomplishes this by using Microsoft’s built in virtualization software called Hyper-V to run.

      In this tutorial you’ll enable the WSL, install Ubuntu 20.04 onto your workstation using the WSL, and install Microsoft’s new Windows Command Line to access your Ubuntu 20.04 installation. This will provide you with a Linux programming environment that is native to Windows.

      Prerequisites

      In order to follow along with this guide, you’ll need:

      • Personal Computer with Windows 10 installed: The Windows Subsystem for
        Linux 2 requires Windows 10 version 1903 or higher with build 18362 or higher. For ARM64 systems, version 2004 or higher with build 19041 is required. Builds lower than this will not support the WSL 2.

      Warning: If you are installing the WSL on a virtual machine you will need to expose CPU virtualizations flags to the virtual machine. For example, if you are installing the WSL on a virtualized Windows 10 that is running in Hyper-V named MyWSL you will need to run the following command on the virtualization host, not the virtual machine. This is a Windows command so you will need an elevated PowerShell prompt to do this. Replace MyWSL with the name of your VM in Hyper-V:

      • Set-VMProcessor -VMName MyWSL -ExposeVirtualizationExtensions $true

      If you are not installing the WSL on a virtual machine, you can skip this warning entirely.

      Step 1 — Enabling Windows Services for the WSL

      The first thing you need to do is enable specific Windows services so that you can run the WSL. These services come with Windows but are turned off by default until you decide you need them. Open up the Start menu and search for PowerShell. You’ll need to right click on PowerShell and click on Run as Administrator.

      Open Windows PowerShell as an administrator

      Once you’ve done this, a PowerShell window will open. You’ll use the Windows Deployment Image Servicing and Management tool to enable optional Windows features that are disabled by default. Run the following command to enable the WSL feature:

      PS C:Windowssystem32> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
      

      Once you run the command you’ll see output similar to this:

      output

      Deployment Image Servicing and Management tool Version: 10.0.19041.844 Image Version: 10.0.19042.985 Enabling feature(s) [==========================100.0%==========================] The operation completed successfully.

      Next, run the following command in PowerShell to enable Windows’ Virtual Machine Platform. This enables the second generation of the WSL by enabling Hyper-V and allowing Windows’ to install Linux using it.

      PS C:Windowssystem32> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
      

      Once you run the command you’ll see output similar to this:

      output

      Deployment Image Servicing and Management tool Version: 10.0.19041.844 Image Version: 10.0.19042.985 Enabling feature(s) [==========================100.0%==========================] The operation completed successfully.

      Once you have done this you will need to restart Windows for these changes to take place.

      After the restart is finished, log back in to your workstation.

      Next you’ll need to download the latest Linux kernel update package from Microsoft and install it.

      To install this package, click to download the wsl_update_x64.msi package to your local workstation. Once it is downloaded, run the application and follow the prompts to install it.

      Download the Linux Kernel patch and run

      Finally, you need to set the default version of the WSL to version 2. Open another PowerShell terminal as an administrator and run the following command:

      PS C:Windowssystem32> wsl --set-default-version 2
      

      Once you run the command you’ll see output similar to this:

      output

      For information on key differences with WSL 2 please visit https://aka.ms/wsl2

      Now that you’ve done this the WSL 2 is enabled and ready to run on your workstation. Next you’ll need to install a Linux-based operating system using the WSL 2.

      Step 2 — Installing Ubuntu 20.04 using the WSL

      Now that you have the WSL 2 installed, you next need to install a Linux distribution from the Microsoft Store. For this tutorial we will be installing the default Ubuntu option from the store, which happens to be Ubuntu 20.04 at this time. There are many different options to choose from and all should take a nearly identical approach to installation as laid out in this tutorial.

      Open your Start menu, search for the Microsoft Store, and open it.

      Open the Microsoft Store

      Locate the search bar in the upper right-hand corner and search for Linux.

      Search for Linux

      Many options will appear; select the Ubuntu tile to install the latest supported version of Ubuntu. Click the Get button to add the app to your account. Once you’ve done this, the Get button will be replaced by the Install button. Click that button to install Ubuntu to your local workstation. Once the installation is done a Launch button will appear. Click this to launch Ubuntu.

      Select Ubuntu and Install

      The first time you launch Ubuntu it will inform you that it is performing initial configuration that may take a few minutes. After this it will prompt you for a Linux system username and password. This username and password doesn’t have to be the same as your system but it will be required for you to be able to use sudo to gain admin privileges.

      Perform Initial Setup of Ubuntu

      Once you have created your user the initial setup is complete and Ubuntu is ready to be used.

      Once initial setup is done Ubuntu is ready to be used

      Now that you have Ubuntu installed, you’ll install a more robust terminal for accessing Ubuntu through Windows.

      Step 3 — Installing and Configuring the New Windows Command Line

      Ubuntu provides a default terminal for use, but Microsoft open sourced and reimplemented their Terminal tool and branded it at Windows Terminal. This terminal supports many more customization and ease-of-use options than the default Ubuntu terminal, so you’ll want to install it.

      Next you’ll install this terminal on your workstation. Navigate back to the search bar in the Microsoft Store and search for Terminal.

      Search Terminal in the Microsoft Store looking for Windows Terminal

      Install the Windows Terminal the same way you installed Ubuntu, by clicking Get and Install. Launch the terminal by clicking Launch or selecting the program from your Start menu.

      Get and Install the Windows Terminal. Then click launch

      By default, the Windows Terminal opens up a PowerShell console.

      Default Windows Terminal opens up PowerShell

      If you want to open a different console, click the down arrow button to see what is available. You have access to PowerShell, Command Prompt, and Azure Cloud Shell by default. When you install any WSL Linux, it will appear here as well like the Ubuntu install did. Clicking Ubuntu will open an Ubuntu shell in a new tab.

      Windows Terminal supports many different options

      If you want to change some of the Terminal’s default options, click the down arrow button and select Settings.

      Open up settings to change the default to the WSL Ubuntu

      Next, set Ubuntu as your default console. Under Default Profile select your Ubuntu WSL image, and click Save to make it your default option.

      Select Ubuntu as your Default Profile

      Now when you click the + button or open a new terminal Ubuntu will be the default shell.

      Clicking the plus or opening the terminal new will give you your WSL Ubuntu shell

      You now have the new Windows Command Line tool installed and configured to open your WSL Ubuntu terminal by default. You are now ready to use Linux on Windows using the WSL.

      Conclusion

      You now have a fully functioning Linux environment running in Windows. You configured your computer to take advantage of the Windows Subystem for Linux, and installed an Ubuntu environment using the WSL. If you prefer a different Linux distribution, there are others you can install, including Debian, SUSE, or Kali Linux. From here, you can install developer tools to have a complete Linux development environment running on Windows.



      Source link

      How To Set Up Visual Studio Code (VS Code) for PHP Development


      Introduction

      Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems.

      With a large collection of extensions for many programming languages, VS Code can be customized to serve a wide variety of development needs. In this guide, you’ll learn how to set up Visual Studio Code for working on PHP projects.

      The gif shows the VS Code interface for PHP development

      Prerequisites

      To follow this guide, you’ll need to download and install the appropriate version of Visual Studio Code for your operating system.

      The instructions in this guide were validated on an Ubuntu 20.04 desktop computer, but they should work seamlessly in all operating systems that are supported by VS Code. Please note, though, that keyboard shortcut keys may need to be slightly modified for compatibility with MacOS systems.

      Right after installation, VS Code already recognizes PHP code and helps with syntax highlighting, basic debugging, and code indentation. These features are suitable for quick edits or when working with individual PHP scripts. Working in larger projects, though, can become difficult without more context around the code and how each file interacts and integrates within the larger project.

      There are a number of VS Code extensions that can help speed up your productivity when working on PHP projects. In this guide, we’ll install and set up PHP Intelephense, a popular PHP extension for VS Code that provides several advanced features such as improved code completion, better navigation between components, rich information tooltips on mouse hover, code auto formatting, and real time error reporting based on static code analysis.

      Open the extensions tab by clicking on the last icon on the left menu bar, or by pressing CTRL + SHIFT + X. This will bring up a sidebar menu with a search box and a list of popular or recommended extensions. Type “php” or “intelephense” to locate the PHP Intelephense extension. Click on the Install button to install and enable the extension.

      The gif shows how to access the extensions menu on the left sidebar

      Once installation is complete, Intelephense’s official documentation recommends that you disable the built-in PHP Language Features extension that comes with VS Code.

      To disable this extension, type @builtin php in the Extensions search box to locate the built-in PHP extensions. Then click on the settings icon for the PHP Language Features extension, and click the Disable option in the drop-down menu.

      The gif shows how to disable the builtin PHP Language Features extension

      If you have any files open in VS Code, you’ll need to reload the editor to apply the changes.

      You can install other extensions by following the same process described for the PHP Intelephense extension, but be aware that some extensions will require additional software to be installed on your system. Check the extension documentation to make sure you have requirements set appropriately.

      Step 2 — Importing or Creating a New PHP Project

      To import an existing PHP project into VS Code, click on the first icon on the left menu bar or type CTRL + SHIFT + E to access the file explorer. Click the Open Folder button and select your project’s directory. In case you are creating a new project, you can create a new folder and select that as your project directory.

      The gif shows how to import a PHP project to VS Code

      The explorer window will now show the project’s directory tree, giving you quick access to files and directories on your project.

      Step 3 — Customizing Theme and Editor Font (Optional)

      Although not necessary, it is often a good idea to customize the appearance of your editor to make it more comfortable to use in the longer term. As a developer you may spend several hours every day looking at an IDE such as VS Code, and for that reason it’s important to make sure the editor font has an appropriate size, and the contrast is enough for good readability without tiring your eyes too quickly.

      You may want to experiment with different themes and fonts in order to find a custom setup that works well for you.

      Changing VS Code Theme

      VS Code comes with a few different themes that allow you to change the colors used in the editor interface and in the code highlighting. Both dark and light styles are included by default.

      Go to File -> Preferences -> Color Theme or type CTRL + K + T to select a different theme for VS Code.

      The gif shows how to change VS Code theme

      You can also install theme extensions to further customize VS Code’s appearance. If you search for theme within the extensions tab (CTRL + SHIFT + X), you’ll find several theme extensions in different styles and colors, including color schemes ported from other popular editors and platforms.

      Adjusting the Font

      Although the default VS Code font settings will be good enough for many users, you may want to adjust the size and the type of the editor font for increased readability.

      If you would like to modify the font size or change to another type, you can go to File -> Preferences -> Settings, then choose Text Editor on the left menu. Then, click on Font in the submenu that opens up. That section contains font family and size settings which you can tweak as preferred.

      The gif shows how to change VS Code editor font size

      The changes are immediately saved and applied to all current open files.

      Conclusion

      Visual Studio Code is a lightweight yet powerful code editor that can be customized to suit the needs of most developers. In this guide, you learned how to install and configure the PHP Intelephense extension for extra support while working on PHP projects, how to import and create new projects within VS Code, and how to customize the editor appearance for a more comfortable coding experience.

      For more tutorials on Visual Studio Code, check our VS Code tag page. If you’d like to learn more about PHP development, you can refer to our How To Code in PHP series for an introduction to the language, and our PHP tag page for more PHP tutorials.



      Source link