Run and Debug Your PHP Project
Once you have your PHP Project, you can run the application and debug. Debugging allows you to run the application and stopping on breakpoints F9, stepping on the next line F10, inside a function call F11, out of the function call Shift+F11 or inspecting and modifying variables. You can see e.g. local variables, super-global variables and current call stack.
To run and debug the project, ensure it is properly configured (see below) and press F5 (or in
Menu | Debug | Start Debugging
). You can also run the project without debugging by pressing Ctrl+F5.
Configuring PHP
Running the application locally requires properly configured PHP. To enable support for debugging, PHP extension Xdebug has to be installed and configured as well.
PHP Tools help with the setup in two ways.
Once you start your first application F5 and there is no valid PHP installation found, you can download and setup a recommended version of PHP with pre-configured Xdebug within one click from Microsoft Web Platform Installer. This is the most recommended option for most users.
For users with custom requirements or requiring to use their existing PHP installation, PHP Tools help by checking the configuration and suggesting recommended fixes eventually.
The issues dialog is shown automatically if there is an issue with configuration during the project startup. It can also be invoked manually from
Menu | Tools | Options
, in
PHP Tools | Interpreter
, by clicking onto View Recommendations.
A list of PHP installations and their configuration can be found in
Menu | Tools | Options
, in
PHP Tools | Interpreter
. You can see the version of PHP, whether Xdebug is detected and whether there are possible configuration issues. In case of an issue, you can click on the View Recommendations warning and automatically apply the recommended and suggested settings.
Remote Debugging and Custom Web Server
To run the application on a remote server or locally using a not-listed Web Server, go to project properties. Select Custom Web Server and enter its URL.
In this case, PHP and Xdebug configurations are not checked whether they are installed or configured properly. You have to make sure that:
- The project files are published onto the remote server before debugging or the web server is mapped onto your local project folder.
- PHP and Xdebug are configured on the custom web server.
- Xdebug configuration allows remote debugging.
- Custom server is running and is accessible from the URL you specified.
Next steps
Read on to find out about:
- Extension Marketplace – Browse the extensions others have shared
- Debugging – Learn more about VS Code debugging
Getting Started with PHP Tools
Welcome to PHP Tools for Visual Studio. The following guide will help you with the basics, so you can quickly start working with PHP in Microsoft Visual Studio.
Note: PHP Tools for Visual Studio is a Visual Studio extension. Please note, licensing of Visual Studio Express does not allow the extensibility. Thus PHP Tools does not support VS Express editions.
That’s It
Thank you for reading our quick start guide. There is much more you can do with Visual Studio and PHP Tools. For more tips and/or questions, please see the rest of the documentation and the product’s features page.
PHP Tools for Visual Studio transparently integrate into Microsoft Visual Studio, and extend it with the support for PHP language. The extension is focused on developer productivity respecting conventions. It understands the code, provides smart code completion, quick navigation, error checking, code diagnostics, code formatting, integrated PHP manual, project system, debugging support, composer package manager, and more.
Well-Known IDE
• Respecting Visual Studio guidelines
• Automatic updates & Easy installation
• Version control support (TFS, Git, SVN, …)
• Seamless integration respecting conventions
• High performance environment
Smart PHP editor
• Full PHP 5.4 – 8.1 support
• PHP IntelliSense
• HTML/CSS/JS support
• Smarty, Twig, Blade templating
• Real-Time Code Validation
• Shows embedded documentation
Visual Debugging
• Breakpoints in PHP and JavaScript
• Inspect variables, watches
• Immediate Window
• Multiple session debugging
HTML/JS/CSS support
• Visual Studio HTML Editor
• Syntax Highlighting, Schema validation
• Formatting, Outlining, Commenting
• Full IntelliSense
• Web Essentials support
Code Navigation
• Browse declarations within your solution
• Quickly search through available symbols
• Navigate directly to symbol definitions
• Navigate To, Class View, Object Browser, …
Integrated PHP manual
• PHP functions & constants & classes
• Integrated documentation
• Search available symbols while typing
• PHPDoc support
PHP Tools for Visual Studio transparently integrate into Microsoft Visual Studio, and extend it with the support for PHP language. The extension is focused on developer productivity respecting conventions. It understands the code, provides smart code completion, quick navigation, error checking, code diagnostics, code formatting, integrated PHP manual, project system, debugging support, composer package manager, and more.
Well-Known IDE
• Respecting Visual Studio guidelines
• Automatic updates & Easy installation
• Version control support (TFS, Git, SVN, …)
• Seamless integration respecting conventions
• High performance environment
Smart PHP editor
• Full PHP 5.4 – 8.1 support
• PHP IntelliSense
• HTML/CSS/JS support
• Smarty, Twig, Blade templating
• Real-Time Code Validation
• Shows embedded documentation
Visual Debugging
• Breakpoints in PHP and JavaScript
• Inspect variables, watches
• Immediate Window
• Multiple session debugging
HTML/JS/CSS support
• Visual Studio HTML Editor
• Syntax Highlighting, Schema validation
• Formatting, Outlining, Commenting
• Full IntelliSense
• Web Essentials support
Code Navigation
• Browse declarations within your solution
• Quickly search through available symbols
• Navigate directly to symbol definitions
• Navigate To, Class View, Object Browser, …
Integrated PHP manual
• PHP functions & constants & classes
• Integrated documentation
• Search available symbols while typing
• PHPDoc support
By Erika Heidi
Developer Advocate
Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems.
With a large collection of extensions for many programming languages, VS Code can be customized to serve a wide variety of development needs. In this guide, you’ll learn how to set up Visual Studio Code for working on PHP projects.
To follow this guide, you’ll need to download and install the appropriate version of Visual Studio Code for your operating system.
The instructions in this guide were validated on an Ubuntu 20.04 desktop computer, but they should work seamlessly in all operating systems that are supported by VS Code. Please note, though, that keyboard shortcut keys may need to be slightly modified for compatibility with MacOS systems.
Right after installation, VS Code already recognizes PHP code and helps with syntax highlighting, basic debugging, and code indentation. These features are suitable for quick edits or when working with individual PHP scripts. Working in larger projects, though, can become difficult without more context around the code and how each file interacts and integrates within the larger project.
There are a number of VS Code extensions that can help speed up your productivity when working on PHP projects. In this guide, we’ll install and set up PHP Intelephense, a popular PHP extension for VS Code that provides several advanced features such as improved code completion, better navigation between components, rich information tooltips on mouse hover, code auto formatting, and real time error reporting based on static code analysis.
Open the extensions tab by clicking on the last icon on the left menu bar, or by pressing
CTRL + SHIFT + X
. This will bring up a sidebar menu with a search box and a list of popular or recommended extensions. Type “php” or “intelephense” to locate the PHP Intelephense extension. Click on the Install button to install and enable the extension.
Once installation is complete, Intelephense’s official documentation recommends that you disable the built-in PHP Language Features extension that comes with VS Code.
To disable this extension, type
@builtin php
in the Extensions search box to locate the built-in PHP extensions. Then click on the settings icon for the PHP Language Features extension, and click the Disable option in the drop-down menu.
If you have any files open in VS Code, you’ll need to reload the editor to apply the changes.
You can install other extensions by following the same process described for the PHP Intelephense extension, but be aware that some extensions will require additional software to be installed on your system. Check the extension documentation to make sure you have requirements set appropriately.
To import an existing PHP project into VS Code, click on the first icon on the left menu bar or type
CTRL + SHIFT + E
to access the file explorer. Click the Open Folder button and select your project’s directory. In case you are creating a new project, you can create a new folder and select that as your project directory.
The explorer window will now show the project’s directory tree, giving you quick access to files and directories on your project.
Although not necessary, it is often a good idea to customize the appearance of your editor to make it more comfortable to use in the longer term. As a developer you may spend several hours every day looking at an IDE such as VS Code, and for that reason it’s important to make sure the editor font has an appropriate size, and the contrast is enough for good readability without tiring your eyes too quickly.
You may want to experiment with different themes and fonts in order to find a custom setup that works well for you.
VS Code comes with a few different themes that allow you to change the colors used in the editor interface and in the code highlighting. Both dark and light styles are included by default.
Go to File -> Preferences -> Color Theme or type
CTRL + K + T
to select a different theme for VS Code.
You can also install theme extensions to further customize VS Code’s appearance. If you search for
theme
within the extensions tab (
CTRL + SHIFT + X
), you’ll find several theme extensions in different styles and colors, including color schemes ported from other popular editors and platforms.
Although the default VS Code font settings will be good enough for many users, you may want to adjust the size and the type of the editor font for increased readability.
If you would like to modify the font size or change to another type, you can go to File -> Preferences -> Settings, then choose Text Editor on the left menu. Then, click on Font in the submenu that opens up. That section contains font family and size settings which you can tweak as preferred.
The changes are immediately saved and applied to all current open files.
Visual Studio Code is a lightweight yet powerful code editor that can be customized to suit the needs of most developers. In this guide, you learned how to install and configure the PHP Intelephense extension for extra support while working on PHP projects, how to import and create new projects within VS Code, and how to customize the editor appearance for a more comfortable coding experience.
For more tutorials on Visual Studio Code, check our VS Code tag page. If you’d like to learn more about PHP development, you can refer to our How To Code in PHP series for an introduction to the language, and our PHP tag page for more PHP tutorials.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
If you are macOS user, ServBay.dev is a good tool, especially for the beginners. It handles all PHP, MariaDB, PostgreSQL versions, plus Redis and Memcached. Run multiple PHP instances simultaneously and switch easily. This tool has made my PHP dev simpler. Worth a shot!
Also there is an AI code suggestions extension IntelliPHP: https://marketplace.visualstudio.com/items?itemName=DEVSENSE.intelli-php-vscode
I have gone through your article which was on PHP extensions. The essential PHP extensions for specific functionalities depend on the requirements of your project. However, here are some commonly used extensions for different functionalities: 1.Database Connectivity 2.XML Processing 3.JSON Manipulation 4.Image Processing 5.Encryption and Hashing 6.compression and Archive 7.File System Manipulation 8.Date and Time Manipulation 9.Caching and Performance Optimization From my point of view, these are some points to be included in your article. Readers, If you want to develop your PHP website, you can get a free consultation from an IT company like Alakmalak technologies. They have 17+ years of experience in this field.
Just adding – for a complete PHP language support (debug, IntelliSense, format, code actions, test explorer, and more) there is all-in-one commercial extension https://marketplace.visualstudio.com/items?itemName=DEVSENSE.phptools-vscode
Click below to sign up and get $200 of credit to try our products over 60 days!
Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
New Project from Existing Code
If there is already a folder with existing PHP code files, a new Visual Studio project can be created right from there.
Customization
The Visual Studio environment is fully customizable. Most common tasks you may want to customize are listed below.
File Extension Being Opened by PHP Editor
In addition to default .php file extension, you can configure other file extensions to be edited with PHP editor capabilities. This is useful when you work on projects using non-standard file extensions for PHP script file, like .php5, .inc or .module. Go to
Menu | Tools | Options
, into section
Text Editor | File Extensions
, and map additional file extensions you need to PHP Editor.
Fonts and Colors
PHP Editor respects current users color scheme. Any color in the editor or in Visual Studio environment itself can be configured. Go to
Menu | Tools | Options
, in section
Environment | Fonts and Colors
, and modify any display item listed. PHP specific colors are prefixed with PHP. Other colors are shared with Visual Studio built-in colors – Identifier, Keyword, Comment, String, Number, Text.
Keyboard Mappings
PHP Tools respects the Visual Studio keyboard scheme. Shortcuts used to work with your projects and editor can be managed in
Menu | Tools | Options
, in the section
Environment | Keyboard
.
PHP Editor Options
Options of PHP Editor includes adjustment of code formatting behavior, change tab sizes, fine-tune IntelliSense, disable outlining of various code blocks and more. Go to
Menu | Tools | Options
, and navigate to section
Text Editor | PHP
for additional settings.
Next steps
If PHP development in Visual Studio is interesting to you, please install PHP Tools for Visual Studio and make sure to let the authors know how you like it, what features you are missing or if you run into anything that could be further improved. You can reach them at DEVSENSE’s PHP Tools Community Forum.
PHP in Visual Studio Code
Visual Studio Code is a great editor for PHP development. You get features like syntax highlighting and bracket matching, IntelliSense (code completion), and snippets out of the box and you can add more functionality through community-created VS Code extensions.
Related links
- New Project – creating a new PHP project, either empty or from a template.
- New Project from Composer Package – creating a new PHP project from a composer package.
- New Project from Remote location – creating a new PHP project that is initialized with files from a remote location, and setups both-way synchronization.
PHP extensions
There are many PHP language extensions available on the VS Code Marketplace and more are being created. You can search for PHP extensions from within VS Code in the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)) then filter the extensions dropdown list by typing ‘php’.
Disable built-in PHP support
To disable the built-in PHP smart completions in favor of suggestions from an installed PHP extension, uncheck PHP > Suggest: Basic, which sets
php.suggest.basic
to false in your
settings.json
file.
Test Your Application
PHP project integrates into Visual Studio Test Explorer. Go to
Menu | Test | Windows | Test Explorer
to manage the test cases. Project files are scanned and PHP Unit test cases are automatically listed within the Test Explorer window.
Within the window, you can start or debug your test cases using built-in PHP Unit framework.
Note: availability of the Test Explorer feature depends on your edition of Visual Studio.
Quick start
First, install PHP Tools for Visual Studio
Create your PHP project
After the installation:
- Select Create a new project from the start page or File > New > Project… from the title bar
- In the language combo box select PHP, select PHP Web Project, then select Next
- Name your project and select Create.
- At this point, you can select the project template. Let’s choose Empty Web Site and select Next:
- Now, you can select which PHP version to set for the project. For this short tutorial, we can go with PHP 8.1 and select Finish. PHP Tools will check your environment and install and configure PHP which is set up in the project:
Use the PHP Editor in Visual Studio
When the installation is finished, the project will open. In the editor, you can hover over any symbol to get a tooltip. Or press Ctrl + Space to see the IntelliSense for the current context.
Run and Debug PHP in Visual Studio
Place a breakpoint F9 and hit F5 to run the project and start debugging. The server which is configured in the project (by default it’s PHP’s built-in Web server) will run and a browser opens. Then the breakpoint will get hit.
Congratulations! You are debugging PHP in Visual Studio.
This was a simple walkthrough of how PHP Tools for Visual Studio can be used where you have one project in the solution. A more complex setup is possible: developers can add PHP projects to their existing solutions (*.sln) – having one IDE should make their life easier, or they can work with PHP just by opening a folder. More tutorials can be found on DEVSENSE’s documentation.
First PHP project
Most of the features in Visual Studio work within the context of a project. Debugging, IntelliSense, testing or configuring web server depends on a PHP project. The project corresponds to a single application or a library, it can be bound to a source control or configured to publish modified files onto a remote server.
Projects in Visual Studio work with a local copy of your files. To push them on a server, you have to deploy your files – either by configuring automatic publish or by your own.
There are several ways to create a new project in Visual Studio by:
- Creating a new PHP project from scratch.
- Creating a PHP project around existing files.
- Importing existing files into a project.
New PHP Project from Scratch
An empty PHP Project is the simplest way of getting started with PHP Tools. Go to ‘Menu | File | New | Project’ and look for ‘PHP’ group. Find the project template you need and confirm.
Additional files and directories can be added in various ways:
-
In
Menu
or
Solution Explorer | Project | Add New Item
- Drag & Drop from Windows Explorer into Solution Explorer
- Enabling Show All Files in Solution Explorer to see all the files physically present within the project directory and including them into the project
New Project in an Existing Folder
If you already have files in a local folder, you can create PHP Project in that folder with all the files included. Navigate to
Menu | File | New | Project From Existing Code ...
(Note availability of this feature depends on Visual Studio edition) and walk through the wizard steps.
Importing Local Files to a Project
If you already have a project, you can add existing files. See New PHP project from scratch for more information.
Project From Existing Code Menu
Open
File
|
New
|
Project From Existing Code...
(if available).
Then select PHP and click Next >
This will display the following wizard. Choose a name for your new project, the root folder containing the existing code, and a filter to ignore specific file types.
Click Finish, Visual Studio will create a new project (
.phpproj
) in the folder you specified, containing all the files within this folder.
In case your folder contains
composer.json
file and you are missing the required packages defined in the file, the following dialog will appear, asking for your permission to download the package into your project.
Editing a PHP File
PHP Tools provides Visual Studio with a smart editor of PHP files.
This allows you to work with great overview of your code, taking advantage of navigation bar, outlining, syntax highlighting; even with PHP, HTML, JavaScript or CSS mixed together, smart auto-completion Ctrl+Space taking into account the current code context, tooltip assistance, help integration F1, jump to definition F12 and live error underlining helping you to build error-free code.
Built-in code snippets help you to write code fast avoiding typos. You can insert a code snippet Ctrl+K,X like new function body, for loop, try/catch construct and more to speed up your development. Newly inserted snippet is automatically formatted and cursor position moved directly inside the new code so you can type your code instantly. Moreover selected area of a code can be surrounded by a snippet Ctrl+K,S to avoid the need of copy-pasting and other refactoring.
Getting to know the IDE
The Visual Studio main window is divided into several areas – menu bar, status bar, editor area, side panel containing the Solution Explorer, and various toolbars. All the positions can be changed. The following image describes the default layout.
When you launch Visual Studio, you are welcomed with the Start Page. This allows you to open recent projects or create new ones quickly.
When a project is opened, you can see the files that are a part of the project in the Solution Explorer. The Solution Explorer allows you to manage, search and open files, their properties and the project properties.
The editor area contains opened files. It allows you to see and modify the content, and take advantage of advanced IntelliSense features, navigation features, syntax highlighting, live error detection and more.
PHP in Visual Studio
PHP is one of the most popular programming languages for server-side web development. It’s used in many frameworks and CSMs like WordPress, Laravel, Symfony, and others which are behind a sizable chunk of the Internet.
Visual Studio is a powerful IDE, but its focus didn’t align with some languages, PHP being one of them. As time progressed more languages found their way to Visual Studio, like Python and eventually PHP. A Prague-based company called DEVSENSE developed an extension called PHP Tools for Visual Studio which has been available in the Visual Studio ecosystem for over a decade.
Since its inception PHP Tools for Visual Studio was a paid extension, offering a free trial. Now, that’s changed. DEVSENSE is releasing a big part of their offering as a free extension, leaving some features as paid ones. That allows PHP developers to work in Visual Studio and take advantage of all the great stuff which is available.
That means developers will get IntelliSense, formatting, project system, on-the-fly code analysis, composer (PHP dependency management) integration and other advanced editor-related features for free. In the latest version, PHP Tools support PHP 8.2 which hasn’t been released officially yet, and other things like generics which are a must-have for frameworks like Laravel. Other features like debugging, refactoring, unit testing, and code lens are available in the premium offering. The detailed comparison matrix can be found at https://www.devsense.com/purchase
Linting
VS Code uses the official PHP linter (
php -l
) for PHP language diagnostics. This allows VS Code to stay current with PHP linter improvements.
Tip: Using XAMPP? Install the full version of PHP in order to obtain the development libraries.
There are three settings to control the PHP linter:
-
php.validate.enable
: controls whether to enable PHP linting at all. Enabled by default. -
php.validate.executablePath
: points to the PHP executable on disk. Set this if the PHP executable is not on the system path. -
php.validate.run
: controls whether the validation is triggered on save (value:
"onSave"
) or on type (value:
"onType"
). Default is on save.
To change the PHP settings, open your User or Workspace Settings (⌘, (Windows, Linux Ctrl+,)) and type ‘php’ to filter the list of available settings.
To set the PHP executable path, select the Edit in settings.json link under PHP > Validate: Executable Path, which will open your user
settings.json
file. Add the
php.validate.executablePath
setting with the path to your PHP installation:
Windows
{ "php.validate.executablePath": "c:/php/php.exe" }
Linux and macOS
{ "php.validate.executablePath": "/usr/bin/php" } or { "php.validate.executablePath": "/usr/local/bin/php" }
Keywords searched by users: visual studio php project
Categories: Phát hiện thấy 77 Visual Studio Php Project
See more here: kientrucannam.vn
See more: https://kientrucannam.vn/vn/