Visual studio code run php file in browser

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.

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.

Visual studio code run php file in browser

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

Snippets

Visual Studio Code includes a set of common snippets for PHP. To access these, hit ⌃Space (Windows, Linux Ctrl+Space) to get a context-specific list.

Visual studio code run php file in browser

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

Visual studio code run php file in browser

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.

Debugging

PHP debugging with XDebug is supported through a PHP Debug extension. Follow the extension's instructions for configuring XDebug to work with VS Code.

Next steps

Read on to find out about:

  • Extension Marketplace - Browse the extensions others have shared
  • Debugging - Learn more about VS Code debugging

9/1/2022

I can't find a way to run php on Visual studio code, Does anyone know how?

Duplicate:

Yes it is but a little bit different from here.

Steps:

I followed below steps to configure php in VS Code.

  1. Configure PHP linting in user settings
    Visual studio code run php file in browser
  2. Install Php Debug extension in VSCode
  3. Then configure php.ini file
    Visual studio code run php file in browser
  4. Create a external php file in root folder
  5. add <? echo "My First PHP site in VSCode."; ?> in external php file which I created now
  6. In my index.html file I referenced my php file like:
    Visual studio code run php file in browser
  7. Run my web server apache using xampp control panel
  8. Build my project and run it on web browser it shows me nothing.
  9. Also when I open dev tools of my chrome browser its shows me my php code of index file commented. why? I don't know.
    Visual studio code run php file in browser

Question:

What I am doing wrong in my above steps to configure php in vs code. Please explain me in easy steps so I can easily achieve my goal. Thanks in advance.

asked Aug 21, 2016 at 19:08

Visual studio code run php file in browser

Ahmer Ali AhsanAhmer Ali Ahsan

5,09416 gold badges38 silver badges76 bronze badges

1

Looks like you in fact don't want to run PHP from Visual Code, but instead you're trying to get PHP to work at all.

  1. add in external php file which I created now

You're using short tags and that's ok, if your configuration allows it, however I would recommend using explicit PHP tags: <?php echo "My First PHP site in VSCode."; ?>

In my index.html file I referenced my php file like:

There's the problem. You're placing PHP code in a HTML file. PHP code in HTML files won't be (at least by default) executed. Change the filename from index.html to index.php.

That should do it.

answered Aug 23, 2016 at 12:38

Visual studio code run php file in browser

2

How do I run a PHP file in browser?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

How do you launch a file in a browser using Visual Studio Code?

In the Visual Studio Code Explorer, right-click on your new file. Select “Open Live Server.” The HTML file will open in the browser. Once it does, try to edit the HTML code.

Can I view PHP code in browser?

Web developers and others who are knowledgeable about web pages know you can use a browser to view the HTML source code of a website. However, if the website contains PHP code, that code is not visible, because all the PHP code is executed on the server before the website is sent to a browser.

How do I run a PHP script from a website?

You just follow the steps to run PHP program using command line..
Open terminal or command line window..
Goto the specified folder or directory where php files are present..
Then we can run php code using the following command: php file_name.php..