Skip to content

Instantly share code, notes, and snippets.

@theoboldalex
Last active October 17, 2025 19:23
Show Gist options
  • Select an option

  • Save theoboldalex/27d5b40dce9a8ad444494b0c4d1b3ef6 to your computer and use it in GitHub Desktop.

Select an option

Save theoboldalex/27d5b40dce9a8ad444494b0c4d1b3ef6 to your computer and use it in GitHub Desktop.
Setup PHP Intelephense with license on native NeoVim LSP

How to setup Intelephense with Neovim's native LSP and license key for PHP development

First, create a file called license.txt in $HOME/intelephense/license.txt and paste in your license key. Save that file.

Note

Another option is to create a file called licence.txt directly in $HOME. If you do this, you must name the file correctly (including the typo!)

Next we will want make sure we have intelephense installed on our host. There are numerous ways to do this. The most common is to use Mason but I opt to do a global install of the package with NPM.

sudo npm i intelephense -g

Now we can setup intelephense in our Nvim config. How you structure your files is up to you. I use the native LSP api built into NeoVim v0.12. In order to follow this guide, you must be on at least this version.

vim.diagnostic.config({ virtual_text = true })
vim.lsp.config('*', { root_markers = { ".git" } })
vim.lsp.enable({
    'php',
})

Now that we have enabled an LSP called php in our call to vim.lsp.enable, we need to create a file called php.lua in ./lsp. Neovim will look here for LSP config to load.

If you have a paid license, you will need to read the contents in and set the value of init_options.licenceKey to its value. Note again the typo in licence.

In the table that this file returns, we need to set the command to run when starting the LSP server, the filetypes that are relevant to the LSP so that Neovim knows when to start and attach to the server as well as any additional root markers that denote that we are in the context of a project that would need this LSP to attach.

This line in our init file, sets git repos as root markers for any LSP server but our php specific config adds composer.json to this table. Likewise, we might add package.lock when setting up a JavaScript LSP or .luarc.json when setting up our Lua LSP server.

local get_intelephense_license_key = function()
    local f = assert(io.open(os.getenv("HOME") .. "/intelephense/license.txt", "rb"))
    local content = f:read("*a")
    f:close()
    return string.gsub(content, "%s+", "")
end

return {
    cmd = { "intelephense", "--stdio" },
    filetypes = { 'php' },
    init_options = { licenceKey = get_intelephense_license_key() },
    root_markers = { "composer.json" }
}
@theoboldalex
Copy link
Author

I have updated the gist with some more up to date approaches. Thanks for the note about dropping a file directly in $HOME. I will stick with the extra function as it gives me more flexibility and lowers the risk of my exposing my license key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment