I hope this post will take the struggle out some of the Laravel setup and __by the end of this tutorial you should be able to:
- use PHP
- run composer
- create a new Laravel project without any errors!
-If you have already tried setting up Laravel and are having issues with PHP or Composer, I would recommend deleting your current installation files and their related PATH's and start over at Step 1.\
-If you are currently having problems with php.ini and fileinfo, like many of us starting with PHP 8, hopefully Step 5 will help.
- Download PHP zip file from https://windows.php.net/download/
- Create a new folder in the C drive called "php8". This will make your PHP files easily accessible.
- Extract Downloaded PHP files to your new php8 folder
- Download Composer-Setup.exe from getcomposer.org/download
- Run the file and make sure that C:\php8\php.exe is your command line PHP and that a php.ini file is created. You can skip the Proxy Server Prompt.
- Open your Command Prompt and type
php -v. After you press Enter, you will see your PHP version number.
- In the Command Prompt check for your composer in the same way with
composer -vYou will see the version number in addition to a list of commands composer can run.
In the Command Prompt enter:
composer global require laravel/installer
and the Laravel will be installed on your system.
Laravel is now installed globally but when you try to create new file by typing:
laravel new example-app
the project will only be partially created and will throw the following error:
Problem 1 - laravel/framework[v8.12.0, ..., 8.x-dev] require league/flysystem ^1.1 -> satisfiable by league/flysystem[1.1.0, ..., 1.x-dev]. - league/flysystem[1.1.0, ..., 1.x-dev] require ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension. - Root composer.json requires laravel/framework ^8.12 -> satisfiable by laravel/framework[v8.12.0, ..., 8.x-dev].
The problem is that your php.ini file is missing the fileinfo and init extensions. The extensions are written into your php.ini file but need to be uncommented manually. Here is how to do it:
- Open the php.ini file in your php8 folder. If you have not sorted your files is the file right below php.exe but right above php.ini-development. You can also search for it using the file explorer. Then open the file in either Notepad or VScode.
- Once the file is open, search for the text "fileinfo" with no spaces and you will come to a long list of extensions. Remove the ; from in front of
- Save the file and you are set! Time to create a new Laravel file and begin coding!
laravel new example-app