Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of several methods of compiling and configuring httpd2.4 in Centos 6

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface

When we use linux, we must use httpd this service. On centos7, the default installation of httpd is version 2.4. as we all know, version 2.4 has been improved and more convenient to use than the previous version, but on our centos6, the default installation version is 2.2, so, if we want to install the httpd2.4 version on centos6, what should we do?

In this article, the editor will show you two ways to compile and install the httpd2.4 version on centos6.

Method one: separate compilation method

1. Download the source code and decompress it

We can use yum info httpd and yum info apr to view the official websites of these two services, and then we can go to the official website to download the latest stable version:

The address of the official website is attached below:

Httpd official website: http://httpd.apache.org/

Apr official website: http://apr.apache.org/

We can go to the official website to download the latest stable version. Here, the editor downloads apr-1.6.2.tar.gz,apr-util-1.6.0.tar.gz,httpd-2.4.28.tar.bz2. In the following experiment, we will demonstrate how to install the version downloaded by the editor.

We use the rz command to upload the source package we downloaded to our centos6 virtual machine, and we can check it out:

[root@centos6 temp] # lltotal 8004 RW Oct 15 12:35 httpd-2.4.28.tar.bz2-1 root root 1071074 Sep 29 12:27 apr-1.6.2.tar.gz-rw-r--r-- 1 root root 565507 Sep 29 12:27 apr-util-1.6.0.tar.gz-rw-r--r-- 1 root root 6553163 Oct 15 12:35 httpd-2.4.28.tar.bz2

The next step is to extract:

Tar xvf httpd-2.4.28.tar.bz2tar xvf apr-util-1.6.0.tar.gztar xvf apr-1.6.2.tar.gz

After unzipping it, let's take a look at it as usual:

[root@centos6 temp] # lsapr-1.6.2 apr-1.6.2.tar.gz apr-util-1.6.0 apr-util-1.6.0.tar.gz httpd-2.4.28 httpd-2.4.28.tar.bz2

We found that there are now three folders, and this step is complete.

2. The package group that the installation depends on

Before the compilation installation starts, we have to install the dependent package group, otherwise there will be errors in the next compilation installation process.

The installation commands are as follows:

Yum groupinstall "development tools"-yyum install pcre-devel-yyum install openssl-devel-yyum install expat-devel-y

After the installation is successful, we can compile the apr separately.

3. Compile and install apr-1.6.2

When we compile and install apr-1.6.2, we must first make sure that all our operations are carried out in this folder!

First, let's go to the catalog

[root@centos6 temp] # cd apr-1.6.2/ [root@centos6 apr-1.6.2] # lsapr-config.in CMakeLists.txt libapr.mak pollapr.dep config.layout libapr.rc randomapr.dsp configure LICENSE READMEapr.dsw configure.in locks README.cmakeapr.mak docs Makefile.in shmemapr.pc.in dso Makefile.win stringsapr.spec emacs-mode memory supportatomic encoding misc tablesbuild file_io mmap testbuildconf helpers network_io threadprocbuild.conf include NOTICE timebuild-outputs.mk libapr.dep NWGNUmakefile toolsCHANGES libapr.dsp passwd user

Then we can compile and install it:

[root@centos6 apr-1.6.2] # / configure-- prefix=/app/apr [root@centos6 apr-1.6.2] # make & & make install

The compiled command is simple, just specify a directory, remember this directory 0.0, and then we'll use it again.

After the compilation and installation is complete, let's take a look at the / app directory to see if the apr folder has been generated:

[root@centos6 apr-1.6.2] # ls / app/apr

You can see that you already have this folder, so we finished this step.

4. Compile and install apr-util-1.6.0

Similar to the previous step, but one thing to note is that when compiling apr-util-1.6.0, you need to rely on the apr-1.6.2 package, so keep up with the apr-1.6.2 directory. Next, let's talk about the specific operation.

First of all, we still need to enter this directory:

[root@centos6 temp] # cd apr-util-1.6.0 [root@centos6 apr-util-1.6.0] # lsaprutil.dep configure.in Makefile.winaprutil.dsp crypto memcacheaprutil.dsw dbd miscaprutil.mak dbm NOTICEapr-util.pc.in docs NWGNUmakefileapr-util.spec encoding READMEapu-config.in export_vars.sh.in README.cmakebuckets hooks README.FREETDSbuild include redisbuildconf ldap renames_pendingbuild.conf libaprutil.dep strmatchbuild-outputs.mk libaprutil.dsp testCHANGES libaprutil.mak uriCMakeLists.txt libaprutil.rc xlateconfig.layout LICENSE xmlconfigure Makefile.in

