Installing PHP on Arch

Now that apache is running on your Arch server you might want to add PHP support to it. Here's how.

Adding mod_php

Once you have a basic apache installation in place it might behoove you to install any modules and dependencies you know you'll need as well. For most users this will at least mean installing PHP. In this article we walk you through that process.

Install the PHP base

Let's start with an install of the basic PHP package:

sudo pacman -S php-apache

Pacman will want to nab some files to go with it, like the latest PHP package, which is good.

More PHP libraries

Your web application may require more than the basic PHP installation to function. In that case you'll want to find any required PHP libraries in pacman's repositories and install them.

To see what PHP modules are available try a:

pacman -Ss php-

Note the "-" at the end of "php". This will show any packages that start with "php-", along with a brief description.

If you want to get more information about one of the available packages, use pacman's "-Si" option to get details:

pacman -Si php-gd

The output will include a longer description of the package, the version of the library in the package, and more.

Once you've decided what extra PHP modules you need to install (if any), run "sudo pacman -S" with a list of modules as the arguments. As an example, here's a command to install several commonly-used PHP libraries at once (handy if you aren't sure what you'll need):

sudo pacman -S php-gd php-mcrypt php-memcache php-pspell php-snmp php-xsl

You may get a notice that a module installed a config file to the /etc/php/conf.d directory. The config files that get installed to that directory are set up so they do not enable the module by default. You need to uncomment the directive to load the extension by editing that file and removing the semicolon (";") from the beginning of the line starting with ";extension=".

The php.ini file

You may need to make changes to the php.ini file for your application. If so you can find the php.ini used by the apache module here:


The initialization files for additional PHP modules you may have installed should usually show up in this directory:


Including php5_module.conf

Now we need to tell apache to load the PHP module when it starts. Some steps have been done for us.

The config file that contains the directives we need has been installed to:


It's nice to have those written out for us already, but we need to put a reference to them into apache's main config file before it will use them. Edit the file:


Scroll down to the bottom of the file, then add the line:

Include conf/extra/php5_module.conf

Restart apache

You'll need to restart apache to get it to load the new module:

sudo /usr/sbin/apachectl graceful


With that, you have not just an apache web server, but one that runs PHP. Neat! Your work isn't done, however. In the next article we'll discuss apache's configuration files and where to find them, so you can start customizing apache for your slice.

  • -- Jered
Want to comment?

(not made public)


(use plain text or Markdown syntax)