Compile and install Apache 2.4 In CentOS 6

Source: Internet
Author: User
Tags fully qualified domain name

Compile and install Apache 2.4 In CentOS 6

The httpd-2.4 adds the following new features and new modules
New features:
(1) MPM supports DSO operation and is loaded as needed in the form of modules;
(2) event MPM is supported;
(3) support asynchronous read/write;
(4) Each module and directory can use their respective log levels;
(5) configuration of each request;
(6) Enhanced expression analyzer;
(7) Support for keepalive timeout in milliseconds;
(8) The FQDN-based VM no longer needs the NameVirtualHost command;
(9) User-Defined variables are supported;
New module:
(1) mod_proxy_fcgi
(2) mod_ratelimit
(3) mod_remoteip
Modified some configuration mechanisms:
Order, Deny, and Allow are no longer supported for IP-based access control;

1. Deployment Environment
1. System Version and Kernel

[root@localhost ~]# cat /etc/centos-release   CentOS release 6.9 (Final)  [root@localhost ~]# uname -r  2.6.32-696.el6.x86_64

2. Set the program package required for httpd installation to "Development tools" and "Server Platform Development". Use yum to install it.

[root@localhost ~]# yum groupinstall "Development tools" "Server Platform Development" -y

2. Compile and install the software package httpd2.4 on which http2.4 depends on apr, apr-util, and pcre of a later version. install these three software packages before installing httpd2.4. 1.compile and install apr-1.6.2.tar.gz.

[root@localhost ~]# wget http://mirrors.shuosc.org/apache/apr/apr-1.6.2.tar.gz[root@localhost ~]# tar xf apr-1.6.2.tar.gz -C /usr/local/src/[root@localhost ~]# cd /usr/local/src/apr-1.6.2/[root@localhost apr-1.6.2]# ./configure --prefix=/usr/local/apr[root@localhost apr-1.6.2]# make && make install

2.compile and install apr-util-1.6.0.tar.gz

[root@localhost ~]# wget http://mirrors.shuosc.org/apache/apr/apr-util-1.6.0.tar.gz[root@localhost ~]# tar xf apr-util-1.6.0.tar.gz -C /usr/local/src/[root@localhost ~]# cd /usr/local/src/apr-util-1.6.0/[root@localhost apr-util-1.6.0]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr[root@localhost apr-util-1.6.0]# make && make install

3.compile and install pcre-8.41.tar.gz

[root@localhost ~]# wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz[root@localhost ~]# tar xf pcre-8.41.tar.gz -C /usr/local/src/[root@localhost ~]# cd /usr/local/src/pcre-8.41/[root@localhost pcre-8.41]# ./configure --prefix=/usr/local/pcre[root@localhost pcre-8.41]# make && make install

Create apache users and groups first

[root@localhost ~]# groupadd -r apache[root@localhost ~]# useradd -r -g apache apache

Compile and install apache2.4

[root@localhost ~]# wget http://mirrors.shuosc.org/apache/httpd/httpd-2.4.28.tar.gz[root@localhost ~]# tar xf httpd-2.4.28.tar.gz -C /usr/local/src/[root@localhost ~]# cd /usr/local/src/httpd-2.4.28/[root@localhost httpd-2.4.28]# ./configure --prefix=/usr/local/apache2 --sysconf=/etc/httpd24 \> --with-included-apr --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre \> --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

The meanings of the preceding options are as follows: -prefix =/usr/local/apache2 installation path-sysconf =/etc/httpd24 configuration file path-with-supported ded-apr contains apr-with-apr =/usr/local/apr specify the installation path of apr-with-apr-util =/usr/local/apr-util/Specify the installation path of apr-util-with-pcre =/usr/local/pcre pcre installation path-enable-so allows loading DSO module-enable-ssl at runtime. If not loaded, you cannot use https-enable-cgi to allow Using cgi script-enable-rewrite to support URLs. rewrite mechanism-enable-modules = most enable most common modules-enable-mpms-shared = all enable all modes supported by MPM-with-mpm = prefork by default prefork Mode

[root@localhost httpd-2.4.28]# make && make install

Note: configure: error: Bundled APR requested but not found. /srclib /. download and unpack the corresponding apr and apr-util packages. /srclib /. download the apr and apr-util source code, decompress the package to the httpd-2.4.28/srclib, and remove the version number.

