Chuyển tới nội dung
Home » Php On Visual Studio 2017 | Prerequisites

Php On Visual Studio 2017 | Prerequisites

How to Run PHP Using Visual Studio Code

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.

Troubleshooting

PHP Tools cannot be found on VS Marketplace

The most probable cause is that you are running an older Visual Studio version. Please update to the latest VS version.

In Visual Studio, go to

Help

, and click

Check for Updates

. Then in Visual Studio Installer, click on

Update

.

If you see this message in the VSIX Installer log, it usually means you will need to update your Visual Studio.

You can see which VS version is a minimal supported version in the VSIX Installer log. There is a section specifying the supported VS version range:


26-7-2022 11:33:05 - Supported Products : 26-7-2022 11:33:05 - Microsoft.VisualStudio.Community 26-7-2022 11:33:05 - Version : [16.10,17.0)

In this case, the lowest supported version is

16.10

.

To see which Visual Studio version are you running, go to

Help

, and click

About Microsoft Visual Studio

:

If you see a version higher than the one from the VSIX Installer log, then please contact us at [email protected].

Otherwise please update your Visual Studio by opening

Help

menu and clicking

Check for Updates

. Then in Visual Studio Installer, click on

Update

.

Tiện ích mở rộng mới hỗ trợ lập trình PHP trong Visual Studio 2017

Ngoc Huynh

Một tiện ích mở rộng mới trong Visual Studio Tools Marketplace cung cấp hỗ trợ cho lập trình PHP làm việc với Visual Studio 2017.

Được cung cấp bởi Prague-based Devsense, tiện ích mới này hứa hẹn sẽ biến Visual Studio thành một môi trường phát triển PHP mạnh mẽ.

Cho tới thời điểm hiện tại VS 2017 có lượt tải về hơn hẳn so với các phiên bản trước 2010-2015. Hiện đã có sẵn bản dùng thử miễn phí, tuy nhiên chi tiết giá bản chính thức tới nay vẫn chưa được tiết lộ. Nhưng trên trang web của sản phẩm cho biết giấy phép dành cho cá nhân có giá $ 79 trong khi giấy phép thương mại là $ 149.

Nó hỗ trợ PHP phiên bản 7.1, 7.0, 5.6, 5.5 và 5.4, cung cấp IntelliSense, code completion, và hỗ trợ một số chức năng mới chẳng hạn như visual debug, một số hướng dẫn PHP tích hợp.

Tìm hiểu chi tiết về chức năng mới của PHP Tools cho Visual Studio tại đây

Chỉ trong tuần này, trong báo cáo thị trường cho biết: ” PHP Tool cho Visual Studio hoà nhập nhanh chóng vào Microsoft Visual Studio, với những tiện ích hỗ trợ cho PHP. Tiện ích mới giúp tăng hiệu suất của lập trình viên. Nó hiểu code, mang đến code completion thông minh, điều hướng nhanh, kiểm tra lỗi cú pháp, hướng dẫn PHP tích hợp, hệ thống dự án, hỗ trợ debug và hơn thế nữa. ”

Hiện tại PHP Tools cho Visual Studio đã được 2.259 lượt cài đặt, nhưng chỉ có 2 đánh giá 5.0 ( đánh giá cao nhất)

Nguồn bài viết : https://visualstudiomagazine.com

How to Run PHP Using Visual Studio Code
How to Run PHP Using Visual Studio Code

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 validation, code formatting, integrated PHP manual, built-in web server, debugging support, test explorer integration, 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.2 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 validation, code formatting, integrated PHP manual, built-in web server, debugging support, test explorer integration, 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.2 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 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

Basic Installation

You will need to have Microsoft Visual Studio installed before installing PHP Tools. You can download the free Community version here or use any other Visual Studio version, except for Express versions, which are not supported.

If you already have Microsoft Visual Studio installed, you can jump directly to the Manage Extensions dialog and search for PHP Tools for Visual Studio.

Once downloaded, you’ll be prompted to close Visual Studio. The package will be installed and Visual Studio configured for the PHP development. After starting Visual Studio next time, you can proceed to the product activation and get started.

If you would like more detailed steps, please, continue reading.

How to run PHP on Visual Studio Code
How to run PHP on Visual Studio Code

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.

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.

PHP in Visual Studio 2019 | Getting Started
PHP in Visual Studio 2019 | Getting Started

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" }

Code faster

Boost your productivity with our editor’s smart code analysis and fast preemptive code completion. Utilize a wide range of navigational features, have a localized manual at your fingertips, and easily perform quick refactoring actions. Experience the advantages of IntelliPHP, our on-machine AI assistant, which enables you to code more efficiently with less typing. Rest assured, your private code remains secure as IntelliPHP runs locally on your machine.

Create Your First PHP Project using XAMPP and Visual Studio Code 2021
Create Your First PHP Project using XAMPP and Visual Studio Code 2021

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.

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.

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.

