Linode Library Home
Linode Library RSS Feed
Home :: LAMP Guides
Print View View Source

LAMP Server on Arch Linux

Published: by


This document is an older, unmaintained guide. There may be a new guide available for this software.

Arch Linux is a contemporary minimalist Linux distribution that emerged in 2002 in an effort to provide a modern, lightweight, and cleanly designed distribution of a Linux operating system. Arch uses a rolling release system, which means that after running system updates all systems are running the same version of Arch Linux

As a result, Arch Linux is a great distribution for users who would like to, or need to, run the most up to date versions of various software packages and libraries. Because of its minimalist underpinnings and focus on simplicity, many users find it easy to fully understand how Arch systems work and develop environments and applications on top of Arch Linux.

While Arch makes some sacrifices in the areas of usability and stability for simplicity and "freshness," it's still a great system for people who like to enjoy total control of their server. Arch also offers a lot to those who want to manage the most up to date software, as it provides a clean and coherent package management tool. It's great for people who want to learn more about the inner workings of a Linux system.

As a means of introducing you to the Arch Linux system, we provide this guide which contains step by step instructions for installing a full-featured LAMP stack on an Arch Linux system. This guide is authored against a post-2009.08 release of Arch Linux. In this guide, you will be instructed on setting up Apache, MySQL, and PHP. If you don't feel that you will need MySQL or PHP, please don't feel obligated to install them.


Set the Hostname

Before you begin installing and configuring the components described in this guide, please make sure you've followed our instructions for setting your hostname. Issue the following commands to make sure it is set properly:

hostname -f

The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).

Install and Configure the Apache Web Server

The Apache Web Server is a very popular choice for serving web pages. While many alternatives have appeared in the last few years, Apache remains a powerful option that we recommend for most uses.

Make sure your system's package database is up to date by issuing the following command:

pacman -Sy

To install the current version of the Apache web server (in the 2.x series) use the following command:

pacman -S apache

Configurations directives for Apache are contained in the httpd.conf file, which is located at /etc/httpd/conf/httpd.conf. We advise you to make a backup of this file into your home directory, like so:

cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup

There are additional Apache configuration files, which are included near the end of the httpd.conf file, and located in the /etc/httpd/conf/extra/ directory. You may also choose to include additional files in your Apache configuration using a similar syntax. Regardless of how you choose to organize your configuration files, making regular backups of known working states is highly recommended.

Enable Starting Apache at Boot

Unless configured to do so, Arch will not instruct Apache to start when the system boots or reboots. To ensure that this happens, we'll need to edit the DAEMONS=() entry in the /etc/rc.conf file to include httpd in the list of daemons to start at boot. Alternately, to achieve the same effect we can add the following line to the file /etc/rc.local:

File excerpt:/etc/rc.local

/etc/rc.d/httpd start

Prepare Apache for Virtual Hosting

Now we'll configure virtual hosting so that we can host multiple domains (or subdomains) with the server. These websites can be controlled by different users, or by a single user, as you prefer.

Begin by defining the default site. Edit the line that reads "DocumentRoot /srv/http" so that it reads:

File excerpt:/etc/httpd/conf/httpd.conf

DocumentRoot "/srv/http/default"

Edit the line that reads "<Directory "/srv/httpd">" so that it reads:

File excerpt:/etc/httpd/conf/httpd.conf

<Directory "/srv/httpd/default">

