3 min read
Table of Contents:
PHP development can be frustrating on Windows. It does not have a "native" way to configure PHP or its package manager Composer. Let us learn a powerful quick way to use WSL and composer's installer to setup a local development environment.
The Windows Subsystem for Linux let's a Windows machine (Windows 10 or 11) run an instance of Linux on top of their Windows operating system. It operates in a different way than a Docker container or Virtual Machine. It is a truly unique way to use Linux with Windows.
If you have a Windows 10/11 machine you have the ability to enable your machine to run WSL. If you do not have it installed, please click here to follow Microsoft's documentation. Once complete use your terminal/cmd to open up the instance!
Composer is a tool that is a repository manager for PHP. It allows for people to share packages of premade code. A great example is the Laravel Framework or Symfony. If you plan to use PHP installing Composer is almost a must!
Once you are in your WSL Instance (I recommend the Ubuntu WSL distro if you can't decide which one), run the command:
cd ~
This will put us in our home directory. When you first login to your WSL instance it will put you in a mounted version of your C Drive. I have no need to be in there and want to utilize the Linux system.
Now we will download a script from Composer's website:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
The first command copies the download file from the website and names itself "composer-setup.php" the second runs a script to ensure that the file downloaded correctly.
The way we write out this script will ensure it installs to the correct place in your Linux installation so you can just run the commands of composer.
sudo php composer-setup.php --install-dir=/bin --filename=composer
This command will download everything from composer that is required and install it in the "bin" folder. You need sudo privileges for this folder. It will also change the filename from "composer.phar" to "composer" to make it easier to call on.
Now you need to close out the terminal and reopen it. Once it is back up run:
composer
It should come up with the help dialog by composer. If you followed all of the steps it should be working! Hope this helps and have a great evening!
Create a simple terminal application that can let you know how much weight you need to put on the ba...
Relying on HTML to validate your forms is just one step in ensuring visitors enter their information...
NodeJS can help you automate simple tasks. Being a web developer you can achieve the same goals as o...
Python can take boring tasks away from you so you can continue to do other things. It is a scripting...
Most WordPress sites use Apache as their server. Apache has a lot of tools built into it to speed up...
@goodeveningtech
@cobb208
@cobb208_cobb
@goodeveningtech
@corycobb208