≡ Menu

Install Apache 2 from Source on Linux

ApacheAll Linux distributions comes with Apache. However, it is recommended to download latest Apache source code, compile and install on Linux. This will make it easier to upgrade Apache on a ongoing basis immediately after a new patch or release is available for download from Apache. This article explains how to install Apache2 from source on Linux.

1. Download Apache

Download the latest version from Apache HTTP Server Project . Current stable release of Apache is 2.2.9. Move the source to /usr/local/src and extract it as shown below.

# cd /usr/local/src
# gzip -d httpd-2.2.9.tar.gz
# tar xvf httpd-2.2.9.tar

2. Install Apache

View all configuration options available for Apache using ./configure –help (two hyphen in front of help). The most commonly used option is –prefix={install-dir-name} to install Apache on a user defined directory.

# cd httpd-2.2.9
# ./configure --help

In the following example, Apache will be compiled and installed to the default location /usr/local/apache2 with the DSO capability. Using the –enable-so option, you can load modules to Apache at runtime via the Dynamic Shared Object (DSO) mechanism, rather than requiring a recompilation.

# ./configure --enable-so
# make
# make install

Note: During the ./configure, you may get the following error message.

# ./configure --enable-so
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
configure failed for srclib/apr

Install the gcc and the dependent modules as shown below and try ./configure again to fix the above issue.

# rpm -ivh gcc-4.1.2-14.el5.i386.rpm glibc-devel-2.5-18.i386.rpm glibc-headers-2.5-18.i38
6.rpm kernel-headers-2.6.18-53.el5.i386.rpm
Preparing...                ########################################### [100%]
1:kernel-headers         ########################################### [ 25%]
2:glibc-headers          ########################################### [ 50%]
3:glibc-devel            ########################################### [ 75%]
4:gcc                    ########################################### [100%]

3. Start Apache and verify installation

# cd /usr/local/apache2/bin
# ./apachectl start

Go to http://local-host, which should display the default message “It Works!”

4. Start Apache automatically during system startup

Modify the /etc/rc.d/init.d/httpd script and change apachectl and httpd variable to point to the appropriate new location as shown below. Please note that this httpd script was originally installed as part of the default Apache from the Linux distribution.

apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}

Now, you can perform the following to stop and start the Apache

# service httpd stop
# service httpd start

Setup the Apache to automatically startup during reboot as shown below.

# chkconfig --list httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
# chkconfig --level 2345 httpd on
# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

References:

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Anonymous October 2, 2009, 10:14 am

    <3! This guide was so explicit it was impossible to mess up. Thanks!

  • Vamsi February 11, 2010, 11:05 am

    Hi !
    thanks for the detailed..guide..
    can you please tell the advantages of manually compiling apache instead of using the build in manager like apt, yum , etc..
    thanks !

  • vamsi March 22, 2011, 8:49 pm

    hey i am using Ubuntu9.04 i installed Apache but i am not find in my system .if i use command line Aptitude i find the httpd package but where can i find this Applications,systems .please help me

  • Md. Mujahidul Islam Khan June 12, 2011, 5:55 am

    Wow!! All done successfully. Thank you so much…

  • Joseph January 23, 2012, 7:23 pm

    Hi,

    This is an excellent tutorial but unfortunately I have run into some issues. I installed the latest version – 2.2.21.
    I am able to start up Apache using the following commands and I get the “it works” on my browser when I type http://localhost. There is no message to say Apache has started when I type the ./apachectl start command though.

    # cd /usr/local/apache2/bin
    # ./apachectl start

    For starters I did not have the /etc/rc.d/init.d/httpd file so I added the following script

    #!/bin/bash
    apachectl=/usr/local/apache2/bin/apachectl
    httpd=${HTTPD-/usr/local/apache2/bin/httpd}
    chmod 775

    Now when I try to start httpd automatically I get the following error.

    [root@localhost ~]# service httpd start
    httpd: unrecognized service

  • Rupesh Rawat August 24, 2012, 2:51 am

    Sir when I am running this command # cd /usr/local/apache2/bin
    # ./apachectl start then its giving error

    ./apachectl: line 80: /usr/local/apache2/bin/httpd: No such file or directory

    how to resolve it

  • Harendra Kumar September 17, 2012, 10:39 am

    thanks for this pretty info…

  • Gopu Krishnan August 14, 2013, 9:12 am

    Hi,

    How to update and secure the apache which is compiled. Is there any issues updating the apache which is compiled with “yum update” command ?

    Thanks,

  • Matt B October 11, 2013, 12:32 pm

    hi there, where can I find help on installing/enabling modules later”

    “Using the –enable-so option, you can load modules to Apache at runtime via the Dynamic Shared Object (DSO) mechanism”

    tia,

    – Matt

  • Hawa Traore November 26, 2014, 4:03 am

    Hi
    I Have installed php from yum repository and Apache from source and enabled so module while istalling apache but once i run Apache, php modules was not loaded. Thanks.

  • Hawa Traore November 26, 2014, 8:16 pm

    Hi,
    I installed php from yum repository and Apache form source and i enable so module while installing Apache, but once i compile Apache php modules was not loaded.

    Thanks

  • Hema December 2, 2014, 1:27 am

    I am able to start up Apache using the following commands and I get the “it works” on my browser when I type http://localhost.

    # cd /usr/local/apache2/bin
    # ./apachectl start

    Now when I try to start httpd automatically I get the following error.

    [root@localhost ~]# service httpd start
    httpd: unrecognized service