Now, uncomment (remove the leading # character) line that reads "Include conf/extra/httpd-vhosts.conf" near the end of the /etc/httpd/conf/httpd.conf file, like so:

File excerpt:/etc/httpd/conf/httpd.conf

Include conf/extra/httpd-vhosts.conf

All of the configuration for the specific virtual hosting setups will be combined in a single file called httpd-vhosts-vhost.conf, located in the /etc/httpd/conf/extra/ directory. Open this file in your favorite text editor, and we'll begin by setting up virtual hosts.

Configure Name-based Virtual Hosts

There are different ways to set up Virtual Hosts, however we recommend the method below. By default, Apache listens on all IP addresses available to it.

Now we will create virtual host entries for each site that we need to host with this server; we'll want to replace the existing VirtualHost blocks with ones that resemble the following. We'll use "" and "" as example sites.

File excerpt:/etc/httpd/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
     DocumentRoot /srv/www/
     ErrorLog /srv/www/
     CustomLog /srv/www/ combined
            <Directory />
               Order deny,allow
               Allow from all

<VirtualHost *:80>
     DocumentRoot /srv/www/
     ErrorLog /srv/www/
     CustomLog /srv/www/ combined
            <Directory />
               Order deny,allow
               Allow from all

Notes regarding this example configuration:

  • All of the files for the sites that you host will be located in directories that exist underneath /srv/http. You can symbolically link these directories into other locations if you need them to exist in other places.
  • ErrorLog and CustomLog entries are suggested for more fine-grained logging, but are not required. If they are defined (as shown above), the logs directories must be created before you restart Apache.

Before you can use the above configuration, you'll need to create the specified directories. You can do this with the following commands:

mkdir -p /srv/http/
mkdir /srv/http/

mkdir -p /srv/http/
mkdir /srv/http/

After you've set up your virtual hosts, issue the following command to run Apache for the first time:

/etc/rc.d/httpd start

Assuming that you have configured the DNS for your domain to point to your Linode's IP address, Virtual hosting for your domain should now work. Remember that you can create as many virtual hosts with Apache as you need.

Anytime you change an option in your httpd-vhosts.conf file, or any other Apache configuration directive, remember to reload the configuration with the following command:

/etc/rc.d/httpd reload

Install and Configure MySQL Database Server

MySQL is a relational database management system (RDBMS), and is a popular component in contemporary web development tool chains. It is used to store data for many popular applications, including WordPress and Drupal.

Install MySQL

The first step is to install the mysql-server package, which is accomplished by the following command:

pacman -S mysql

In Arch Linux this provides version 5.1.37 of MySQL. To start MySQL for the first time issue, the following command:

/etc/rc.d/mysqld start

Note that the MySQL configuration file is located at /etc/mysql/my.cnf; we need to edit it so that MySQL will listen to connections only on the loopback interface (localhost). Add the line "bind-address=" to the [mysqld] block.

File excerpt:/etc/mysql/my.cnf


You will also want to remove or comment out the line that reads skip-networking, so that MySQL can listen for connections over TCP only on the local interface (as many applications expect). At this point MySQL should be ready to configure and run.

Enable Starting MySQL at Boot

Unless configured to do so, Arch will not instruct MySQL to start when the system boots or reboots. To ensure that this happens, we'll need to edit the DAEMONS=() entry in the /etc/rc.conf file to include mysqld in the list of daemons to start at boot. Alternately, to achieve the same effect we can add the following line to the file /etc/rc.local:

/etc/rc.d/mysqld start

Configure MySQL and Set Up MySQL databases

After installing MySQL, it's recommended that you run mysql_secure_installation, a program that helps secure MySQL. mysql_secure_installation gives you the option to disable root logins from outside localhost, remove anonymous user accounts, and the option to remove the test database. Additionally, it allows you to set your root password. Run the following command to execute the program:


Next, we'll create a database and grant your users permission to use it. First, log in to MySQL:

mysql -u root -p

Enter MySQL's root password, and you'll be presented with a prompt where you can issue SQL statements to interact with the database.

To create a database and grant your users permissions on it, issue the following command. Note that the semi-colons (;) at the end of the lines are crucial for ending the commands. Your command should look like this:

create database lollipop;
grant all on lollipop.* to 'foreman' identified by '5t1ck';

In this example lollipop is the name of the database, foreman is the username, and 5t1ck is the user's password. Note that database usernames and passwords are only used by scripts connecting to the database, and that database user account names need not (and perhaps should not) represent actual user accounts on the system.

With that completed you've successfully configured MySQL and you may now pass these database credentials on to your users. To exit the MySQL database administration utility, issue the following command:


With Apache and MySQL installed, you are now ready to move on to installing PHP to provide scripting support for your web pages.

Installing and Configuring PHP

PHP makes it possible to produce dynamic and interactive pages using your own scripts and popular web development frameworks. Furthermore, many popular web applications like WordPress are written in PHP. If you want to be able to develop your websites using PHP, you must first install it.

Arch includes packages for installing PHP from the terminal. Issue the following command:

pacman -S php php-apache php-suhosin libmcrypt libtool

Once PHP is installed we'll need to tune the configuration file located in /etc/php/php.ini for more descriptive errors, logging, and better performance. These modifications provide a good starting point if you're unfamiliar with PHP configuration.

Make sure that the following values are set and relevant lines are uncommented (comments are lines beginning with a semi-colon (;)):

File excerpt:/etc/php/php.ini

display_errors = Off
log_errors = On
error_log = /var/log/php.log
max_execution_time = 300
memory_limit = 64M
register_globals = Off

We'll need to enable the PHP module in the /etc/httpd/conf/httpd.conf file by adding the following lines in the appropriate sections:

File excerpt:/etc/httpd/conf/httpd.conf

LoadModule php5_module modules/
Include conf/extra/php5_module.conf

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

With this completed, PHP should be fully functional.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Creative Commons License

This guide is licensed under a Creative Commons Attribution-NoDerivs 3.0 United States License.

Last edited by Sharon Campbell on Monday, October 7th, 2013 (r3837).