Then we can compile and install it. Note that the code at compile time is slightly different from what you just did, and you need to add the directory of apr-1.6.2:

[root@centos6 apr-util-1.6.0] # / configure-- prefix=/app/apr-util-- with-apr=/app/apr/ [root@centos6 apr-util-1.6.0] # make & & make install

The compiled command is simple, just specify a directory, remember this directory 0.0, and then we'll use it again.

After the compilation and installation is complete, let's take a look at the / app directory to see if the apr-util folder has been generated:

[root@centos6 apr-1.6.2] # ls / app/apr apr-util

You can see that you already have this folder, so we finished this step.

5. Compile and install httpd-2.4

Again, first of all, we need to go to this directory:

[root@centos6 temp] # cd httpd-2.4.28/ [root@centos6 httpd-2.4.28] # lsABOUT_APACHE docs Makefile.winacinclude.m4 emacs-style modulesApache-apr2.dsw httpd.dep NOTICEApache.dsw httpd.dsp NWGNUmakefileapache_probes.d httpd.mak osap.d httpd.spec READMEbuild include README.cmakeBuildAll.dsp INSTALL README.platformsBuildBin.dsp InstallBin.dsp ROADMAPbuildconf LAYOUT serverCHANGES libhttpd.dep srclibCMakeLists.txt libhttpd.dsp supportconfig.layout libhttpd.mak testconfigure LICENSE VERSIONINGconfigure.in Makefile.in

Then, we will compile and install, the compilation command is a bit long, we should be careful not to write less, or you will report an error! Or, like the editor, write the code on separate lines, but you must add the\ symbol before you can make a promise.

[root@centos6 httpd-2.4.28] #. / configure-- prefix=/app/httpd24\ >-- enable-so\ >-- enable-ssl\ >-- enable-cgi\ >-- enable-rewrite\ >-- with-zlib\ >-- with-pcre\ >-- with-apr=/app/apr/\ >-- with-apr-util=/app/apr-util/\ >-- enable-modules=most\ >-- enable-mpms-shared=all\ >-- with-mpm=prefork [root @ centos6 httpd-2.4.28] # make & & make install

At this point, the steps of compiling and installing are all over. We can test it.

6. Test and configure

First, let's check to see if our port 80 is not open:

[root@centos6 ~] # ss-tnlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0128: 22:: * LISTEN 0128 *: 22 *: * LISTEN 0128 127.0.0.1 LISTEN 631 *: * LISTEN 0128: 1 LISTEN 631: * LISTEN 0100:: 1:25:: * LISTEN 0100 127.0.1displacement 25 *: *

It can be seen that our port 80 is not open, and we strongly suggest that you must check it. If we have installed httpd service on our previous machine, uninstall it, or at least stop the service to ensure that our port 80 is closed, otherwise our newly installed version 2.4 will not start!

Next, let's go to the / app/httpd24/bin/ directory and turn on the service:

[root@localhost ~] # cd / app/httpd24/bin/ [root@localhost bin] #. / apachectl startAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

Now, let's take a look at the port opening:

[root@localhost bin] # ss-tnlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128: 80:: * LISTEN 0 128: 22:: * LISTEN 0 128 *: 22 *: * LISTEN 0 128 127.0.1 LISTEN 631 *: * LISTEN 0 128: 1 LISTEN 631: * LISTEN 0100:: 1:25:: * LISTEN 0100 127.0.1 25 *: *

As you can see, our port 80 is open, and then we can test it with other machines:

We use the curl command on centos7 to test:

[root@centos7 ~] # curl 192.168.191.128It works!

The test was successful.

At this point, our experiment has been successfully completed, and the httpd2.4 version has been successfully installed on centos6.

Methods the method of secondary compilation

In the last experiment, we installed the httpd2.4 version on centos6 using the method of compiling separately, but the method of compiling separately is still a little troublesome, so is there a way to compile it all at once? The editor is very responsible to tell you, of course there is! Next, let's take a look at how to compile and install everything at once.

1. Download the source code and upload it to the virtual machine

We can use yum info httpd and yum info apr to view the official websites of these two services, and then we can go to the official website to download the latest stable version:

The address of the official website is attached below:

Httpd official website: http://httpd.apache.org/

Apr official website: http://apr.apache.org/

We can go to the official website to download the latest stable version. Here, the editor downloads apr-1.6.2.tar.gz,apr-util-1.6.0.tar.gz,httpd-2.4.28.tar.bz2. In the following experiment, we will demonstrate how to install the version downloaded by the editor.

We use the rz command to upload the source package we downloaded to our centos6 virtual machine, and we can check it out:

