18 August 2015

My personal development environment runs on Arch Linux, and I had a lot of trouble getting it set up how I wanted. It’s the same setup as ones like Chris Mallison’s (for OS X) and Bruno de Bundt’s (for Ubuntu), but the process for setting it up on Arch is somewhat different. I used parts of each of their guides, and they certainly deserve some credit for this guide as well.


Run the following command:

$ pacman -S apache php php-apache dnsmasq mariadb

That will get you all the packages you need for the whole installation.1


In /etc/httpd/conf/httpd.conf, there are some things you need to change. Uncomment the lines: 2

Include conf/extra/httpd-vhosts.conf
LoadModule vhost_alias_module modules/mod_vhost_alias.so

Comment out the following block:

<Directory />
    AllowOverride none
    Require all denied

If you want to store your sites somewhere other than /srv/http, replace /srv/http in the line DocumentRoot "/srv/http" with the address at which you’d like to store your sites. On the line below, change where it says /srv/http to whatever you just changed your DocumentRoot to. For instance, I store my sites in ~/development/sites, so I would replace /srv/http with /home/jesse/development/sites.

Note: If the place that you’re changing your DocumentRoot to is inside your home directory, do not use the ~ character, but instead use the extended /home/<user> notation.

Delete or comment out everything in /etc/httpd/conf/extra/httpd-vhosts.conf, and replace it with this:

<Directory "/srv/http">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all

<Virtualhost *:80>
    VirtualDocumentRoot "/srv/http/%1/htdocs"
    ServerName sites.dev
    ServerAlias *.dev
    UseCanonicalName Off

If you changed your DocumentRoot, make sure to change the /srv/http parts of both Directory and VirtualDocumentRoot in the vhost configuration above to whatever you set your DocumentRoot to. So again, I would replace <Directory "/srv/http"> with <Directory "/home/jesse/development/sites">, and VirtualDocumentRoot "/srv/http/%1/htdocs" with VirtualDocumentRoot "/home/jesse/development/sites/%1/htdocs".

Once we have set up dnsmasq, this vhost configuration will make it so that any site placed in the DocumentRoot will be accessible by going to sitename.dev in the browser. The end of the path in VirtualDocumentRoot is the directory in which your site files will be stored. For instance, your index.html file for the site called sitename would be located at /your/document/root/sitename/htdocs/index.html. You can change the htdocs folder to be whatever you want, but it’s traditionally either htdocs or wwwroot.


Uncomment these lines in /etc/httpd/conf/httpd.conf, or create them at the end of the list of LoadModule calls if they don’t already exist:

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
LoadModule php5_module modules/libphp5.so

Comment out this line:

LoadModule mpm_event_module modules/mod_mpm_event.so

At the end of the list of Include statements, just after the block for configuring mod_proxy_html, add the line:

Include conf/extra/php5_module.conf

If you would like pages other than index.html to be able to act as the index page of a site, edit the line:

DirectoryIndex index.html

and change it to something like

DirectoryIndex index.html index.php

You can add as many different index pages as you want.

Open up /etc/php/php.ini. If you changed your DocumentRoot in /etc/httpd/conf/httpd.conf, add it to open_basedir like so:


If you didn’t change your DocumentRoot, you can leave open_basedir as is.


Uncomment one or both of the following lines in /etc/php/php.ini:

extension = pdo_mysql.so
extension = mysqli.so

If you haven’t used or set up MySQL/MariaDB before, run the following commands:

$ mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
systemctl start mysqld.service
systemctl enable mysqld.service
$ mysql_secure_installation

For the mysql_secure_installation command, set your root MySQL password, and then answer Y to all the prompts until the program exits.


At the end of /etc/dnsmasq.conf, add the following lines:


In /etc/resolv.conf.head (which you may have to create), add this line:


Finishing Up

Run these commands:

$ systemctl restart httpd
$ systemctl restart dnsmasq
$ systemctl restart dhcpcd

You should be good to go! To test your configuration, go to your DocumentRoot and run:

$ mkdir -p test/htdocs
$ echo "<?php phpinfo(); ?>" > index.php

In your browser, go to test.dev and you should see the PHP info page printed out. Go forth and create sites to your heart’s content!

MariaDB is a community-developed fork of MySQL, made by the developers of MySQL to make sure there is always a version of MySQL freely available.

For the purposes of this article, a line is uncommented by removing the # from the beginning of the line. So, # Include bla_bla bla becomes Include bla_bla bla.

blog comments powered by Disqus