Apache Web Server on Ubuntu 12.04 LTS (Precise Pangolin)
Updated by Linode Written by Linode
DeprecatedThis guide has been deprecated and is no longer being maintained.
The Apache HTTP Web Server (Apache) is an open source web application for running web servers. This guide explains how to install and configure an Apache web server on Ubuntu 12.04 LTS.
If instead you would like to install a full LAMP (Linux, Apache, MySQL and PHP) stack, please see the LAMP on Ubuntu 12.04 guide.
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 BeginPermalink
Ensure that you have followed the Getting Started and Securing Your Server guides, and the Linode’s hostname is set.
To check your hostname run:
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 && sudo apt-get upgrade
Install ApachePermalink
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:
- /etc/apache2/apache2.conf
Configure Virtual HostingPermalink
Apache supports name-based virtual hosting, which allows you to host multiple domains on a single server with a single IP. Although there are different ways to set up virtual hosts, the method below is recommended.
Disable the default Apache virtual host:
sudo a2dissite 000-default.conf
Create an
example.com.conf
file in/etc/apache2/sites-available
with your text editor, replacing instances ofexample.com
with your own domain URL in both the configuration file and in the file name:- /etc/apache2/sites-available/example.com.conf
Repeat this process for any other domains you host.
Note
Create directories for your websites and websites’ logs, replacing
example.com
with your own domain information:sudo mkdir -p /var/www/example.com/public_html sudo mkdir /var/www/example.com/logs
Enable the site:
sudo a2ensite example.com.conf
Restart Apache:
sudo systemctl restart apache2
Apache Mods and ScriptingPermalink
Install Apache ModulesPermalink
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 available Apache modules:
sudo apt-cache search libapache2*
Install any desired modules:
sudo apt-get install [module-name]
All mods are located in the
/etc/apache2/mods-avaiable
directory. Edit the.conf
file of any installed module if needed, then enable the module:sudo a2enmod [module-name]
To disable a module that is currently enabled:
a2dismod [module-name]
Install Support for ScriptingPermalink
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
PHP support:
sudo apt-get install libapache2-mod-php5 php5 php-pear php5-xcache
php5-suhosin
, for additional PHP security:sudo apt-get install php5-suhosin
PHP with MySQL:
sudo apt-get install php5-mysql
More InformationPermalink
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 CommunityPermalink
Find answers, ask questions, and help others.
This guide is published under a CC BY-ND 4.0 license.