Enabling php-mode and syntax highlighting in Emacs

Sometimes I am forced to edit PHP files outside Eclipse. Here’s a quick guide to make your text editor (in this case, Emacs) a little more user friendly by enabled php-mode and syntax highlighting.

First download php-mode and stick it in your ~/.emacs.d folder:

cd ~/.emacs.d
wget http://php-mode.svn.sourceforge.net/svnroot/php-mode/tags/php-mode-1.4.0/php-mode.el

Next paste the following code into your ~/.emacs file. This will enable php-mode and syntax highlighting. As you can see, I also added a default file extension for .module files.

(global-font-lock-mode 1)

(require 'php-mode)
(setq auto-mode-alist
  (append '(("\.php$" . php-mode)
            ("\.module$" . php-mode))

Now when you open .php or .module files, your code will be syntax highlighted and emacs will be tailored to editing PHP code. Screen shot:

syntax highlight

Updated: 2013-04-02

If you want to enable syntax highlighting on vim (mac osx):

Check out Tomorrow Theme (which I use primary with Sublime Text).

  1. Download the package and copy Tomorrow-Night.vim to /usr/share/vim/vim73/colors.

  2. Added a ~/.vimrc file with:

syntax on colo Tomorrow-Night

For Ubuntu:

sudo apt-get install php-elisp