Working on a PHP project in Visual Studio may start in two ways; either opening a folder (
Folder), or creating a regular Visual Studio project (
Project). Although both approaches work, we're recommending the seconds option, since it provides much more features and the full blown Visual Studio experience. Let's take a look on the New Project Wizards.
There are a lot of project templates, which are pretty much self describing. First, there are two kinds of projects - a Web Site and a Console. Usually people are creating a Web Site in PHP.
Then you're either creating an empty project from scratch, or a new project based on a template, or just want to start a Visual Studio project somewhere in an existing location - either local or remote.
The first project template allows to create a new project from scratch. After choosing the
PHP Web Project template, the project creation wizard opens.
Choose Empty Web Site, and follow the wizard steps to finish the project creation. This project template creates a standard project with a single initial file, ready to run. Note, that PHP and debugging is initialized automatically, and by default upon starting the newly created project, the built-in web server is started.
The next step lets you to select the desired PHP version, and whether to create a legacy project type. This option allows to create a project that is compatible with Visual Studio 2017 and older, including Visual Studio 2010. Note, that if there is any already installed PHP on the system, it is chosen by default. Otherwise, PHP will be installed and configured for you.
For more details, please see the New Project documentation page.
The same wizard allows to create a new WordPress web site, ready to run. The WordPress sources are always downloaded from the official wordpress.org host, and it is always a latest version. It's not worth installing an older version, since it is always recommended to update to the newest anyways.
Expect that about 20MB of data will be downloaded from Internet. Without the Internet connection, the wizard won't finish.
Upon creating the WordPress project, you may need to specify the web server host, or at least the localhost port number. WordPress will create its configuration upon first run, and will expect the domain (including the port number) won't change (the domain name will be stored into the database). The next steps are fully up to you; the recommended approach is to choose IIS or IIS Express host in the project properties (above), whilst specifying exact host name and port number, so it won't change, and will be always the same every time you run the project. After deployment to a remote host, expect to set
WP_SITEURLconstants explicitly. Read more at https://wordpress.org/support/article/changing-the-site-url/.
Another prepared template is the Laravel project. This is actually a shortcut for the new project from composer project named
The wizard will check the PHP satisfies the Laravel project requirements, and will download all the required components.
A neat option is a simple CMS website, consisting only of a few source files, configuration, no database, and content in Markdown files. This makes use of Pico CMS. This kind of project is suitable for small yet powerfull websites, where you suppose to write all the content in Markdown files, and additionally add extensions that may dynamically modify the rendered content. Pico CMS provides simple CMS solution with powerful extensibility options.
A vast array of project templates are available as composer packages. Once you know which one you need, you can create projects right from Visual Studio; choose PHP Project from Composer, and follow the steps. The interactive text box will search and provide additional package information.
The next step allows to specify the PHP version, and creates the new project; Nothing else has to be done - if there is not PHP executable, it is first downloaded and installed, debugging extension configured, required extensions enabled, composer project downloaded and created. Additional configuration may be fixed for you as well.
A common problem is working with an existing code on a remote server. PHP Tools provides the complete solution while giving the full featured IntelliSense, code analysis, and both way synchronization with the remote host. The PHP Project from Remote Location project template guides through the process. This wizard will:
Upon confirming, the files will be downloaded locally, and both way synchronization initialized. Optionally, you can either run the project from the locally copied files, or remotely using the Public URL. For further synchronization of the project files, either enable Publish on Save in Project Properties, or use the Remote Explorer.
In case you don't want to download all the files locally; you just need to edit a few words on the remote host and debug the project remotely - follow these steps. Basically we're going to create an empty local project with a remote profile.
F5to verify the website opens and the debugger is attached.
Remote Explorer, and create the remote profile pointing to the server.
Frequently, there is already a PHP website created and running locally. In such case, Visual Studio just needs a project file, so it can open it, it can show the file tree, and allow to setup project properties such as debugging.
Project form Existing PHP Code project template, and follow the steps. This will just create a project file, and opens it in Visual Studio.
The last option is to create a simple PHP Console Project. The project will run a startup script specified in Project Properties in the regular Windows Command Prompt upon pressing