How to run PHP in Visual Studio Code on Windows 10/11 [2024 Update] PHP Developers
How to run PHP in Visual Studio Code on Windows 10/11 [2024 Update] PHP Developers

Prerequisites

To install PHP Tools for Visual Studio, you’ll need:

  • Administrator access. Please ensure you can provide administrator access to your hard drive because the installation package copies files to the system’s AppData. For Visual Studio 2010 up to 2015, you’ll be queried to allow access to the system’s Program Files*.

  • Microsoft Visual Studio. Install Microsoft Visual Studio. You can choose the Community edition, which is the free** option, or any other Visual Studio´s supported editions, such as Professional, Enterprise or higher. Express editions are not supported.

Download and Installation

PHP Tools installation package can be downloaded from:

  • Visual Studio Marketplace – Choose PHP Tools edition according to the version of your Visual Studio.

  • DEVSENSE.com – You can download any version or any update of PHP Tools for Visual Studio directly from our WebSite.

Instructions for Installation

  1. Close Visual Studio
  2. Run the installation package downloaded from any of the locations above
  3. Follow the instructions on the screen.
  4. Restart Visual Studio.

The software’s installation package can also be used for an Offline Activation.

How to Run PHP in Visual Studio Code on Windows 10 [ 2021 Update ] VS Code + PHP [ PHP Developers ]
How to Run PHP in Visual Studio Code on Windows 10 [ 2021 Update ] VS Code + PHP [ PHP Developers ]

Testimonials

Awesome tool!

A Main Hobbies

What can I say? Exceeded my expectations in all ways!

GD Software

Absolutely fantastic! I have no hesitation in recommending this to any other PHP developer now or into the future. I have used numerous “PHP specific” IDEs in the past and have always wished they would share the comfort of developing in VS, with this extension it is made possible and has exceeded my expectations. No qualms in paying for the Professional version, in fact, I purchased it almost instantly. Congratulations DEVSENSE, job well done.

Fantastic tool, finally done by a group of people who are actually attentive and working to improve the experience. Highly recommended.

Well, I really have to say this, is without doubt the best PHP development plugin for Visual Studio.

Very great thing. Never had such a great debugging experience with PHP and Visual Studio. God thanks there is PHP tools, so I have all my favourite languages within my favourite IDE!

Just tried your debugging feature…AWESOME!!!!!!!

ANDRITZ AG

Great Extension. Switched from VS.php to PHP Tools. Also Great support here and in their own forum! Would be willing to pay even more then they charge now!

OMICRON electronics GmbH

One of the reasons why I never wanted to code in PHP was because I never found IDE with the same functionality/practice as I code in VS/C#. This tool is a game changer for me and especially I love the debugging features.

Closte LLC

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.

PHP Extensions For VSCode | How To Install PHP Extension In Visual Studio Code | Simplilearn
PHP Extensions For VSCode | How To Install PHP Extension In Visual Studio Code | Simplilearn

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.

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.

How to Run PHP using Visaul Studio Code with Xampp - [ VS Code 2023 PHP Setup ]
How to Run PHP using Visaul Studio Code with Xampp – [ VS Code 2023 PHP Setup ]

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 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.

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.

How to run PHP file on localhost XAMPP | open php file in browser
How to run PHP file on localhost XAMPP | open php file in browser

Keywords searched by users: php on visual studio 2017

Getting Started | Php Tools For Visual Studio Documentation
Getting Started | Php Tools For Visual Studio Documentation
Php In Visual Studio - Visual Studio Blog
Php In Visual Studio – Visual Studio Blog
Php Tools For Visual Studio - Visual Studio Marketplace
Php Tools For Visual Studio – Visual Studio Marketplace
How To Set Up WordPress Coding Standards In Visual Studio Code - Sridhar  Katakam
How To Set Up WordPress Coding Standards In Visual Studio Code – Sridhar Katakam
Hướng Dẫn Lập Trình Php Trên Visual Studio
Hướng Dẫn Lập Trình Php Trên Visual Studio
Hướng Dẫn Sử Dụng Visual Studio Code A-Z Toàn Tập
Hướng Dẫn Sử Dụng Visual Studio Code A-Z Toàn Tập
Php Tools For Visual Studio 2013 In Action - Youtube
Php Tools For Visual Studio 2013 In Action – Youtube
Tiện Ích Mở Rộng Mới Hỗ Trợ Lập Trình Php Trong Visual Studio 2017 - Trang  Chủ
Tiện Ích Mở Rộng Mới Hỗ Trợ Lập Trình Php Trong Visual Studio 2017 – Trang Chủ
Blog - Motoanhquoc.Vn
Blog – Motoanhquoc.Vn
Php Programming With Visual Studio Code And Apache Server - Youtube
Php Programming With Visual Studio Code And Apache Server – Youtube

See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *