• Home

Logo

Navigation
  • Home
  • Articles
    • Content Writing
    • Design
    • General
    • Internet Marketing
    • Social Media
    • Tools and Tips
    • Usability
    • Web Hosting Articles
  • Tutorials
    • AJAX Tutorials
    • ASP Tutorials
    • C# Tutorials
    • CGI and Perl Tutorials
    • CSS Tutorials
    • Flash Tutorials
    • HTML Tutorials
    • Illustrator Tutorials
    • Java Tutorials
    • JavaScript Tutorials
    • Linux Tutorials
    • Miscellaneous Tutorials
    • MySQL Tutorials
    • Photoshop Tutorials
    • PHP Tutorials
    • Python Tutorials
    • Wireless Tutorials
    • WordPress Tutorials
    • XML Tutorials
  • Scripts
    • AJAX Scripts
    • ASP Scripts
    • ASP.NET Scripts
    • CGI & Perl Scripts
    • Flash Scripts
    • Java Scripts
    • JavaScript Scripts
    • PHP Scripts
    • Python Scripts
    • Remotely Hosted
    • Tools and Utilities
    • XML Scripts
  • Answers
  • Online Services
  • Tools

How to Install Apache 2 on Linux

By Richard Laffers | on Dec 20, 2007 | 0 Comment
Linux Tutorials
  • Tweet
  • Share
  • Tweet
  • Share

Installing Apache 2 on Linux

This tutorial explains the installation of Apache web server,
bundled with PHP and MySQL server on a Linux machine. The tutorial is
primarily for SuSE 9.2, 9.3, 10.0 & 10.1, but most of the steps
ought to be valid for all Linux-like operating systems.

Apache 2 Installation

prerequisites

Before you begin, it is highly recommended
(though not inevitable) to create a system user and user group under
which your Apache server will be running.


# groupadd www
# useradd -g www apache2

What
is it good for? All actions performed by Apache (for instance your PHP
scripts execution) will be restricted by this user’s privileges. Thus
you can explicitly rule which directories your PHP scripts may read or
change. Also all files created by Apache (e.g. as a result of executing
your PHP scripts) will be owned by this user (apache2 in my case), and
affiliated with this user group (www in my case).

download source

Get the source from http://httpd.apache.org/download.cgi ( httpd-2.2.4.tar.gz ). These instructions are known to work with all 2.x.x Apache versions.

unpack, configure, compile

Go to the directory with the downloaded file and enter:


# tar -xzf httpd-2.2.4.tar.gz
# cd httpd-2.2.4
# ./configure --prefix=/usr/local/apache2 --enable-so --with-included-apr

The configure options deserve a little bit more of detail here. The most important --prefix option specifies the location where Apache is to be installed. Another commonly used option --enable-so turns on the DSO support, i.e. available modules compiled as shared objects can be loaded or unloaded at runtime. Very handy.

To compile some modules statically (they are always loaded, faster execution times), use --enable-module option. To compile a module as a shared object, use --enable-module=shared option.

For all available configuration options and their default values check the Apache documentation or type ./configure --help.

SSL support

To support secure connections, you need to specify --enable-ssl option when you run ./configure. In addition to that, you will also have to configure your httpd.conf file later.

Note: Make sure that openssl is installed on your system before you run ./configure with --enable-ssl. If not, download the latest version from http://www.openssl.org/source/ , unpack, configure, make, make install. You will also need to generate server certificate. Place server.crt and server.key into /etc/ssl/apache2/ directory and make them readable by Apache2.

configuration example

For example, to compile the mod_rewrite module statically and mod_auth_digest as a DSO, and to enable secure connections, enter:


# ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-auth-digest=shared --enable-ssl

Tip: If you are upgrading from older Apache version, you may want to copy config.nice
from the directory to which the previous version was unpacked (if
available) to where you unpacked the new Apache tarball file. Run ./config.nice instead of
./configure. This way all the previously used configure options will be applied to the new installation effortlessly.

Once you configured everything as you like, compile and install the software:


# make
# make install

edit httpd.conf

Before you start Apache server, edit the httpd.conf file according to your needs (the file is generously commented).


# vi /usr/local/apache2/conf/httpd.conf

I suggest the following changes (some of them may have already been set automatically) at the appropriate places inside httpd.conf (ignore "..."):


ServerRoot "/usr/local/apache2"
...


User apache2
Group www

...
DocumentRoot "/foo/path_to_your_www_documents_root"
...

Options FollowSymLinks
AllowOverride None

...
DirectoryIndex index.php index.html index.htm index.html.var

