Skip to content

Create a Hello World in PHP

Prerequisites

The following prerequisites must be filled to run this service:

Steps

Create the project

  • Create a new folder for your project and open it in Visual Studio Code.
  • Add devcontainer configuration files by clicking on the bottom left corner of Visual Studio Code and selecting "Remote-Containers: Add Development Container Configuration Files...".
  • Select "PHP" in the list of available containers.
  • Select the latest version of PHP (8.2 at the time of this commit) in the list of available versions.

Your folder should look like that:

1
2
3
.
├── .devcontainer
   └── devcontainer.json

Create the index.php file

  • Create a new file named index.php in the root of your project.
  • Add the following code in the file:
<?php echo 'Hello World'; ?>

Your folder should look like that:

1
2
3
4
.
├── .devcontainer
   └── devcontainer.json
   index.php

Run the project

  • Open the command palette in Visual Studio Code by pressing Ctrl+Shift+P or Cmd+Shift+P.
  • Select "Remote-Containers: Reopen in Container".
  • Open the terminal in Visual Studio Code.
  • Run the following command to start the server:
php -S localhost:8080