Run php on vs code

Run php on vs code

Run php on vs code

1) Download and Install XAMPP

You can find the XAMPP installer on the following permalink:
https://www.apachefriends.org/index.html

2) Create a new project/folder

Go to the xampp\htdocs folder and create a new folder (with your project name)

3) Create a PHP file inside the project folder

Open vs code in the project folder and create a new PHP file with a .php extension (i.e FileName.php) with the following code

Run php on vs code

4) Open XAMPP Control Panel and start Apache server.

Run php on vs code

5) Open the browser and search localhost/FolderName/FileName.php

Run php on vs code

Congratulations you have successfully created and run your first PHP code using visual studio code🎉.

You can also check my youtube video “how to run PHP in Visual Studio Code in 2021” if any doubt.👇

Run php on vs code

Run php on vs code
+
Run php on vs code

Overview

According to a 2019 Survey from StackOverflow, Microsoft’s Visual Studio Code is the most popular Code Editor for Developers. It can be installed for free on Windows, Mac, and Linux and includes built-in support for PHP with features such as syntax highlighting and IntelliSense (code completion).

Several widely used plugins are recommended here for development with PHP.

https://code.visualstudio.com/

Run php on vs code

PHP Server Extension

When you install PHP on your computer you can then use the PHP Server extension with VS Code to launch a site. It works perfectly with FastSitePHP, simply right-click on the [index.php] file and select [PHP Server: Serve Project] or click on the PHP Server icon in the upper-right corner of the screen.

https://marketplace.visualstudio.com/items?itemName=brapifra.phpserver

Run php on vs code

You will then see FastSitePHP launch (or the starter site) in your default browser.

Run php on vs code

Code Runner Extension

https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

With Code Runner you can run PHP files, JavaScript files, Python files or scripts from over 30 other languages. Simply right-click on the file and select [Run Code] or click the [Run] button in the upper-right corner of the screen.

Run php on vs code

Console output will be displayed in the pane below your code. It’s much easier to copy content from here than a terminal or command prompt and you don’t have to switch back and forth between a terminal window for running scripts.

Run php on vs code

Additional Extensions

Find more here:

https://code.visualstudio.com/docs/languages/php

Updating Syntax Color for easier to read PHP tags in PHP templates

By default PHP tags <?php, <?, ?> will be the same color as HTML which can make them hard to read if you are using PHP Templates for server side rendering.

This can be easily changed in the settings. Search for tokenColorCustomization and then add the following snippet. If you would like a different color or font style simply update the JSON settings.

"editor.tokenColorCustomizations": {
    "textMateRules": [{
        "scope": [
            "punctuation.section.embedded.begin.php",
            "punctuation.section.embedded.end.php"
        ],
        "settings": {
            "foreground": "#bbbb03",
            "fontStyle": "bold"
        }
    }]
},

Can I run 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.

How can I run PHP file in Visual Studio Code without xampp?

There is a much easier way to run PHP, no configuration needed:.
Install the Code Runner Extension..
Open the PHP code file in Text Editor. use shortcut Ctrl+Alt+N. or press F1 and then select/type Run Code , or right click the Text Editor and then click Run Code in editor context menu..

How do I run PHP code?

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

How set PHP executable path in VS Code?

Everytime that I open VSCode I get this message: Cannot validate since no PHP executable is set. Use the setting 'php..
Go To System Properties..
Go To Advanced Tab..
Click "Environment Variables".
Select Path..
Add a new path that points to your php 7 executable:.