Talk:Server

From ArchWiki
Revision as of 12:25, 17 December 2012 by Fengchao (Talk | contribs) (Part I: Install the base system: still exist in main page.)

Jump to: navigation, search

Original Document

Template:Box Note

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.

LAMP

Introduction

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).

Installation

# 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

Configuration

Apache

  • 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
  • Edit /etc/rc.conf: If you set a hostname, the HOSTNAME variable should be the same; otherwise, use "localhost":
#
# Networking
#
HOSTNAME="localhost"
  • Edit /etc/httpd/conf/httpd.conf as 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.conf as root and add the httpd daemon:
DAEMONS=(... httpd ...)

Or add this line to /etc/rc.local:

/etc/rc.d/httpd start
  • If you want to use user directories (i.e. ~/public_html on the machine is accessed as http://localhost/~user/) to be available on the web, uncomment the following lines in /etc/httpd/conf/extra/httpd-userdir.conf:
UserDir public_html

and

<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.

Advanced Options

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 sample@sample.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

<Directory "/srv/http">

to whatever you changed your DocumentRoot to.

PHP

PHP is practically available out of the box now.

  • Add these line in /etc/httpd/conf/httpd.conf
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".

Apache2:

LoadModule php5_module  /usr/lib/httpd/modules/libphp5.so
AddHandler php5-script php

http://dan.drydog.com/apache2php.html

  • 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 /etc/php/php.ini:
;extension=gd.so

to

extension=gd.so

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 DocumentRoot is outside of /home/, add it to open_basedir in /etc/php/php.ini as such:
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
  • Under <IfModule mime_module>
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).

MySQL

  • Configure MySQL as described at the MySQL wiki.
  • Edit /etc/php/php.ini (this is in /usr/etc on older systems) to uncomment the following line (By removing ;):
;extension=mysql.so
  • You can add minor privileged users for your web scripts by editing the tables found in the mysql database. You have to restart MySQL for changes to take effect. Don't forget to check the mysql/users table. 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/phpMyAdmin in a web browser - for testing by phpMyAdmin, you should have installed phpMyAdmin (pacman -S phpmyadmin). It should display phpMyAdmin main page.
  • Edit /etc/rc.conf (to start MySQL at boot):
DAEMONS=(... mysqld ...)

Or add this line to rc.local:

/etc/rc.d/mysqld start
  • 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.cnf and comment out the skip-networking line as such:
skip-networking

to

#skip-networking