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
composer
global path withexport PATH="$PATH:$HOME/.config/composer/vendor/bin" >> ~/.zshrc
. - Configure
phpactor
to auto-load global packages:Create file
~/.config/phpactor/phpactor.yml
and 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.el
to use their interfaces in Emacs. Configure
config.el
as 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 sync
and restart the Emacs.
3. Usage
- Use
M-x lsp-describe-session
to verifyphpactor
is in use. - Use
M-x php-cs-fixer-fix
to format the current PHP buffer. - Use
M-x phpunit-current-test
to run the tests in the current buffer.