Getting Started with PHP
PHP is fully supported on Devboxes and Repositories. It leverages Docker to run a configurable PHP container, while also bringing LSP support through Intelephense, which includes auto-formatting, auto-linting and type definitions.
In this tutorial, we will showcase two different approaches you can use to get started with PHP in CodeSandbox: starting from a template or importing an existing PHP project.
Starting from a template
CodeSandbox provides a growing collection of PHP templates that may be useful depending on your use case.
In case you want a fresh, blank environment to start building a project from scratch, you can use our PHP starter (opens in a new tab). Otherwise, you will find our existing PHP templates in the template library (opens in a new tab).
After forking one of these templates, you can open a terminal (which you can find under DevTools, on the top right) to run php
commands.
Importing an existing repository
You can also import one of your existing PHP repositories from GitHub into CodeSandbox by following the steps below.
1. Import repository
From the CodeSandbox dashboard, click "Import from GitHub" and input the URL of your repository. If you are missing the required permissions, you should get a prompt asking you to update them.
2. Rebuild the container
As mentioned above, CodeSandbox relies on a Dockerfile to run PHP.
After importing your repository, you won't be able to immediately run php
commands. First, you need to rebuild the container.
To do that, open any .php
file and you will see a prompt appear, asking if you want to create a Dockerfile. Click "Create Dockerfile".
CodeSandbox will create this file and set up PHP. The first time when you do this step, it can take a while. However, after this setup, we will create a memory snapshot of the VM, which will ensure that the following VM loads (& clones!) will be fast.
3. Use the container
Now that the container has been built, all your new terminal sessions will be executed from inside this container, which is running PHP. You can test this by opening a new terminal, and verifying that php
is installed.
If this is your first time using CodeSandbox, keep reading on how to set up your sandbox or repository.