Skip to content
Oct 20 / kkrizka

How To Install php-mode Without Root Privelages

I am a bit fan of the GNU/Emacs editor, and I use it for all my large scale development. One reason I like it is because of its ability to handle the formating, like automatic indentation and highlighting, of PHP files with the use of the php-mode package. However this package does not come with the default GNU/Emacs installation, so when I am using a public computer or editing the files directly on the web server, I do not get the comfort of that package. I cannot install it, because I do no have the write privileges to the default site-lisp file that contains all these packages. But luckily I can easily change the path site-lisp to another directory where I can place the needed file. I will provide step-by-step instructions on how to do this.

  1. Download the php-mode package version 1.2.0
  2. Create a new directory called site-lisp in the emacs.d directory located in your home directory. You can do that by issuing the following command:

    mkdir -p ~/.emacs.d/site-lisp

  3. Install the php-mode package that you downloaded in step 1 by moving it to this directory.

    tar -xvzf php-mode-1.2.0.tgz
    mv php-mode.el ~/.emacs.d/site-lisp

  4. Open the .emacs located in your home directory file using your favorite editor. This file contains all the definitions that are automatically loaded every time you start up emacs

    emacs ~/.emacs

  5. Insert the following lines into the .emacs file. The first will append your newly created site-lisp directory to the list of directories that contain emacs packages. The rest of the lines associate PHP files with the php-mode package, so it is automatically loaded.
    (setq load-path (cons "~/.emacs.d/site-lisp" load-path))
     
    (autoload 'php-mode "php-mode" "PHP editing mode" t)
    (add-to-list 'auto-mode-alist '("\.php\'" . php-mode))
    (add-to-list 'auto-mode-alist '("\.php5\'" . php-mode))
    (add-to-list 'auto-mode-alist '("\.php4\'" . php-mode))
    (add-to-list 'auto-mode-alist '("\.php3\'" . php-mode))

4 Comments

Leave a comment
  1. krpalospo / Jul 17 2008

    Hi, I tried install this mode in emacs for windows but didn’t work Please you can help me the error was:

    when it begin say that in the buffer

    An error has occurred while loading `c:/Documents and Settings/carpovmu/Datos de programa/.emacs’:

    Wrong number of arguments: cons, 4

    so I don’t know what i do ???

  2. ravishankar somasundaram / Aug 14 2009

    The above code which is to be placed in .emacs dosent work , and throws error because of the backtic operators used, use the below given code instead of step 5 in the above given tutorial.

    (add-to-list ‘load-path “/your/path/to/.emacs.d/site-lisp”)
    (autoload ‘php-mode “php-mode” “PHP editing mode” t)
    (add-to-list ‘auto-mode-alist ‘(“\.php[345]?\'” . php-mode))

    • Karol Krizka / Aug 16 2009

      Grr, stupid WordPress started converting my normal quotes into backticks. I fixed it now. Thanks for noticing!

      • ravishankar somasundaram / Sep 6 2009

        Oh, then i really wonder why didnt it convert my quotes to backtick 😉

        and think about publishing this line

        (add-to-list ‘auto-mode-alist ‘(”\.php[345]?\’” . php-mode))

        instead of your 4 add-to-list lines.

        anyways nice tutorial, i really appreciate the efforts.

Leave a comment
Cancel reply