You know composer is a framework for maintaining PHP packages - installing them as a dependency to your project, ensuring their requirements, auto-loading classes, and much more. But you can also create a new PHP project directly from a composer package, easily. In Visual Studio Code it's even simpler.
Already know composer? With PHP Tools you don't have to install
composer, just pick command
composer: create project ...and that's it.
We need a few things; obviously Visual Studio Code and the following.
PHP - please make sure, you have
php installed. With PHP Tools you can configure what version of PHP will be used, and check whether it is installed correctly (docs.devsense.com).
Composer Extension - make sure, you have this extension installed: Composer for VS Code. It extends Visual Studio Code with commands for maintaining your composer packages, IntelliSense for
composer.json, and it also automatically downloads
Start with an empty workspace. Open VS Code and either open an empty folder, or close an existing folder so you have an empty workspace like this:
Open Command Palette and choose
Composer: create-project ... command. Confirm.
If you have an empty workspace, you'll get asked, where to create the project. Then the command asks for the package name to create your project from. Just type a few letters, it searches it for you including the corresponding information. I personally like watching for downloads and stars count ...
There are many package you can create the project from. The most populars are probably
Confirm the selection, and watch the progress in Visual Studio Code's Output:
The project is created, now you can setup Visual Studio Code to run and debug it. Open Run and Debug tab, and create
launch.json file, as shown on the picture:
.vscode/launch.json file is ready, but make a few adjustments for your actual project first. In case of Laravel, we need to change the web root folder from