[root@localhost httpd-2.4.28]# cp -rf /usr/local/src/apr-1.6.2 /usr/local/src/httpd-2.4.28/srclib/apr[root@localhost httpd-2.4.28]# cp -rf /usr/local/src/apr-util-1.6.0 /usr/local/src/httpd-2.4.28/srclib/apr-util

Run the command again.

Iv. Configuration after installation 1. Export the binary program directory to the path environment variable

[root@localhost ~]# vim /etc/profile.d/apache2.sh  export PATH=/usr/local/apache2/bin:$PATH  [root@localhost ~]# source /etc/profile.d/apache2.sh  [root@localhost ~]# echo $PATH  /usr/local/apache2/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin 

2. Export the outbound file path

[root@localhost ~]# vim /etc/ld.so.conf.d/apache2.conf  /usr/local/apache2/lib  [root@localhost ~]# ldconfig 

3. Export the header file, which can be link-based.

[root@localhost ~]# ln -sv /usr/local/apache2/include/ /usr/include/apache2   `/usr/include/apache2/include' -> `/usr/local/apache2/include/' 

4. Export help manual

[root@localhost ~]# vim /etc/man.config   MANPATH /usr/local/apache2/man  [root@localhost ~]# man -M /usr/local/apache2/man httpd

5. Start and test the apache service.

[root@localhost ~]# apachectl start  [root@localhost ~]# ss -tunl | grep 80  tcp    LISTEN    0    128        :::80        :::*   [root@localhost ~]# vim /etc/sysconfig/iptables  -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  [root@localhost ~]# service iptables restart

Open the browser and enter the IP address of the centos host in the browser. The page displays the following information:It works! Indicates that the apache service has been started normally. Note: during startup, "AH00558: httpd: cocould not reliably determine the server's fully qualified domain name, using localhost. localdomain. set the 'servername' directive globally to suppress this message "error. the solution is as follows:

[root@localhost ~]# vim /etc/httpd24/httpd.conf ServerName localhost:80 [root@localhost ~]# apachectl restart 

This error does not occur after the apache service is restarted. 6. Create an apache STARTUP script.

[root@localhost ~]# apachectl stop [root@localhost ~]# vim /etc/init.d/httpd 
#!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: The Apache HTTP Server is an efficient and extensible \ # server implementing the current HTTP standards. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd/httpd.pid # ### BEGIN INIT INFO # Provides: httpd # Required-Start: $local_fs $remote_fs $network $named # Required-Stop: $local_fs $remote_fs $network # Should-Start: distcache # Short-Description: start and stop Apache HTTP Server # Description: The Apache HTTP Server is an extensible server # implementing the current HTTP standards. ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache2/bin/apachectl httpd=httpd=${HTTPD-/usr/local/apache2/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} # The semantics of these two functions differ from the way apachectl does # things -- attempting to start while running is a failure, and shutdown # when not running is also a failure. So we just do it the way init scripts # are expected to behave here. start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } # When stopping httpd, a delay (of default 10 second) is required # before SIGKILLing the httpd parent; this gives enough time for the # httpd parent to SIGKILL any errant children. stop() { status -p ${pidfile} $httpd > /dev/null if [[ $? = 0 ]]; then echo -n $"Stopping $prog: " killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd else echo -n $"Stopping $prog: " success fi RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=6 echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else # Force LSB behaviour from killproc LSB=1 killproc -p ${pidfile} $httpd -HUP RETVAL=$? if [ $RETVAL -eq 7 ]; then failure $"httpd shutdown" fi fi echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart|try-restart) if status -p ${pidfile} $httpd >&/dev/null; then stop start fi ;; force-reload|reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" RETVAL=2 esac exit $RETVAL 

Add the execution permission to the httpd File

[root@localhost ~]# chmod +x /etc/init.d/httpd 

Then you can use the service command to start and close httpd.

[root@localhost ~]# service httpd start [root@localhost ~]# service httpd restart [root@localhost ~]# service httpd stop 

7. Add auto-start upon startup

[root@localhost ~]# chkconfig --add httpd [root@localhost ~]# chkconfig httpd on [root@localhost ~]# chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.