31 Jan 2025
Configure PHP with Doom Emacs on Arch Linux
This post records my steps of installing and configuring basic PHP with Doom Emacs and Arch Linux.
1. Terminal Installation
yay php: install PHP.yay composer: install PHP package manager.yay phpactor: install the language server.- Install the following packages with `composer` globally so any project can use it:
composer global require phpunit/phpunit: install PHP test framework.composer global require techlivezheng/phpctags: better code completion.composer global require friendsofphp/php-cs-fixer: code formatting.
- Export the
composerglobal path withexport PATH="$PATH:$HOME/.config/composer/vendor/bin" >> ~/.zshrc. - Configure
phpactorto auto-load global packages:Create file
~/.config/phpactor/phpactor.ymland write to file:composer.autoloader_path: - ~/.config/composer/vendor/autoload.php
2. Emacs Configuration
- Uncomment
(php +lsp)ininit.el. - Add packages
(package! phpactor)and(package! php-cs-fixer)topackages.elto use their interfaces in Emacs. Configure
config.elas following:(after! lsp-mode (setq lsp-disabled-clients '(intelephense php-ls)) ;; disable other language servers (setq lsp-php-server 'phpactor) ;; set the language explicitly (setq lsp-phpactor-path (executable-find "phpactor"))) (use-package! php-mode :hook (php-mode . lsp-deferred)) ;; defer lsp loading- run
doom syncand restart the Emacs.
3. Usage
- Use
M-x lsp-describe-sessionto verifyphpactoris in use. - Use
M-x php-cs-fixer-fixto format the current PHP buffer. - Use
M-x phpunit-current-testto run the tests in the current buffer.