"apache2" and "www" are the user and user group I have previously created (see Prerequisites)

Apart from these, later you will probably want to specify detailed options for specific directories, load some DSO modules, setup virtual servers etc.

SSL support

If you wish to enable SSL for secure connections (assuming that you have configured Apache with --enable-ssl option – see above), add the following in the appropriate sections inside httpd.conf (ignore "..."; replace "laffers.net" with your own, and set the actual path to your server certificate and key file):

Listen 80
Listen 443
...

ServerName laffers.net:443
SSLEngine on
SSLCertificateFile /etc/ssl/apache2/server.crt
SSLCertificateKeyFile /etc/ssl/apache2/server.key
ErrorLog /usr/local/apache2/logs/error_log_laffers.net
TransferLog /usr/local/apache2/logs/access_log_laffers.net
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0

Note: In some newer distributions, httpd.conf is dissected into many additional files located in conf/extra. In that case, you may want to do the SSL settings from above inside the conf/extra/httpd-ssl.conf file. Don’t forget to uncomment "Include conf/extra/httpd-ssl.conf" in the httpd.conf file.

After you installed PHP (next part of this tutorial), few additional changes need to be done to httpd.conf (but they are usually made automatically during PHP installation).

setup access privileges

Don’t forget to setup Apache access privileges to your www directories:


# chown -R apache2:www /foo/path_to_your_www_documents_root
# chmod -R 750 /foo/path_to_your_www_documents_root

"apache2" and "www" are the user and user group I have previously created (see Prerequisites)

start and stop apache server

After everything is set up, start Apache:


# /usr/local/apache2/bin/apachectl start

Similarly, if you wish to stop Apache, type:


# /usr/local/apache2/bin/apachectl stop

automatic startup

It’s a good idea to let your Apache server start automatically after each system reboot. To setup Apache automatic startup, do:


# cp /usr/local/apache2/bin/apachectl /etc/init.d
# chmod 755 /etc/init.d/apachectl
# chkconfig --add apachectl
# chkconfig --level 35 apachectl on

further reading

  • Apache HTTP Server Version 2.2 Documentation
  • mod_ssl HowTo
Share this story:
  • tweet

Author Description

 

No Responses to “How to Install Apache 2 on Linux”

You must be logged in to post a comment.

Connect With Us

RSSSubscribe 1,241Followers 494Likes
  • Popular
  • Recent
  • Comments
  • Creating Energy Spheres in Photoshop

    Apr 15, 2008 - 96 Comments
  • Easy Screen Scraping in PHP with the Simple HTML DOM Library

    Aug 6, 2008 - 20 Comments
  • Calculating date difference more precisely in PHP

    Mar 7, 2008 - 13 Comments
  • When Does Hosting Your Website in the Cloud Make Sense?

    Oct 8, 2010 - 2 Comments
  • Fun with the Microsoft Managed Extensibility Framework Part 2

    Oct 6, 2010 - 0 Comment
  • Fun with the Microsoft Managed Extensibility Framework Part 1

    Sep 22, 2010 - 0 Comment
  • Website Management on the go with the iPad

    I appreciated your post, but I was looking for something I didn't...
    November 24, 2012 - drmoderator
  • Creating Energy Spheres in Photoshop

    I'm a little stuck down here especially at the step of creating the...
    November 23, 2012 - sarah
  • Running background processes in PHP

    Can you give an example? As see it, you can use this only when you...
    November 16, 2012 - Shaked Klein Orbach
Developer Resources
  • Tutorial Directory
  • Learn HTML
  • Learn PHP
  • Learn CSS
  • Learn AJAX
  • Learn JavaScript
  • Learn Pear
  • White Papers
  • Resources
    • NetVisits Web Directory
    • Realtor Pixels
    • Answers On The Run
    • Ask A Geek
  • Recent Posts

    • When Does Hosting Your Website in the Cloud Make Sense?
    • Fun with the Microsoft Managed Extensibility Framework Part 2
    • Fun with the Microsoft Managed Extensibility Framework Part 1
    • Website Management on the go with the iPad
    • Code Contracts in C# 4.0 – Part 1

    Calendar

    May 2013
    M T W T F S S
    « Oct    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  

    Recent Comments

    • drmoderator on Website Management on the go with the iPad
    • sarah on Creating Energy Spheres in Photoshop
    • Shaked Klein Orbach on Running background processes in PHP
    • Thomas Cuvillier on How To Upload Files Using PHP
    • rizal aditya on Extracting text from Word Documents via PHP and COM
    • Home
    © 2003 - 2013 DeveloperTutorials.com. All Rights Reserved. Privacy Policy.