1# PHP
 2
 3PHP support is available through the [PHP extension](https://github.com/zed-extensions/php).
 4
 5- Tree-sitter: https://github.com/tree-sitter/tree-sitter-php
 6- Language Servers:
 7  - [phpactor](https://github.com/phpactor/phpactor)
 8  - [intelephense](https://github.com/bmewburn/vscode-intelephense/)
 9
10## Choosing a language server
11
12The PHP extension offers both `phpactor` and `intelephense` language server support.
13
14`phpactor` is enabled by default.
15
16### Phpactor
17
18The Zed PHP Extension can install `phpactor` automatically but requires `php` to be installed and available in your path:
19
20```sh
21# brew install php            # macOS
22# sudo apt-get install php    # Debian/Ubuntu
23# yum install php             # CentOS/RHEL
24# pacman -S php               # Arch Linux
25which php
26```
27
28### Intelephense
29
30[Intelephense](https://intelephense.com/) is a [proprietary](https://github.com/bmewburn/vscode-intelephense/blob/master/LICENSE.txt#L29) language server for PHP operating under a freemium model. Certain features require purchase of a [premium license](https://intelephense.com/).
31
32To switch to `intelephense`, add the following to your `settings.json`:
33
34```json [settings]
35{
36  "languages": {
37    "PHP": {
38      "language_servers": ["intelephense", "!phpactor", "..."]
39    }
40  }
41}
42```
43
44To use the premium features, you can place your [licence.txt file](https://intelephense.com/faq.html) at `~/intelephense/licence.txt` inside your home directory. Alternatively, you can pass the licence key or a path to a file containing the licence key as an initialization option for the `intelephense` language server. To do this, add the following to your `settings.json`:
45
46```json [settings]
47{
48  "lsp": {
49    "intelephense": {
50      "initialization_options": {
51        "licenceKey": "/path/to/licence.txt"
52      }
53    }
54  }
55}
56```
57
58## PHPDoc
59
60Zed supports syntax highlighting for PHPDoc comments.
61
62- Tree-sitter: [claytonrcarter/tree-sitter-phpdoc](https://github.com/claytonrcarter/tree-sitter-phpdoc)
63
64## Setting up Xdebug
65
66Zed’s PHP extension provides a debug adapter for PHP and Xdebug. The adapter name is `Xdebug`. Here a couple ways you can use it:
67
68```json
69[
70  {
71    "label": "PHP: Listen to Xdebug",
72    "adapter": "Xdebug",
73    "request": "launch",
74    "initialize_args": {
75      "port": 9003
76    }
77  },
78  {
79    "label": "PHP: Debug this test",
80    "adapter": "Xdebug",
81    "request": "launch",
82    "program": "vendor/bin/phpunit",
83    "args": ["--filter", "$ZED_SYMBOL"]
84  }
85]
86```
87
88In case you run into issues:
89
90- ensure that you have Xdebug installed for the version of PHP you’re running
91- ensure that Xdebug is configured to run in `debug` mode
92- ensure that Xdebug is actually starting a debugging session
93- check that the host and port matches between Xdebug and Zed
94- look at the diagnostics log by using the `xdebug_info()` function in the page you’re trying to debug