Apache Web Server on Debian 7 (Wheezy)
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
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 withsudo
. If you’re not familiar with thesudo
command, you can check our Users and Groups guide.
Before You Begin
Make sure you’ve followed the Setting Up and Securing a Compute Instance 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 Apache
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:
- File: /etc/apache2/apache2.conf
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.- File: /etc/apache2/sites-available/example.com.conf
1 2 3 4 5 6 7 8
<VirtualHost *:80> ServerAdmin webmaster@example.com 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>
Note
If you would like to enable Perl support, add the following lines to the
VirtualHost
entry, right above the closing</VirtualHost>
tag:- File: > /etc/apache2/sites-available/example.com.conf
1 2
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 /etc/apache2/mods-available/
directory.
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.
To install:
Ruby support:
sudo apt-get install libapache2-mod-ruby
Perl support:
sudo apt-get install libapache2-mod-perl2
Python support:
sudo apt-get install libapache2-mod-python
MySQL in Python support:
sudo apt-get install python-mysqldb
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.
This page was originally published on