chanthornsp / wsl-laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setup WSL For Laravel Development

Install WSL

Go to https://learn.microsoft.com/en-us/windows/wsl/install-manual and follow the instructions

Install Ubuntu 22.04 LTS

Remove Password Requirement for Sudo (Optional)

  • Run sudo visudo
  • Go to the end of the file and add the following line:
    ALL ALL = (root) NOPASSWD: /usr/sbin/service
    <your_username> ALL=(ALL) NOPASSWD: ALL
  • Save and exit by pressing Ctrl + X, then Y, then Enter (Nano Editor)

Install PHP MySQL Nginx Redis and required packages...

  • Run
    sudo apt-get install network-manager libnss3-tools jq xsel build-essential libssl-dev zip unzip dnsmasq nginx mysql-server php-fpm php-cli php-mysql php-sqlite3 php-intl php-zip php-xml php-curl php-mbstring redis-server php-redis php-pear php-dev pkg-config libz-dev libzip-dev libmemcached-dev libmemcached11 libmemcachedutil2 libmagickwand-dev imagemagick memcached -y
  • Verify PHP is installed by running php -v You should see PHP Version.

Setup MySQL

  • Run
    sudo service mysql start
  • To change the root password run sudo mysql
    • Run
      ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
    • Replace password with your password.
    • Run
      FLUSH PRIVILEGES;
    • Run
      exit;
  • Restart MySQL by running
    sudo service mysql restart

Node Setup

  • Node.js LTS version:

  • Using Ubuntu

    curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - &&\
    sudo apt-get install -y nodejs
    
  • Run node -v to verify NodeJS is installed

  • Reference

Install Composer

  • cd ~ to go to your home directory

  • Run

    wget https://getcomposer.org/installer
  • Run

    php installer
  • Run

    sudo mv composer.phar /usr/local/bin/composer

    Add composer to your path

  • Run composer --version to verify composer is installed

  • Add this to the end of your ~/.bashrc file by running

    nano ~/.bashrc

    and adding this to the end of the file:

    export PATH="$HOME/.config/composer/vendor/bin:$PATH"

    save and exit by pressing Ctrl + X, then Y, then Enter (Nano Editor)

  • Run

    source ~/.bashrc

    to reload your bashrc file

Set Laravel Valet for linux

  • Install Required Packages

    • Run
      sudo apt-get install network-manager libnss3-tools jq xsel -y
  • Install Valet via Composer

    • Run
      composer global require cpriego/valet-linux
  • Run

    valet install
  • Go to your web root directory e.g.

    cd /var/www
  • Run

    valet park

    to register your current working directory as a path that Valet should search for sites

  • To test if Valet is working create a new directory in your web root directory

    mkdir info
  • If permission denied run (Not Recommended)

    sudo chmod -R 777 /var/www

    OR (Recommended)

    sudo chown -R $USER:$USER /var/www

    and create directory again

  • Run

    cd /var/www/info
  • Run

    echo "<?php phpinfo();" > index.php
  • On Windows you must add host 127.0.0.1 info.test to C:\Windows\System32\drivers\etc\hosts file

  • You can use Hosts File Editor to edit hosts file

  • Open your browser and go to http://info.test

  • Auto Valet start

  • Run

    nano ~/.bashrc
    • Go to the end of the file and add the following line:
      if ! ps -C nginx >/dev/null; then
          sudo service mysql start # start mysql if not running
          valet start # start valet
      fi

Install Laravel Installer

  • Run composer global require laravel/installer
  • Run laravel --version to verify Laravel Installer is installed

Editor Setup (VSCode)

  • Install VSCode
  • Install VSCode Remote WSL Extension
  • Open WSL Terminal
  • Go to your project folder
  • Run code . to open VSCode

Others (Optional)

About

License:MIT License