[root@centos6 temp] # lltotal 8004 RW Oct 15 12:35 httpd-2.4.28.tar.bz2-1 root root 1071074 Sep 29 12:27 apr-1.6.2.tar.gz-rw-r--r-- 1 root root 565507 Sep 29 12:27 apr-util-1.6.0.tar.gz-rw-r--r-- 1 root root 6553163 Oct 15 12:35 httpd-2.4.28.tar.bz2

This step is complete.

2. The package group that the installation depends on

Before the compilation installation starts, we have to install the dependent package group, otherwise there will be errors in the next compilation installation process.

The installation commands are as follows:

Yum groupinstall "development tools"-yyum install pcre-devel-yyum install openssl-devel-yyum install expat-devel-y

After the installation is successful, we can compile the apr separately.

3. Decompress the source code

In the first step, we have uploaded the source code to our virtual machine, but no operation has been done yet. In this step, we need to decompress the source code and put it in the specified folder to create conditions for compilation and installation. The specific operations are as follows:

First, decompress the three packets:

Tar xvf httpd-2.4.28.tar.bz2tar xvf apr-util-1.6.0.tar.gztar xvf apr-1.6.2.tar.gz

After the decompression is completed, we copy xvf apr-1.6.2.tar.gz and apr-util-1.6.0.tar.gz to the specified folder in the httpd-2.4.28.tar.bz2 directory and rename them:

[root@centos6 temp] # cp-an apr-1.6.2 httpd-2.4.28/srclib/apr [root@centos6 temp] # cp-an apr-util-1.6.0 httpd-2.4.28/srclib/apr-util [root@centos6 temp] # ls httpd-2.4.28/srclib/apr apr-util Makefile.in

We can see that there are already two folders, apr and apr-util, in the httpd-2.4.28/srclib/ directory. This step is complete.

4. Compile and install

After all the preparatory work is done, the next step is to compile and install.

Similarly, you need to go to the httpd-2.4.28/ directory first. As the code is very long, I hope everyone will write it carefully and carefully, or write it as an editor:

[root@centos6 temp] # cd httpd-2.4.28 [root@centos6 httpd-2.4.28] #. / configure-- prefix=/app/httpd24\-- enable-so\-- enable-ssl\-- enable-cgi\-- enable-rewrite\-- with-zlib\-- with-pcre\-- with-included-apr\-- enable-modules=most\-enable-mpms-shared=all\-- with-mpm=prefork [root@centos6 httpd-2.4.28] # make-j 4 & & make install

The installed make-j 4 & & make install line of code means to start four processes to work at the same time to install, which is faster.

Above, the compilation and installation is complete, and then we can test and make some configuration changes.

5. Test and configure

First, go to the / app/httpd24 folder and take a look at the contents:

[root@centos6 httpd24] # lsbin build cgi-bin conf error htdocs icons include lib logs man manual modules

In the last experiment, we went to the bin/ directory and used apachectl to start our service, but it would be troublesome to start the service like this every time. Because we need to add a path, we simply set this path to the PATH variable, so it will be more convenient for us to use the service. The specific operations are as follows:

[root@centos6 bin] # vim / etc/profile.d/httpd24.shPATH=/app/httpd24/bin:$PATH

Then let's run it to make it work:

[root@centos6 bin] #. / etc/profile.d/httpd24.sh

Now we can start our service on any page.

[root@centos6 bin] # apachectl start

We can now test our service on another machine:

[root@centos7 ~] # curl 192.168.191.128It works!

Our page is saved in the / app/httpd24/htdocs/ folder. We can also modify this page according to our own needs.

[root@centos6 httpd24] # cd htdocs/ [root@centos6 htdocs] # lsindex.html [root@centos6 htdocs] # vim index.html Welcome to keer'home!

Then let's check it out on centos7:

[root@centos7 ~] # curl 192.168.191.128Welcome to keer'home!

It's what it looks like after we modified it.

Of course, we still want to be able to write a service script, so it will be more convenient for us to use it. Now that our service is started, we can check it out with ps aux:

[root@centos6 htdocs] # ps auxUSER PID% CPU% MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 19348 1560? Ss 00:22 0:01 / sbin/initroot 2 0.0 0.0 00? S 00:22 0:00 [kthreadd]. Daemon 35258 0.0 0.0 76416 1436? S 00:53 0:00 / app/httpd24/bin/httpd-k startdaemon 35259 0.0 76416 1436? S 00:53 0:00 / app/httpd24/bin/httpd-k startdaemon 35260 0.00.1 76416 2104? S 00:53 0:00 / app/httpd24/bin/httpd-k startdaemon 35261 0.00.1 76416 2084? S 00:53 0:00 / app/httpd24/bin/httpd-k startdaemon 35262 0.00.1 76416 2084? S 00:53 0:00 / app/httpd24/bin/httpd-k startdaemon 35264 0.0 76416 1440? S 00:54 0:00 / app/httpd24/bin/httpd-k startroot 35326 13.0 110260 1152 pts/0 R + 01:22 0:00 ps aux

