- 1 Original Document
- 2 Preface
- 3 Part I: Install the base system
- 4 Deciding on the Arch installation
- 5 Part II: Deciding what you need
- 6 LAMP
What is a web server?
If you are reading this guide, there is a fair chance that you already know the answer to this question. However, there is also the possibility that you simply stumbled on this guide and don't know exactly what a server is. Hence, before we get into the actual construction of an Arch server, we will go over exactly what a server is.
Simply put, a server is a computer (or a specific program) that provides services to other computers or programs. In the specific confines of this guide, we are refering to the construction of a computer that provides web-based services to other computers.
Types of servers include:
- Web (HTTP) servers
- File (FTP, SAMBA, NFS, etc.) servers
- Email servers
- DNS servers
- DHCP Servers
- IRC Servers
- Time Servers
- Media servers
- and many more...
So do I need a server?
It depends, many users (even some who have comprehensive web sites) are quite happy with having basic web hosting. It tends to be cheaper than obtaining a dedicated server, and if something goes wrong it is the hosts responsibility to fix it rather than yours. On the other hand, some people would like more control than basic hosting allows, or may find that they require a feature or application that is not permitted by their provider. In cases such as this, a dedicated server becomes much more appealing. Regardless, before obtaining a dedicated server (or setting up your home computer as a web server), it is important that the user understand a few things.
- Setting up a server requires time and dedication, there is no one-click-and-it-works system.
- You will have issues at some point in time that make you question your decision.
- You will learn more than you ever wanted to know about servers (and quite possibly Linux in general).
If you haven't abandoned hope yet, than please read on and we'll see if we can assist you in successfully building your server!
Part I: Install the base system
Setting up Arch Linux
For the purposes of this guide, we will assume that you already have successfully built a basic Arch system. If you do not have Arch set up yet, please refer to the Beginners Guide or the Official Install Guide as that is outside the scope of this guide.
Deciding on the Arch installation
Tip: If you aren't sure which guide to follow the beginners guide includes building a desktop (necessary if you are using services that require a GUI) the official install guide just explains how to install a 'text version' of arch, i.e. you will need to run everything from command line; this is fine if you are just running an ftp server for example or are an expert user with no GUI requirements.
Part II: Deciding what you need
Basic web server
If all you are looking for is a simple web server, than your best bet is probably what is known as a LAMP stack. A LAMP stack is a bundle of software that provides the basic necessities for running a simple webserver (LAMP stands for Linux Apache MySQL and PHP).
Full web server
If you require a more inclusive solution, than your best bet is probably to start with a LAMP stack, and build from there. You may also require servers to handle email or ftp access. These will be discussed in depth later in the guide.
This section describes how to set up a simple web server on an Arch Linux system. The combination of applications we will be installing is commonly referred to as LAMP (Linux Apache MySQL PHP).
# pacman -S apache php mysql
This document assumes you will install Apache, PHP and MySQL together. If desired however, you may install Apache, PHP, and MySQL separately and simply refer to the relevant sections below. Template:Box Note
- Create the user http (this account may already exist):
# useradd http
- Add this line to
/etc/hosts(if the file doesn't exist, create it):
127.0.0.1 localhost.localdomain localhost
Note: If you want a different hostname, append it to the end:
127.0.0.1 localhost.localdomain localhost myhostname
/etc/rc.conf: If you set a hostname, the HOSTNAME variable should be the same; otherwise, use "localhost":
# # Networking # HOSTNAME="localhost"
/etc/httpd/conf/httpd.confas root and comment the following module:
LoadModule unique_id_module modules/mod_unique_id.so
It should now appear as:
#LoadModule unique_id_module modules/mod_unique_id.so
- Run the following in a terminal as root to start the http server:
# /etc/rc.d/httpd start
- Apache should now be running. Test by visiting http://localhost/ in a web browser. It should display a simple Apache test page.
- To start Apache automatically at boot, edit
/etc/rc.confas root and add the httpd daemon:
DAEMONS=(... httpd ...)
Or add this line to
- If you want to use user directories (i.e.
~/public_htmlon the machine is accessed as
http://localhost/~user/) to be available on the web, uncomment the following lines in
<Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch ExecCGI <Limit GET POST OPTIONS PROPFIND> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS PROPFIND> Order deny,allow Deny from all </LimitExcept> </Directory>
You must make sure that your home directory permissions are set properly so that Apache can get there. Your home directory and
~/public_html/ must be executable for others ("rest of the world"). This seems to be enough:
$ chmod o+x ~ $ chmod o+x ~/public_html
There may be some other, more-secure ways of setting the permissions by creating a special group and allowing only Apache and you to enter there... You know how paranoid you are.
These options in /etc/httpd/conf/httpd.conf might be interesting for you:
# Listen 80
This is the port Apache will listen to. For Internet-access with router, you have to forward the port.
# ServerAdmin email@example.com
This is the admin's email-address which can be found on error-pages e.g.
# DocumentRoot "/srv/http"
This is the directory where you should put your web pages. Change it, if you want to, but don't forget to change the
to whatever you changed your DocumentRoot to.
PHP is practically available out of the box now.
- Add these line in
LoadModule php5_module modules/libphp5.so Include conf/extra/php5_module.conf
NOTE: The "Include" can not be directly after the "LoadModule" line in the configuration file, it need to be down with the other "Includes".
LoadModule php5_module /usr/lib/httpd/modules/libphp5.so AddHandler php5-script php
- Remember to add a file handler for .phtml if you need it in /etc/httpd/conf/extra/php5_module.conf:
DirectoryIndex index.php index.phtml index.html
- If you want the libGD module, uncomment in
Pay attention to which extension you uncomment, as this extension is sometimes mentioned in an explanatory comment before the actual line you want to uncomment.
- If your
DocumentRootis outside of
/home/, add it to
open_basedir = /home/:/tmp/:/usr/share/pear/:/path/to/documentroot
suggestion - Add your document root as follows: open_basedir = /home/:/tmp/:/usr/share/pear/:/srv/http
- Restart the Apache service to make changes take effect (as root):
# /etc/rc.d/httpd restart
- Test PHP with a simple, but very informative script:
<html> <head> <title>PHP Test Page</title> </head> <body> This is Arch Linux, running PHP. <?php phpinfo(); ?> </body> </html>
Save this file as
test.php and copy to
/srv/http/ or to
~/public_html if you permitted such a configuration.
If you continue to have problems, edit your /etc/httpd/conf/httpd.conf file with the following information
- Edit your httpd.conf file
# nano /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
- Restart Apache
# /etc/rc.d/httpd restart
Be sure to test the page again to verify it's working properly (as stated above).
- Configure MySQL as described at the MySQL wiki.
/etc/php/php.ini(this is in
/usr/etcon older systems) to uncomment the following line (By removing
- You can add minor privileged users for your web scripts by editing the tables found in the
mysqldatabase. You have to restart MySQL for changes to take effect. Don't forget to check the
mysql/userstable. If there's a second entry for root and your hostname is left with no password set, everybody from your host probably could gain full access. Perhaps see next section for these jobs.
- Run in terminal (as root):
# /etc/rc.d/mysqld start
- MySQL should now be running. Test by visiting
http://localhost/phpMyAdminin a web browser - for testing by phpMyAdmin, you should have installed phpMyAdmin (
pacman -S phpmyadmin). It should display phpMyAdmin main page.
/etc/rc.conf(to start MySQL at boot):
DAEMONS=(... mysqld ...)
Or add this line to
- You can get the "
error no. 2013: Lost Connection to mysql server during query" message instantly whenever you try to connect to the MySQL daemon by TCP/IP. This is the TCP wrappers system (tcpd), which uses the
hosts_access(5)system to allow or disallow connections.
- If you're running into this problem, be sure to add this to your /etc/hosts.allow file:
# mysqld : ALL : ALLOW # mysqld-max : ALL : ALLOW # and similar for the other MySQL daemons.
- Notes: The examples above are the simplest case, telling tcpd to allow connections from anywhere. You may wish to use a more-appropriate choice of permissible sources instead of ALL. Just make sure that localhost and the IP address (numeric or DNS) of the interface by which you connect are specified.
- You might also need to edit
/etc/my.cnfand comment out the
skip-networkingline as such: