Apache Web Server on Debian 7 (Wheezy)
Updated by Linode Written by Linode
DeprecatedThis guide has been deprecated and is no longer being maintained.
The Apache HTTP Web Sever (Apache) is an open source web application for deploying web servers. This tutorial explains how to install and configure the Apache web server on Debian 7 (Wheezy).
Note that if you’re looking to install a full LAMP (Linux, Apache, MySQL and PHP) stack, you may want to consider using our LAMP guide for Debian 7.
NoteThis guide is written for a non-root user. Commands that require elevated privileges are prefixed with
sudo. If you’re not familiar with the
sudocommand, you can check our Users and Groups guide.
Before You Begin
- Make sure you’ve followed the Getting Started guide.
As part of the Getting Started guide, make sure you set the hostname for your server.
Issue the following commands to make sure your hostname is set properly:
hostname hostname -f
The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).
Update your system:
sudo apt-get update && apt-get upgrade
Install the Apache 2 web server, its documentation, and a collection of utilities:
sudo apt-get install apache2 apache2-doc apache2-utils
Edit the main Apache configuration file to adjust the resource use settings. The settings shown below are a good starting point for a Linode 2GB:
1 2 3 4 5 6 7 8 9 10 11
KeepAlive Off ... <IfModule mpm_prefork_module> StartServers 4 MinSpareServers 20 MaxSpareServers 40 MaxClients 200 MaxRequestsPerChild 4500 </IfModule>
Configure Apache for Virtual Hosting
Apache supports name-based virtual hosting, which allows you to host multiple domains on a single server with a single IP.
Disable the default virtual host:
sudo a2dissite default
Each virtual host needs its own configuration file in the
/etc/apache2/sites-available/directory. Create the file for example.com, called
/etc/apache2/sites-available/example.com.conf, with the following content. Be sure to replace example.com with your own domain name.
1 2 3 4 5 6 7 8
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/public_html/ ErrorLog /var/www/example.com/logs/error.log CustomLog /var/www/example.com/logs/access.log combined </VirtualHost>
If you would like to enable Perl support, add the following lines to the
VirtualHostentry, right above the closing
- > /etc/apache2/sites-available/example.com.conf
Options ExecCGI AddHandler cgi-script .pl
Create the directories for example.com’s website files and logs:
sudo mkdir -p /var/www/example.net/public_html sudo mkdir /var/www/example.net/logs
Enable the sites by issuing these commands:
sudo a2ensite example.com.conf
Restart the Apache server to initialize all the changes:
sudo service apache2 restart
Congratulations! You have now installed Apache on your Debian Linode and configured it for virtual hosting.
Apache Modules and Scripting
Install Apache Modules
One of Apache’s strengths is its ability to be customized with modules. The default installation directory for Apache modules is the
List the available modules:
sudo apt-cache search libapache2*
Install a module:
sudo apt-get install [module-name]
Modules, after being installed, should be enabled and ready to use, although you may need to apply additional configuration options depending on the module. Consult the Apache module documentation for more information regarding the configuration of specific modules.
Install Support for Scripting
The following commands install Apache support for server-side scripting in PHP, Ruby, Python, and Perl. Support for these languages is optional based on your server environment.
sudo apt-get install libapache2-mod-ruby
sudo apt-get install libapache2-mod-perl2
sudo apt-get install libapache2-mod-python
MySQL in Python support:
sudo apt-get install python-mysqldb
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.
Join our Community
This guide is published under a CC BY-ND 4.0 license.