Let's first check to see if the user apache exists:

[root@centos6 htdocs] # id apacheuid=48 (apache) gid=48 (apache) groups=48 (apache)

If it does not exist, we can use useradd-r apache to create it, because apache is the account used by the system's service, so we need to add-r

Then we can modify the configuration file. The configuration file is in the / app/httpd24/conf/ folder. Let's go in and modify the file:

[root@centos6 ~] # cd / app/httpd24/conf/ [root@centos6 conf] # lsextra httpd.conf magic mime.types original [root@centos6 conf] # vim httpd.conf

After opening this file, we put:

User daemonGroup daemon

Change it to this:

User apacheGroup apache

That's fine. Let's stop the service now, turn it back on, and then check it out with ps aux:

[root@centos6 conf] # apachectl stop [root@centos6 conf] # apachectl start [root@centos6 conf] # ps auxUSER PID% CPU% MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 19348 1560? Ss 00:22 0:01 / sbin/initroot 2 0.0 0.0 00? S 00:22 0:00 [kthreadd]. Apache 35352 0.0 0.0 76416 1436? S 01:33 0:00 / app/httpd24/bin/httpd-k startapache 35353 0.0 76416 1436? S 01:33 0:00 / app/httpd24/bin/httpd-k startapache 35354 0.0 76416 1436? S 01:33 0:00 / app/httpd24/bin/httpd-k startapache 35355 0.0 76416 1436? S 01:33 0:00 / app/httpd24/bin/httpd-k startapache 35356 0.0 76416 1436? S 01:33 0:00 / app/httpd24/bin/httpd-k startroot 35357 3.00.0 110260 1152 pts/0 R + 01:33 0:00 ps aux

In this way, our httpd runs as apache.

Of course, we can also make a service directly, and we don't need to write the service script ourselves. Just make a copy of the httpd service script that comes with the system and modify it. The specific steps are as follows:

[root@centos6 ~] # cd / etc/init.d [root@centos6 init.d] # lsabrt-ccpp cpuspeed htcacheclean lvm2-monitor ntpd rdma spice-vdagentd winbindabrtd crond httpd mdmonitor ntpdate restorecond sshd wpa_supplicantabrt-oops cups ip6tables messagebus portreserve rngd svnserveacpid dnsmasq iptables netconsole postfix rsyslog sysstatatd firstboot irqbalance netfs pppoe-server sandbox udev-postauditd functions kdump network psacct saslauthd vmware-toolsblk-availability haldaemon killall NetworkManager quota_nld single vmware-tools-thinprintbluetooth halt lvm2-lvmetad nfs-rdma rdisc smartd wdaemon [root@centos6 init.d] # cp httpd httpd24 [root@centos6 init.d] # vim httpd24

The above content in the file does not need to be changed, we just need to change the path, that is, to change the

# Path to the apachectl script, server binary, and short-form for messages.apachectl=/usr/sbin/apachectlhttpd=$ {HTTPD-/usr/sbin/httpd} prog=httpdpidfile=$ {PIDFILE-/var/run/httpd/httpd.pid} lockfile=$ {LOCKFILE-/var/lock/subsys/httpd} RETVAL=0STOP_TIMEOUT=$ {STOP_TIMEOUT-10}

Modified to:

# Path to the apachectl script, server binary, and short-form for messages.apachectl=/app/httpd24/bin/apachectlhttpd=$ {HTTPD-/app/httpd24/bin/httpd} prog=httpdpidfile=$ {PIDFILE-/app/httpd24/logs/httpd.pid} lockfile=$ {LOCKFILE-/var/lock/subsys/httpd24} RETVAL=0STOP_TIMEOUT=$ {STOP_TIMEOUT-10}

Then save and exit.

Next, you can add this service to the list of services:

[root@centos6 init.d] # chkconfig-- add httpd24 [root@centos6 init.d] # chkconfig httpd24 on [root@centos6 init.d] # chkconfig-- list httpd24httpd24 0:off 1:off 2:on 3:on 4:on 5:on 6:off

In this way, our version of httpd2.4 can be controlled through service.

At this point, the main functions of our service are realized.

Our experiment was successfully completed.

Summary

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report