Developing on Windows with WSL2 (Subsystem for Linux) and PHP

Поделиться
HTML-код
  • Опубликовано: 5 июл 2024
  • Developing on Windows with WSL2 (Subsystem for Linux) and a PHP LAMP stack on wsl2. Adam Culp of Beachcasts PHP programming videos shares how to set up a local development environment with PHP on WSL 2, also known as Windows Subsystem for Linux, and installs a Laravel framework project for local development. By installing a full lamp stack on WSL 2. In this Laravel howto we will set up Apache, and PHP on Ubuntu using WSL, for an awesome WSL 2 local dev environment. I also show how to launch VS Code and Windows Explorer from within Ubuntu running inside WSL 2.
    For information about doing this with Laravel Sail, see • Getting Started using ...
    Please * LIKE, COMMENT, AND SUBSCRIBE * - and share with others!
    Key Topics:
    - Creating a development environment using Ubuntu running on WSL 2
    - Installing LAMP in WSL 2
    - Creating a symbolic link to a working directory on a Windows host
    - Setting up the userdir extension for Apache 2
    - Install and configure a Laravel based application on Ubuntu within WSL 2
    - Launching Windows-based tools from within WSL 2 via CLI
    For a nice list of equipment I use in my studio, and to support the channel if you make any purchases (doesn't cost you a thing), visit my kit at kit.co: kit.co/beachcasts/beachcasts-...
    Errata:
    Let me know if you notice anything that should be errata
    Associated Links:
    php.net
    laravel.com/
    apache.org
    code.visualstudio.com
    docs.microsoft.com/en-us/wind...
    beachcasts.com
    Timeline:
    00:00 Intro
    01:25 Prerequisites for setting up a development environment in WSL 2
    02:17 Installing Apache 2 on Ubuntu in WSL 2
    02:55 Install PHP in WSL 2
    04:21 Creating a working directory on Windows (host) to use within Ubuntu (WSL)
    05:33 Add a symbolic link to the directory on the Windows host
    08:13 Activate userdir extension for Apache 2
    09:04 Configure the userdir extension
    11:47 How to install Composer dependency manager for PHP globally
    14:11 Installing the Dom extension (XML extension) for PHP, and unzip utility for Ubuntu
    15:47 Creating a Laravel based application on Ubuntu within WSL
    17:31 Notes about rendering speeds using WSL 2
    18:57 Alternative methods for serving websites from WSL 2
    19:55 Launching VS Code from within a WSL 2 environment over CLI
    21:06 Launching Windows Explorer from within WSL 2 to view files on Windows host
    Other Beachcasts videos you might find interesting:
    WSL 2 with Docker Gettings Started and Docker Desktop Installation • WSL 2 With Docker Gett...
    Getting Started with WSL 2 and Ubuntu on Windows 10 • Getting Started with W...
    Conference Talk Preparation In 8 Steps for Programmers • Must Follow 8-Step Gui...
    How to understand code written by someone else • Secrets of how to unde...
    Ways to advance your programming skills and improve as a developer • Ways to advance your p...
    Make your local DEV environment available on the internet • Make your local DEV en...
    AWS Elastic Load Balancer (ELB) Tutorial How-To • AWS Elastic Load Balan...
    Laravel Model Factory Tutorial using Artisan make:model • Laravel Model Factory ...
    Authentication in Laravel Tutorial • Authentication in Lara...
    Top 5 skills to be a better software developer • Top 5 skills to be a b...
    Install Laravel in Docker container on Ubuntu for beginners • Install Laravel in Doc...
    Getters and Setters accessors in object-oriented programming • Getters and Setters ac...
    Critical programming issues preventing a PHP 7 upgrade • Critical programming i...
    Behat for beginners functional REST API testing tutorial • Behat for beginners fu...
    Doctrine ORM one-to-many bi-directional association • Doctrine ORM one-to-ma...
    PHP Mess Detector static analysis to find PHP code smells • PHP Mess Detector stat...
    Doctrine ORM one-to-many self-referencing association • PHP DoctrineORM one-to...
    10 reasons to become a consultant in a consulting business • Top 10 Reasons To Be a...
    10 bad things about consulting • Top 10 bad things abou...
    How to get lines of code in PHP • PHPLoc Lines of code s...
    Use UUID with Doctrine ORM for DB keys • UUID with Doctrine ORM...
    Make a Create handler middleware • Create Handler middlew...
    Automate Hypermedia creation for PHP REST API • Automate Hypermedia PH...
    Configure Doctrine ORM • Configure Doctrine ORM...
    Configure PhpStorm for PHP development with Docker • PhpStorm setup for PHP...
    Create PHP development environment with docker • PHP web development en...
    Help through referrals:
    Thinking of buying a Tesla electric vehicle? Use this referral link to also get six months of free Supercharging for both of us. Thank you. www.tesla.com/referral/tanya2...
    I use TubeBuddy to help me manage my RUclips channel. If you're interested, click the following link to check it out. www.tubebuddy.com/beachcasts
    #php #wsl2 #beachcasts
  • НаукаНаука

Комментарии • 101

  • @Beachcasts
    @Beachcasts  2 года назад +3

    Please view ruclips.net/video/X3bPWl9Z2D0/видео.html to see how to get a basic WSL 2 setup created.

    • @Beachcasts
      @Beachcasts  2 года назад +1

      Also, to include Docker see ruclips.net/video/h0Lwtcje-Jo/видео.html

    • @ayebosec
      @ayebosec 2 года назад

      @@Beachcasts I need help. I can't do more than communicate with the person or persons remotely viewing and operating my devices. There a common trend. The police won't do jack.

    • @ayebosec
      @ayebosec 2 года назад

      @@Beachcasts I have the name of the host.
      UtilsGearRulesManager

  • @caminhodaslutas
    @caminhodaslutas Год назад +8

    For those experiencing "FORBIDDEN" issues, simply type "cd" to return to your user's initial home directory and then go back one folder using "cd ../". After that, execute the command "chmod +x youruser".

    • @demeja16
      @demeja16 Год назад +2

      thank you so much, you saved my time:)

    • @minihohtis5906
      @minihohtis5906 Год назад +1

      @@demeja16 I apriciate the solution, but what does this actually do?

    • @demeja16
      @demeja16 Год назад +2

      @@minihohtis5906 hello friend, i don't know because I'm newbie in linux, but here is answer fro askubuntu forum:
      chmod +x on a file (your script) only means, that you'll make it executable. Right click on your script and chose Properties -> Permissions -> Allow executing file as program, leaves you with the exact same result as the command in terminal.
      If a file you want to change permissions on is located within the systems directory you may need to be root, like so: (be careful, while using sudo command)

    • @coolyfooly69
      @coolyfooly69 Год назад +1

      Thank You.

    • @chandrashekharkaushik6845
      @chandrashekharkaushik6845 8 месяцев назад +1

      Helped me today ! Thank you!

  • @bobjohnson9947
    @bobjohnson9947 2 года назад +6

    Adam's WIN10 WSL videos are exceptional in my opinion - very, very informative to a new WSL person like myself, and his audio and video are very professional, his tech comments are brief, concise, and extremely useful, and his screen shots of his typed keyboard input commands as he explains his concepts are very helpful. I would highly recommend his WSL videos...

    • @Beachcasts
      @Beachcasts  2 года назад

      Wow, thanks! Do glad you enjoyed them, and found them useful. Appreciate your compliments.

  • @MET87
    @MET87 Год назад +4

    this was not only informative and accurate but also enjoyable to watch! You sir could be a teacher!

  • @MegaAnand101
    @MegaAnand101 Год назад

    Thank you for the great information, very clear, very concise and very informative. I hope you have an amazing new year.

  • @danzeel
    @danzeel Год назад

    very clean lesson, I've been setting it up several times already, many thanks!

  • @bedrettingulen1128
    @bedrettingulen1128 11 месяцев назад

    I am very new in php world and had lots of questions about it. But with this video i found answers to my questions. Thank you so much @Beachcasts.

  • @dannyvsr
    @dannyvsr Год назад +2

    This entire video has been priceless. Thank you for all of your time and efforts in making it.

    • @Beachcasts
      @Beachcasts  Год назад

      I'm so happy this helped you.

    • @Beachcasts
      @Beachcasts  Год назад

      I use the symbolic link to make it easier to navigate, and easier to swap to a new location when/if needed. Hope this helps.

  • @RobertoDeMontecarlo
    @RobertoDeMontecarlo Год назад

    That's exactly what I was looking for! Thank you so much!

  • @alexwisard
    @alexwisard Год назад

    Perfect! Thanks a lot! Next step - docker-compose and abilitty to make custom configs on projects with reusable images/containers.

  • @ChadLozanoBellingham
    @ChadLozanoBellingham 2 года назад +5

    Very well done! Super easy to follow along and very clear. Looking forward to more videos. I would love to see a video about using setting up ATOMIC in WSL2 and maybe linking cudann/cuda to things. (ML Video)

    • @Beachcasts
      @Beachcasts  2 года назад +1

      Thanks for watching. Great suggestion! I've added it to my list of possible future episodes.

  • @eyobgebreyesus9545
    @eyobgebreyesus9545 Год назад

    It works great! Thank you so much.

  • @shawnwbailey
    @shawnwbailey 2 года назад +1

    I am a .net programmer. I use VS Code and Visual Studio as my main tools. Then comes along this php customer. I saw this video and had the WSL2 environment and lamp stack (I added Mariadb) running in an hour. The only hang up was that I couldn't get past permissions issues with composer on an NTFS volume. Maybe you covered this in an earlier video, but I had to make a /etc/wsl.conf with [automount] options="metadata" to get composer to run. BOOM! I am ready to rock tomorrow! Thank you!

    • @Beachcasts
      @Beachcasts  Год назад

      So glad this was helpful, and thank you for sharing how you got Composer running.

  • @KBPNB
    @KBPNB Год назад

    I liked Your explanation method, video quality, your voice very understandable

  • @vunguyen2246
    @vunguyen2246 2 года назад

    Thank you very much! Very helpful video!

    • @Beachcasts
      @Beachcasts  2 года назад +1

      Glad it was helpful! Thank you for watching.

  • @tiagosoares8297
    @tiagosoares8297 2 года назад

    thanks for the tutorial, it was very helpful. I loved the elephants 😁

  • @propertyrealestate9843
    @propertyrealestate9843 8 месяцев назад

    Thank you, very usefull and clearly.

  • @hamdyahmed5742
    @hamdyahmed5742 2 года назад

    Thanks for sharing this...
    Very helpful

    • @Beachcasts
      @Beachcasts  2 года назад

      My pleasure. Thank you for watching, and glad you found it useful.

  • @OliverRivettCarnac
    @OliverRivettCarnac 2 года назад +3

    Great video! Really helped me get a better understanding of things. Just a note, you need to start apache2 after installation which was a step not covered.
    ```sudo service apache2 start```

    • @Beachcasts
      @Beachcasts  2 года назад

      Thank you for the added note, and thank you for watching. So happy it was helpful for you.

  • @noir4356
    @noir4356 Год назад

    Dude, let met tell you you're just great

  • @folomba
    @folomba Год назад

    Hello! Thanks! I like Linux! I like PHP!

  • @disconnected69
    @disconnected69 Год назад

    Спасибо, очень полезно)

  • @hrithikagarwal3777
    @hrithikagarwal3777 2 года назад +1

    Great Tutorial

    • @Beachcasts
      @Beachcasts  2 года назад +1

      Glad it was helpful! Thanks for watching.

    • @hrithikagarwal3777
      @hrithikagarwal3777 2 года назад

      Most Welcome. I need help regarding one more thing, I was trying to embed react component in my php website. So is there any way of doing it?
      I did some Google search, in that we can use V8 extension but I didn't get properly.
      If you have any idea through that I can achieve it please help me out. Any help is appreciated
      Thanks

  • @jujuclinz
    @jujuclinz Год назад

    Great video! I'm hoping that you can also do for MySQL/Phpmyadmin set-up

  • @MET87
    @MET87 Год назад

    Hello! Great video! Can you make a tut on how to connect to the wsl instance using SSH ? I am trying to use Pycharm and i dont get dependencies. i read that i should connect the project trough ssh ....

  • @lloydthomas348
    @lloydthomas348 2 года назад

    Thanks for this. Was really helpful. Setting up MySQL or MariaDB would have been helpful as well (hint bind-address)

    • @Beachcasts
      @Beachcasts  2 года назад

      Thanks for watching. Great idea!

  • @hotasfireph
    @hotasfireph Год назад

    It's a good tutorial, but can you also enable or install xdebuger? I tried several time but I can't seems to make it work in VsCode

  • @chrisandrew_tv
    @chrisandrew_tv 4 месяца назад

    Great video, thank you for sharing!
    For anybody wondering, you can still follow along without the symlink to a Window file system directory, serving the files in WSL, from WSL, with a few minor adjustments along the way. Microsoft's documentation for WSL states that they "recommend against working across operating systems with your files, unless you have a specific reason for doing so" for the fastest performance and speed. Are there any major consequences of this? I don't yet know.

  • @danzeel
    @danzeel 2 года назад +1

    I think in your tutorial missed the step which explain how to start apache, because in other case localhost is not show apache page. In ubuntu console need to write "sudo service apache2 start"". In any case it was very HELPFUL for me!

    • @Beachcasts
      @Beachcasts  Год назад

      Glad you found it helpful.

    • @danzeel
      @danzeel Год назад

      @@Beachcasts Very helpful!

  • @scotle9901
    @scotle9901 2 года назад +2

    Cool!. Please do with docker

    • @Beachcasts
      @Beachcasts  2 года назад +1

      Thanks for the comment. I plan on doing it with Docker, perhaps using Laravel Sail. ;-)

    • @Beachcasts
      @Beachcasts  2 года назад

      You might be interested in this, where I do use Docker. ruclips.net/video/0HTruhilvcU/видео.html But I think Laravel Sail is likely a better approach.

  • @jdkarns
    @jdkarns 3 месяца назад

    Thanks for the video. Great information. Question? I get a message in VS Code. It does not like the Projects file being in windows. Message: This workspace is on the Windows file system (/mnt/). For best performance, we recommend moving the workspace to the Linux file system (~/home). Any thoughts? Thanks

  • @ricko13
    @ricko13 3 месяца назад

    the symbolic link from host to wsl is not recommended, you just need keep everything inside the WSL2 file system for a faster/better experience 👍

  • @md.anisurrahman9459
    @md.anisurrahman9459 2 года назад

    Great video, thank you! Could you also show us How to install WordPress on WSL?

    • @Beachcasts
      @Beachcasts  2 года назад +1

      Thanks for watching. I'll give that some thought.

  • @viktornikolov1570
    @viktornikolov1570 6 месяцев назад +1

    I'm experiencing the 'FORBIDDEN' issue that other people have faced. I gave execute permissions to my user chmod +x /home/myuser as suggested in the comments and this indeed solved the issue but I don't why. Can someone please explain why this works? Is it safe giving execute permissions to /home/myuser? If not safe or simply a bad practice is there a better solution?

  • @igortalic2021
    @igortalic2021 2 года назад

    Amazing videos! Subscribed immediately 😁 Is there any reason why not have the projects in WSL in Ubuntu? Why link to host? Tnx 😊

    • @Beachcasts
      @Beachcasts  2 года назад +1

      The IDE I use to edit runs on the Windows host, so that is why I keep the files there. Alternatively, I could keep them inside the VM, but then would need to connect remotely with the IDE, which is about the same. However, I would risk losing the files if the VM became corrupted.

    • @igortalic2021
      @igortalic2021 2 года назад

      Thanks for the answer! Yeah losing files would be painful 😁 will change that on my pc 😁

    • @Beachcasts
      @Beachcasts  2 года назад +1

      Thank you for watching, and your question.

  • @codesymphony
    @codesymphony Год назад

    why do we create the projects on windows instead of inside the wsl directory?

  • @Happinessisalwaysthere
    @Happinessisalwaysthere Год назад

    If you have problems with some commands, just add sudo before it.

  • @danzeel
    @danzeel Год назад

    Do you use Docker?

  • @codesymphony
    @codesymphony Год назад

    When I navigate to my project it shows the index file as plain code, and doesn't run it

  • @anshulraj1237
    @anshulraj1237 2 года назад

    I have a question if I wish to install a mongodb extension for php how do I add it to the php.ini file in wsl2?

    • @Beachcasts
      @Beachcasts  2 года назад

      Depending on the OS you're using. In Ubuntu you can use 'sudo apt-get install php-mongodb' or something like that. That should add it to the php.ini for you. I've not done this, but should do what you want.

  • @SoundPeaks
    @SoundPeaks 9 месяцев назад

    So you didn't do any additional settings but when you installed Apache you instantly got the test website at your localhost in Windows?
    What if I also have Apache installed in Windows and it is running as a service on localhost domain, what will happen then?

    • @Wongmc644
      @Wongmc644 9 месяцев назад

      I have windows xampp installed too but manual start. I just don't start the windows apps unless I need to use it then I stop the wsl Apache n MySQL. Xampp includes mariadb (MySQL) which I didn't start. Downloaded heidisql on Windows and connect to WSL mariadb for a GUI interface

    • @SoundPeaks
      @SoundPeaks 9 месяцев назад

      @@Wongmc644 thanks for the clarification!

  • @codedusting
    @codedusting Год назад +1

    apache2 directory modification doesn't work.

  • @elibo0n
    @elibo0n 2 года назад +1

    how did you get "localhost" to work right away?

    • @Beachcasts
      @Beachcasts  2 года назад

      I didn't need to do anything. Just worked.

    • @elibo0n
      @elibo0n 2 года назад +2

      @@Beachcasts yup thanks….turns out i needed to restart the apache service for it to work.

  • @kevinm9769
    @kevinm9769 2 года назад

    You looking for a good laugh? Watch this video at .5 playback speed. haha. Very helpful though, thanks for the amazing content!

    • @Beachcasts
      @Beachcasts  2 года назад

      HA, I know, right? Believe me, I do much editing in slow motion to match up sentences between cuts, and watching myself in slow motion is excruciating. :) Thanks for watching.

  • @hambrunaa
    @hambrunaa Год назад

    when I go to localhost I cant access, it says ERR_CONNECTION_REFUSED , what can I be doing wrong?

    • @Beachcasts
      @Beachcasts  Год назад

      Sounds like it may be a security issue. Maybe there was a missed prompt during installation of WSL2 or Ubuntu?

  • @bookable7157
    @bookable7157 Год назад

    pretty good, except I'm trying to figure out how to "save" at minute 11. you sort of assumed people knew how to do that. google isn't being of much help either.

  • @brightamponsah3832
    @brightamponsah3832 Год назад

    11:39 please I am getting "FORBIDDEN access" can you help me with that?

    • @abrahamlund6420
      @abrahamlund6420 Год назад

      me too

    • @abrahamlund6420
      @abrahamlund6420 Год назад

      try chmod 755 /home/

    • @fratell
      @fratell Год назад

      Do a chmod +x on your user dir, and restart apache

    • @caminhodaslutas
      @caminhodaslutas Год назад

      For those experiencing "FORBIDDEN" issues, simply type "cd" to return to your user's initial home directory and then go back one folder using "cd ../". After that, execute the command "chmod +x youruser".

  • @pradipartyst5809
    @pradipartyst5809 Год назад

    Mounting source code is extremely slow.

  • @ayebosec
    @ayebosec 2 года назад

    What is the "apache software foundation"? There's code and Hella software remotely installed in my phone. I was able to get as far as communicating with the person/persons. I need help they are stealing my business and information. I WILL WRITE YOU A CHECK.

    • @Beachcasts
      @Beachcasts  2 года назад

      Sorry, this doesn't make sense. Unless bad people are using open source software. I doubt it is the foundation doing it.

    • @ayebosec
      @ayebosec 2 года назад

      @@Beachcasts it's bad people. I don't have a understanding on how I would stop them.

    • @ayebosec
      @ayebosec 2 года назад

      Nobody seems to be able to help. Not even the police. No wonder why the government hated Snowden 🙄

  • @ayebosec
    @ayebosec 2 года назад

    I don't know how to get any further then I have.

    • @Beachcasts
      @Beachcasts  2 года назад +1

      I don't think this is the right place for your questions. Sorry.