1---
2title: PHP
3description: "Configure PHP language support in Zed, including language servers, formatting, and debugging."
4---
5
6# PHP
7
8PHP support is available through the [PHP extension](https://github.com/zed-extensions/php).
9
10- Tree-sitter: [tree-sitter/tree-sitter-php](https://github.com/tree-sitter/tree-sitter-php)
11- Language Server: [phpactor/phpactor](https://github.com/phpactor/phpactor)
12- Alternate Language Server: [bmewburn/vscode-intelephense](https://github.com/bmewburn/vscode-intelephense/)
13
14## Install PHP
15
16The PHP extension requires PHP to be installed and available in your `PATH`:
17
18```sh
19# macOS via Homebrew
20brew install php
21
22# Debian/Ubuntu
23sudo apt-get install php-cli
24
25# CentOS 8+/RHEL
26sudo dnf install php-cli
27
28# Arch Linux
29sudo pacman -S php
30
31# check PHP path
32## macOS and Linux
33which php
34
35## Windows
36where php
37```
38
39## Choosing a language server
40
41The PHP extension uses [LSP language servers](https://microsoft.github.io/language-server-protocol) with Phpactor as the default. If you want to use other language servers that support Zed (e.g. Intelephense or PHP Tools), make sure to follow the documentation on how to implement it.
42
43### Intelephense
44
45[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/buy).
46
47Configure language servers in Settings ({#kb zed::OpenSettings}) under Languages > PHP, or add to your settings file:
48
49```json [settings]
50{
51 "languages": {
52 "PHP": {
53 "language_servers": ["intelephense", "!phpactor", "!phptools", "..."]
54 }
55 }
56}
57```
58
59To use the premium features, you can place your license file inside your home directory at `~/intelephense/licence.txt` for macOS and Linux, or `%USERPROFILE%/intelephense/licence.txt` on Windows.
60
61Alternatively, you can pass the licence key or a path to a file containing the licence key as an initialization option. To do this, add the following to your `settings.json`:
62
63```json [settings]
64{
65 "lsp": {
66 "intelephense": {
67 "initialization_options": {
68 "licenceKey": "/path/to/licence.txt"
69 }
70 }
71 }
72}
73```
74
75### PHP Tools
76
77[PHP Tools](https://www.devsense.com/) is a proprietary language server that offers free and premium features. You need to [purchase a license](https://www.devsense.com/en/purchase) to activate the premium features.
78
79Configure language servers in Settings ({#kb zed::OpenSettings}) under Languages > PHP, or add to your settings file:
80
81```json [settings]
82{
83 "languages": {
84 "PHP": {
85 "language_servers": ["phptools", "!intelephense", "!phpactor", "..."]
86 }
87 }
88}
89```
90
91To use the premium features, you can add your license in `initialization_options` in your `settings.json`:
92
93```json [settings]
94{
95 "lsp": {
96 "phptools": {
97 "initialization_options": {
98 "0": "your_license_key"
99 }
100 }
101 }
102}
103```
104
105or, set environment variable `DEVSENSE_PHP_LS_LICENSE` on `.env` file in your project.
106
107```env
108DEVSENSE_PHP_LS_LICENSE="your_license_key"
109```
110
111Check out the documentation of [PHP Tools for Zed](https://docs.devsense.com/other/zed/) for more details.
112
113### Phpactor
114
115Configure language servers in Settings ({#kb zed::OpenSettings}) under Languages > PHP, or add to your settings file:
116
117```json [settings]
118{
119 "languages": {
120 "PHP": {
121 "language_servers": ["phpactor", "!intelephense", "!phptools", "..."]
122 }
123 }
124}
125```
126
127## PHPDoc
128
129Zed supports syntax highlighting for PHPDoc comments.
130
131- Tree-sitter: [claytonrcarter/tree-sitter-phpdoc](https://github.com/claytonrcarter/tree-sitter-phpdoc)
132
133## Debugging
134
135The PHP extension provides a debug adapter for PHP via Xdebug. There are several ways to use it:
136
137```json
138[
139 {
140 "label": "PHP: Listen to Xdebug",
141 "adapter": "Xdebug",
142 "request": "launch",
143 "port": 9003
144 },
145 {
146 "label": "PHP: Debug this test",
147 "adapter": "Xdebug",
148 "request": "launch",
149 "program": "vendor/bin/phpunit",
150 "args": ["--filter", "$ZED_SYMBOL"]
151 }
152]
153```
154
155These are common troubleshooting tips, in case you run into issues:
156
157- Ensure that you have Xdebug installed for the version of PHP you're running.
158- Ensure that Xdebug is configured to run in `debug` mode.
159- Ensure that Xdebug is actually starting a debugging session.
160- Ensure that the host and port matches between Xdebug and Zed.
161- Look at the diagnostics log by using the `xdebug_info()` function in the page you're trying to debug.
162
163## Using the Tailwind CSS Language Server with PHP
164
165To get all the features (autocomplete, linting, etc.) from the [Tailwind CSS language server](https://github.com/tailwindlabs/tailwindcss-intellisense/tree/HEAD/packages/tailwindcss-language-server#readme) in PHP files, you need to configure the language server so that it knows about where to look for CSS classes by adding the following to your `settings.json`:
166
167```json [settings]
168{
169 "lsp": {
170 "tailwindcss-language-server": {
171 "settings": {
172 "includeLanguages": {
173 "php": "html"
174 },
175 "experimental": {
176 "classRegex": [
177 "class=\"([^\"]*)\"",
178 "class='([^']*)'",
179 "class=\\\"([^\\\"]*)\\\""
180 ]
181 }
182 }
183 }
184 }
185}
186```
187
188With these settings, you will get completions for Tailwind CSS classes in HTML attributes inside PHP files. Examples:
189
190```php
191<?php
192// PHP file with HTML:
193?>
194<div class="flex items-center <completion here>">
195 <p class="text-lg font-bold <completion here>">Hello World</p>
196</div>
197```
198
199### Laravel/Blade
200
201For Laravel/Blade files, you may need additional configuration to handle Blade directives:
202
203```json [settings]
204{
205 "lsp": {
206 "tailwindcss-language-server": {
207 "settings": {
208 "includeLanguages": {
209 "php": "html",
210 "blade": "html"
211 },
212 "experimental": {
213 "classRegex": [
214 "class=\"([^\"]*)\"",
215 "class='([^']*)'",
216 "class=\\\"([^\\\"]*)\\\"",
217 "@class\\(\\[([^\\]]*)\\]\\)"
218 ]
219 }
220 }
221 }
222 }
223}
224```
225
226This will also provide completions in Blade directives like:
227
228```blade
229{{-- Blade file --}}
230<div class="flex {{ $customClass }} <completion here>">
231 @class(['flex', 'items-center', '<completion here>'])
232</div>
233```