Part 2: Install and configure Apache from source


Install Apache:

1) Get the latest apache:
Check: http://httpd.apache.org/download.cgi

cd
wget http://www.dsgnwrld.com/am//httpd/httpd-2.4.7.tar.gz
tar zxvf httpd-*.tar.gz
cd httpd-*

2) Get the latest apr:
Check: http://apr.apache.org/download.cgi

cd 
mkdir ./httpd-2.4.7/srclib/apr
wget http://www.dsgnwrld.com/am//apr/apr-1.5.0.tar.gz
tar zxvf apr-*.tar.gz
cd apr-*
mv * ../httpd-2.4.7/srclib/apr

3) Get the latest apache portable runtime utils:
Check:
http://apr.apache.org/download.cgi

cd
mkdir ./httpd-2.4.7/srclib/apr-util
wget http://www.dsgnwrld.com/am//apr/apr-util-1.5.3.tar.gz
tar zxvf apr-util*.tar.gz
cd apr-util*
mv * ../httpd-2.4.7/srclib/apr-util

4) Build apache:

cd
cd httpd-*
./configure --bindir=/usr/bin --sbindir=/usr/sbin --prefix=/etc/httpd --exec-prefix=/usr/sbin --with-included-apr --enable-so --enable-auth-digest --enable-rewrite --enable-setenvif --enable-mime --enable-deflate --enable-ssl --enable-headers
make && make install

5) grab a solid init.d and options file from a package and schedule it to run:

cd /etc/init.d/
curl -k https://gist.github.com/mbrownnycnyc/7648794/raw/983c95ef6ed75010a901b2926baf01abe3741a96/httpd -o /etc/init.d/httpd
curl -k https://gist.github.com/mbrownnycnyc/7777766/raw/daf9e238f149dd524f70887f380c4416d4c990e1/sysconfighttpd -o /etc/sysconfig/httpd
chmod o+x httpd
mkdir /var/run/httpd/
mkdir /etc/httpd/run/
chkconfig --add httpd
chkconfig --level 2345 httpd on

6) Create the DocumentRoot:

mkdir /var/www

7) Create the user to run apache:

groupadd apache
useradd -d /var/www -g apache -s /sbin/nologin apache

8) Optionally, generate a self-signed key (for testing):

mkdir /var/www/ssl/
openssl genrsa -des3 -out /var/www/ssl/www_domainy_com.key 4096
openssl rsa -in /var/www/ssl/www_domainy_com.key -out /var/www/ssl/www_domainy_com.key
openssl req -new -key /var/www/ssl/www_domainy_com.key -out ~/server.csr
openssl x509 -req -days 365 -in ~/server.csr -signkey /var/www/ssl/www_domainy_com.key -out /var/www/ssl/www_domainy_com.crt

9) Verify iptables entries for port 80 and 443 exist.

10) Start httpd:

service httpd start

Problems as of 12/16/2013:
1) no pid file is generated by functions’s daemon(), but by httpd with PidFile directive.

  1. March 11, 2014 at 4:43 pm

    I just attempted your install to upgrade 2.2.15 to 2.4.7 in CentOS 6.5. Got all the way to the end but my version is still showing 2.2.15.
    Is there a different path for upgrading?

    • March 11, 2014 at 8:26 pm

      It sounds like you’re running the wrong `httpd`.

      Can you take a look at /etc/init.d/httpd and see which binary is used for `start)`?

  2. March 12, 2014 at 8:10 am

    I’m sorry. I’m still learning Linux. I apologize but I don’t quite understand what you mean by “Can you take a look at /etc/init.d/httpd and see which binary is used for `start)`?”
    You want me to look in the httpd file for something specific?
    Thanks.

    • March 12, 2014 at 8:42 am

      It’s okay, Ed. Everyone has to start somewhere.

      Try:

      vi /etc/init.d/httpd
      

      `/etc/init.d` contains all of the startup scripts (sort of like services in Windows).

      Also check out `chkconfig –list`. You can add and remove daemons (aka services) from startup using `chkconfig –add` and `chkconfig –remove`.

      `/etc/init.d/httpd` is the script that’s executed by the manager at start (look up “runlevels” to understand what 0-6 means).

      By way of the bash script `/etc/init.d/httpd`’s function `start)` you will see what’s happening when you issue something like `service httpd start`. Remember in linux, (mostly) everything is a file.

      You’ll notice that I used `backticks`, this is frequently used to designate commands in notation. You may also see $(string enumeration), which takes the output of a command and makes it “consumable.”

      For instance, try:

      which http #(anything following a # is a comment.)  `which` will tell you which file is accessible via your working path
      pgrep $(which http) #pgrep tells you the PID of a process, I think this should work :)
      

      Now try:

      which service
      vi ($which service)
      

      Although, I’m not sure if `service` is a binary executable :D

  3. March 12, 2014 at 9:06 am

    Thank you.
    I’m combing over the httpd file now. However, this was my output on which http:

    [ed@testcentos ~]$ which http
    /usr/bin/which: no http in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ed/bin)
    
    • March 12, 2014 at 3:52 pm

      Oh snap!

      typo. Try `which httpd`.

  4. March 12, 2014 at 4:25 pm

    Thanks.
    This is what I got.
    [ed@testcentos ~]$ which httpd
    /usr/sbin/httpd
    [ed@testcentos ~]$ pgrep /usr/sbin/httpd
    [ed@testcentos ~]$ pgrep $/usr/sbin/httpd
    [ed@testcentos ~]$

    • March 12, 2014 at 6:41 pm

      Sorry Edward, I can’t spend too much time talking about process, file and daemon management. You should figure out:
      1) what httpd is
      2) how it’s being executed
      3) what you’re upgrading when you follow the process on this page

      Otherwise, we could be here all day, and it isn’t the right forum for that.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: