Install PHP 7 and Composer on Windows 10 through Ubuntu in WSL

A major advantage of using this setup over the more common XAMPP development environment is that with Ubuntu in WSL, the PHP 7 installation will be the 64 bit variant, as opposed to XAMPP where PHP is only available at x86. Using 64bit PHP means more memory for running composer for big projects.

Recently one of our projects got too big and I encountered memory allocation error when I ran composer update. I did this as a workaround and fortunately there was no more issues after I’m done

I assume you already have WSL running on your machine, here are the steps I did to install Composer and PHP 7.0.

Install PHP inside Ubuntu

First update the package list.

$ sudo apt-get update

Then just install php 7.0:

$ sudo apt-get install -y php7.0

It may take a while to setup some stuff…

If everything goes well PHP 7.0 will be installed. Verify it by simply running:

$ php -v

Install Composer inside Ubuntu

To install Composer we follow the official instructions here. Run the following commands:

$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

$ php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

$ php -r "unlink('composer-setup.php');"

Composer is now installed! test it out by running.

$ php composer.phar

You can optionally add composer to your global path to make to make it easier to use.

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

Windows Subsystem for Linux was made for developers and offers all the benefits that comes from using a dedicated Linux machine. With WSL you can run your favorite Windows apps and execute Linux commands natively just like how I installed PHP 7 and Composer inside Ubuntu on our Windows 10 PC.

(Visited 4,179 times, 5 visits today)

Leave A Comment

Your email address will not be published.