Install PHP Composer and Laravel on WSL in 10 minutes
1 min readNov 15, 2023
Install PHP and Composer
First install PHP
# Install the php latest stable
sudo apt install php -y
# Check if success with
php -v
Then install composer
You can also follow this link for actual installation
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
You can check the composer is installing successfully by calling the command
composer
Install Laravel
Go to some directory then create the new project by the following command
composer create-project laravel/laravel example-app
If everything is okay, then we run to serve the server
php artisan serve
Problem: Your requirements could not be resolved to an installable set of packages
Now you need php extra package for XML and Curl
sudo apt install php-xml -y
sudo apt install php-curl -y
then run the composer install again
# At Laravel project directory
composer install
then serve and visit http://localhost:8000
php artisan serve