{"id":55,"date":"2020-05-14T11:00:05","date_gmt":"2020-05-14T15:00:05","guid":{"rendered":"https:\/\/karthik.site\/blog\/?p=55"},"modified":"2020-05-14T13:04:30","modified_gmt":"2020-05-14T17:04:30","slug":"building-apache-http-server","status":"publish","type":"post","link":"https:\/\/karthik.site\/blog\/2020\/05\/14\/building-apache-http-server\/","title":{"rendered":"Building Apache HTTP server from source"},"content":{"rendered":"\n<p>Recently, I had to set up an <a href=\"https:\/\/httpd.apache.org\/\">Apache web server<\/a> at work as part of a personal project. Since I was working on a remote machine without package install privileges, I had to try to build Apache from source packages only, without assuming too much from the system environment. It later turned out that another team had had the same project idea, and <em>they<\/em> had an actual budget. My personal resentment not withstanding however, building Apache was not as straightforward as I&#8217;d assumed. I&#8217;m documenting the process merely for reference and can be adjusted to the individual environment.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Environment<\/h3>\n\n\n\n<p>These steps were tested on boxes with the following environment. Machines missing any of the additional packages can remove the relevant build arguments where applicable (these should be self-evident later on).<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>OS:<\/strong> RHEL 6.8 \/ Ubuntu 18.04 LTS<\/li><li><strong>Additional packages:<\/strong> mysql5.5, sqlite3<\/li><li><strong>Source Packages to download: <\/strong><ul><li><a href=\"https:\/\/httpd.apache.org\/download.cgi\">httpd<\/a> (Apache HTTP server)<\/li><li><a href=\"https:\/\/apr.apache.org\/download.cgi\">apr<\/a>, apr-util, apr-iconv (Apache Portable Runtime)<\/li><li><a href=\"https:\/\/libexpat.github.io\/\">expat<\/a><\/li><li><a href=\"https:\/\/zlib.net\/\">zlib<\/a><\/li><li><a href=\"https:\/\/www.pcre.org\/\">pcre<\/a><\/li><\/ul><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Building packages<\/h3>\n\n\n\n<p>I&#8217;m going to assume that all the source packages are in <code>$SRC_DIR<\/code>. In addition, built packages are going to be installed into the <code>$BUILD_DIR<\/code> directory. For instance:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"355\" src=\"https:\/\/karthik.site\/blog\/wp-content\/uploads\/2020\/05\/httpd-dirs.png\" alt=\"\" class=\"wp-image-65\" srcset=\"https:\/\/karthik.site\/blog\/wp-content\/uploads\/2020\/05\/httpd-dirs.png 900w, https:\/\/karthik.site\/blog\/wp-content\/uploads\/2020\/05\/httpd-dirs-300x118.png 300w, https:\/\/karthik.site\/blog\/wp-content\/uploads\/2020\/05\/httpd-dirs-768x303.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<p>After extracting all the gzipped files, the build process itself is simply running <a href=\"http:\/\/tldp.org\/LDP\/LG\/current\/smith.html\">CMMI<\/a> (<code>configure &amp;&amp; make &amp;&amp; make install<\/code>) inside each of these directories, in order. Note that some packages depend on the binaries from building others. Below are the <code>configure<\/code> commands used to build each package.<\/p>\n\n\n\n<pre title=\"Building expat\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ cd expat-2.2.9\n$ .\/configure --prefix=${BUILD_DIR}\/expat<\/code><\/pre>\n\n\n\n<pre title=\"Building pcre\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ cd pcre-8.44\n$ .\/configure --prefix=${BUILD_DIR}\/pcre<\/code><\/pre>\n\n\n\n<pre title=\"Building zlib\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ cd zlib-1.2.11\n$ .\/configure --prefix=${BUILD_DIR}\/zlib<\/code><\/pre>\n\n\n\n<pre title=\"Building apr\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ cd apr-1.7.0\n$ .\/configure --enable-shared \\\n            --enable-threads \\\n            --enable-other-child \\\n            --prefix=${BUILD_DIR}\/apr<\/code><\/pre>\n\n\n\n<pre title=\"Building apr-iconv\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ cd apr-iconv-1.2.2\n$ .\/configure --with-apr=${BUILD_DIR}\/apr \\\n            --prefix=${BUILD_DIR}\/apr-iconv<\/code><\/pre>\n\n\n\n<pre title=\"Building apr-util\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ cd apr-util-1.6.1\n$ .\/configure --with-apr=${BUILD_DIR}\/apr\/bin\/apr-1-config \\\n            --with-iconv=${BUILD_DIR}\/apr-iconv \\\n            --with-expat=${BUILD_DIR}\/expat \\\n            --with-mysql=\/ \\   # `bin\/mysql` will be appended to this value\n            --with-sqlite3=\/ \\ # `bin\/sqlite3` will be appended to this value\n            --prefix=${BUILD_DIR}\/apr-util<\/code><\/pre>\n\n\n\n<pre title=\"Building httpd\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ cd httpd-2.4.43\n$ .\/configure --enable-authn-anon \\\n            --enable-v4-mapped \\\n            --enable-authz-owner \\\n            --enable-auth-digest \\\n            --disable-imagemap \\\n            --enable-dav \\\n            --enable-dav-fs \\\n            --enable-dav-lock \\\n            --enable-deflate \\\n            --enable-expires \\\n            --enable-headers \\\n            --enable-info \\\n            --enable-mime-magic \\\n            --enable-proxy \\\n            --enable-proxy-ajp \\\n            --enable-proxy-http \\\n            --enable-proxy-ftp \\\n            --enable-proxy-balancer \\\n            --enable-proxy-connect \\\n            --enable-suexec \\\n            --enable-rewrite \\\n            --enable-so \\\n            --disable-userdir \\\n            --enable-vhost-alias \\\n            --with-mpm=prefork \\\n            --enable-mods-shared=all \\\n            --with-pcre=${BUILD_DIR}\/pcre \\\n            --with-z=${BUILD_DIR}\/zlib \\\n            --with-apr=${BUILD_DIR}\/apr\/bin\/apr-1-config \\\n            --with-apr-util=${BUILD_DIR}\/apr-util\/bin\/apu-1-config \\\n            --prefix=${BUILD_DIR}\/httpd<\/code><\/pre>\n\n\n\n<p>Conventionally, the <code>--prefix<\/code> argument to <code>.\/configure<\/code> is the directory where the compiled libraries and binaries will be stored. The <code>--with-*<\/code> arguments provide the location of dependent libraries; this is occasionally the build directory of the dependency, and at other times, a specific binary.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Running the server<\/h3>\n\n\n\n<p>That&#8217;s all to building the Apache HTTP server. To start the server, run:<\/p>\n\n\n\n<pre title=\"\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ ${BUILD_DIR}\/httpd\/bin\/apachectl -k start<\/code><\/pre>\n\n\n\n<p>Apache tries to start up on port 80 by default, but it&#8217;s possible another application is already registered on that port. If so, open <code>${BUILD_DIR}\/httpd\/conf\/httpd.conf<\/code> and edit the port definition here:<\/p>\n\n\n\n<pre title=\"Port selection configuration\" class=\"wp-block-code\"><code lang=\"apacheconf\" class=\"language-apacheconf\"># Change this to Listen on specific IP addresses as shown below to\n# prevent Apache from glomming onto all bound IP addresses.\n#\n# Listen 12.34.56.78:80\nListen 80<\/code><\/pre>\n\n\n\n<p>That should get Apache running on your system. There&#8217;s a lot more to configure in the conf file including server name, virtual hosts, and DSO modules that provide additional functionality. To make sure Apache is running, note your system IP address, and try running <code>http:\/\/&lt;IP&gt;:&lt;conf port&gt;\/<\/code> in a browser. You should see something similar to the screen below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/karthik.site\/blog\/wp-content\/uploads\/2020\/05\/httpd-works.png\" alt=\"Testing the server on a browser\" class=\"wp-image-70\" width=\"511\" height=\"336\" srcset=\"https:\/\/karthik.site\/blog\/wp-content\/uploads\/2020\/05\/httpd-works.png 681w, https:\/\/karthik.site\/blog\/wp-content\/uploads\/2020\/05\/httpd-works-300x197.png 300w\" sizes=\"auto, (max-width: 511px) 100vw, 511px\" \/><figcaption>You&#8217;re damn right it does!<\/figcaption><\/figure>\n\n\n\n<p>And if it does, that&#8217;s 20 minutes well spent.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I had to set up an Apache web server at work as part of a personal project. Since I was working on a remote machine without package install privileges, I had to try to build Apache from source packages only, without assuming too much from the system environment. It&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[10,9,11,12],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-development","tag-apache-httpd","tag-build","tag-linux","tag-server"],"_links":{"self":[{"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":20,"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":83,"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/posts\/55\/revisions\/83"}],"wp:attachment":[{"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/karthik.site\/blog\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}