Skip to content

Instantly share code, notes, and snippets.

@anandkkpr
Last active August 29, 2015 14:01
Show Gist options
  • Save anandkkpr/e46ecd68d9a7c7381c16 to your computer and use it in GitHub Desktop.
Save anandkkpr/e46ecd68d9a7c7381c16 to your computer and use it in GitHub Desktop.
Compiling on Ubuntu from Scratch: Apache
<head>
<style>
body {
color: #444;
font-size: 1.1em;
margin: 0 auto;
text-align: left;
max-width: 75%;
padding: 0 10px;
font-family: Georgia, "Times New Roman", serif; }
a {
color: blue;
text-decoration: none; }
a:hover {
text-decoration: underline; }
a:visited {
color: #555566; }
.post header {
font-size: 1.4rem; }
header {
font-size: 1.6rem;
text-align: center;
margin-top: 50px;
margin-bottom: 50px;
border-bottom: 1px solid #cccccc; }
header ul {
font-size: 1.4rem;
margin: 10px 0;
padding: 0; }
header ul li {
list-style-type: none;
display: inline;
padding: 0 5px; }
header ul li a:hover {
text-decoration: none; }
@media screen and (max-width: 500px) {
header ul li span {
display: none; } }
header h1 {
margin-bottom: 10px; }
header h2 {
font-size: 1.2rem;
margin-bottom: 20px; }
header a {
color: blue; }
header a:visited {
color: blue; }
header, h1, h2, h3, h4, h5, h6 {
font-weight: normal; }
.posts {
list-style-type: none;
margin-left: 0;
padding-left: 0; }
.posts h3 {
font-size: 1.8rem;
margin-bottom: 10px; }
.posts li {
margin-bottom: 40px; }
.posts li.link {
padding-left: 20px; }
.posts li.link h3 {
font-size: 1.4rem; }
.posts li.link h3 i {
color: #d9b54a;
padding-right: 5px; }
.posts li.link p {
margin-top: 5px; }
.posts p {
font-size: 1.7em; }
article h1 {
font-size: 1.8rem;
margin-bottom: 50px;
color: #111; }
article h2 {
font-size: 1.6rem;
border-bottom: 1px solid #cccccc;
color: #111;
margin-top: 50px; }
article h3 {
font-size: 1.4rem;
margin-top: 50px;
color: #111; }
article p, article li {
font-size: 1.4rem;
line-height: 1.5; }
article li {
margin-bottom: 15px; }
article blockquote {
color: #333;
border-left: 1em solid #bbb;
margin-left: 10px;
padding-left: 10px;
font-style: italic; }
article pre {
border: 1px solid #CACACA;
line-height: 1.2em;
font: 1.4rem Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;
padding: 10px;
overflow: auto;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
background-color: #FAFAFB;
color: #393939;
margin: 1.5em 0;
overflow-x: auto;
white-space: pre; }
article pre code, article p code {
margin-bottom: 0; }
article p code, article li code {
font: 0.8em Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;
color: #52595D;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
border: 1px solid #CCC;
background-color: #F9F9F9;
padding: 0 0.5em;
display: inline-block;
margin-bottom: 0; }
.post_date, .post_contact {
margin-top: 50px;
font-size: 1rem;
color: #cccccc;
text-align: center; }
.post_contact {
font-size: 1.3rem;
color: #444; }
.post_contact a, .post_contact a:visited {
color: blue; }
footer {
border-top: 1px solid #cccccc;
padding-top: 10px;
margin: 50px 0;
font-size: 1.3rem;
text-align: center; }
hr {
border: none;
border-top: 1px solid #cccccc;
width: 75%;
margin: 30px auto; }
</style>
</head>
<body>
<header>
<h2>Credits</h2>
<p><a href="http://davidwinter.me/articles/2006/10/17/building-apache-22-from-source-for-ubuntu-dapper/">http://davidwinter.me/articles/2006/10/17/building-apache-22-from-source-for-ubuntu-dapper/</a></p>
</header>
<article>
<h1>Building Apache 2.2 from source for Ubuntu Dapper</h1>
<p>Two reasons you might want to do this.</p>
<ol>
<li>You want to host a Rails application using Mongrel via Apache and <code>mod_proxy_balancer</code>.</li>
<li>You’re studying in a Website administration module for your 3rd year Software Engineering degree :)</li>
</ol>
<p>Seriously though, if you don’t want to use <code>mod_proxy_balancer</code>, just do a normal <code>apt-get install</code> of Apache 2 and you’ll be fine. <code>mod_proxy_balancer</code> is only available for Apache 2.2, and currently, that’s not available from the Ubuntu repositories via <code>apt-get</code>.</p>
<p>This article only covers installing Apache 2.2 - I’ll write another one for getting Subversion and PHP working shortly afterwards.</p>
<h3>Workspace</h3>
<p>If you’ve not got the <code>build-essential</code> package installed yet:</p>
<pre><code>sudo apt-get install build-essential
</code></pre>
<p>It’s best to keep all of the source files in a seperate directory so they don’t mess up your home directory.</p>
<pre><code>cd
mkdir src
cd src
</code></pre>
<h3>Zlib</h3>
<p>So that Apache can compress output to browsers that support it, we’re going to install Zlib first of all:</p>
<pre><code>wget http://www.zlib.net/zlib-1.2.3.tar.gz
tar xvfz zlib-1.2.3.tar.gz
cd zlib-1.2.3/
./configure --prefix=/usr/local
make
sudo make install
</code></pre>
<h3>Apache 2.2</h3>
<p>Now download the Apache 2.2 source files:</p>
<pre><code>cd ..
wget http://apache.rmplc.co.uk/httpd/httpd-2.2.3.tar.gz
</code></pre>
<p>Extract and move into the directory:</p>
<pre><code>tar xvfz httpd-2.2.3.tar.gz
cd httpd-2.2.3/
</code></pre>
<p>Now to configure the build of Apache 2.2 that we want:</p>
<pre><code>./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-deflate --enable-proxy --enable-proxy-balancer --enable-proxy-http
</code></pre>
<p>Besides setting the modules we’d like installed, and the location of the install, this paramater <code>--enable-mods-shared=all</code> is telling Apache 2.2 to build modules so that they can be dynamically loaded when it is started. This means, we can add further modules to our Apache 2.2 install when we like - as we will do with the Subversion modules and PHP.</p>
<p>Once the configuration is complete:</p>
<pre><code>make
sudo make install
</code></pre>
<p>Let’s test that it’s working:</p>
<pre><code>sudo /usr/local/apache2/bin/apachectl start
</code></pre>
<p>Now navigate to <a href="http://localhost">http://localhost</a> and you should see a message saying “It works!”.</p>
<p>Stop Apache:</p>
<pre><code>sudo /usr/local/apache2/bin/apachectl stop
</code></pre>
<h3>Apache at start-up</h3>
<p>Now let’s get Apache to start at boot time automatically:</p>
<pre><code>sudo cp /usr/local/apache2/bin/apachectl /etc/init.d/apachectl
sudo chmod +x /etc/init.d/apachectl
</code></pre>
<p>What we’re doing here is copying the Apache Control script into the start-up directory.</p>
<p>We just need to add a few lines to the file for it to work nicely:</p>
<pre><code>sudo nano /etc/init.d/apachectl
</code></pre>
<p>Add the followinig, so the top of the file looks like:</p>
<pre><code>#!/bin/sh
#
# chkconfig: - 85 15
# description: Apache is a web server.
</code></pre>
<p>Save the file.</p>
<p>Now we need to register it with the start-up manager:</p>
<pre><code>sudo /usr/sbin/update-rc.d apachectl defaults
</code></pre>
<h3>Securing Apache</h3>
<p>It’s also a good idea to create a dedicate Apache system user account. It’ll make your install much more secure.</p>
<pre><code>sudo adduser --system apache
</code></pre>
<p>Now we just need to make sure that Apache runs under this user. We do that by editting the configuration file:</p>
<pre><code>sudo nano /usr/local/apache2/conf/httpd.conf
</code></pre>
<p>You need to find the lines that say:</p>
<pre><code>User daemon
Group daemon
</code></pre>
<p>And change them so they look like:</p>
<pre><code>User apache
Group nogroup
</code></pre>
<p>Save the file.</p>
<p>Now, let’s start Apache:</p>
<pre><code>sudo /usr/local/apache2/bin/apachectl start
</code></pre>
<p>Now to check it’s running under the new user, <code>apache</code>:</p>
<pre><code>ps -aux | grep httpd
</code></pre>
<p>If you see the word <code>apache</code> in there, it’s working.</p>
<h3>Check it’s all working</h3>
<p>Now just reboot the system and before logging in, check on another machine by visiting the servers IP in the web browser and you should see the “It works!” message. This means Apache started up correctly automatically.</p>
<p>Building Apache 2.2 from source. Done.</p>
</article>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment