Httpd source code installation and test steps sharing in CentOS


Environment: centos6.4   x86_ sixty-four

Required applications: Apr( )、APR-UTIL( )、 httpd( )

In Linux, there are two types of software installation: package installation and source code installation. Package installation refers to encapsulating the compiled binary into RPM package, which can be installed directly using RPM tool and Yum tool. Source code installation refers to those that are not compiled into binary and need to be compiled manually. There are two reasons for using source code installation. One is to use the latest version of software, and the other is to customize its functions.

Steps for source code installation:

    Expand the compressed files and extract them to / uer / local / SRC. In the directory of the extracted files, use the. / configure option to detect the compilation environment and generate makefiel files. Use make to compile and make install

The following describes how to install httpd and test through source code in CentOS.

To install software with source code, first install the corresponding compilation environment in the system; The tools needed to build the compilation environment in RedHat include developmentlibraries, development tools, legacy software development and X software development. These development environments are indispensable in rehdhat. There are two main development tools needed in CentOS: additive development and development tools. Therefore, a compilation environment needs to be built during source code installation.

First, we need to mount our CD and find the software package group we want to install through the CD. The command to mount the CD is: Mount / dev / CDROM / media / CDROM. After the CD is successfully mounted, we can query the software package group we need through Yum — disableredo = \ * — enablerepo = C6 media grouplist. Through the query, we found the two necessary development package groups as circled in the figure. Then install the two package groups with the command Yum – disablerepo = \ * — enablerepo = C6 media groupinstall “additionaldevelopment” “development tools”

After the installation, proceed to the installation of httpd. Install APR and APR util before installing httpd

Here we take apr-1.4.6.tar.gz, apr-util-1.5.1.tar.gz and httpd-2.4.4.tar.bz2 as examples; First extract these compressed files into the / usr / local / SRC directory and use the command

Decompress the three compressed files

After decompression, enter the / usr / local / SRC directory to find the directory formed by the three files we just unzipped

To install APR first, go to / usr / local / SRC / apr-1.4.6 directory

You can see a configure file, which is used to configure options and detect the compilation environment. There is also a readme or install file, which tells us some methods to use. Now let’s execute configure. During execution, add — prefix to specify the installation directory. The method is to enter. / configure – prefix = / usr / local / APR (this directory is specified by ourselves. If you want to uninstall the software in the future, you can delete this directory directly. It is installed in / desired / path / of / APR by default, If you use the default installation path and want to uninstall, it will be more troublesome) if there is no error during this process, it indicates that you can proceed to the next step.

Then use make to compile

Making is a long process, and waiting patiently is

Here, the compilation is completed. Next, use make install to install

When we’re done, let’s look in the / usr / local / directory

We have seen the APR we just installed. Go to the APR directory and have a look

We can look at some bin directories, include directory and lib directory

If we want other software to use the APR library, we need to create a. Conf file in the / etc / directory to indicate its library path, so we can create a file

After creation, we write out the path in the file

Then use the ldconfig command to refresh the cache;

You can see that it has been loaded

If you want the program to call the header file of APR, we will create a link in / usr / include to / usr / local / APR / include / apr-1

Switch to the / usr / include directory

You can see many header files in this directory

Then create a link

Through the query, we can see the link just created

OK, now that APR has been installed, it’s time to install APR util

First switch to the / usr / local / SRC / apr-util-1.5.1 directory

You can also see the configure and readme files in this directory

Next, just like the previous APR method, execute. / configure — prefix = / usr / local / APR util. Of course, this will not work. This will prompt an error. We need to point out the full path of APR config. The path of APR config is in the / usr / local / APR / bin directory, so it should be written as. / configure — prefix = / usr / local / APR util — with APR = / usr / local / APR / bin / APR config

After passing the detection, execute make;

Next, install

After the installation is completed, specify the library file path like the previous Apr

Also refresh the cache

Next, specify the header file

Create successfully. Finally, install httpd

Switch to / usr / local / SRC / httpd-2.4.4

You can see that there is configure install readme. Next, execute. / configure — prefix = / usr / local / httpd. Of course, this is certainly not possible. Here, you need to point out the full path of APR config and the full path of APU config, It should be written as. / configure — prefix = / usr / local / Apache — with APR = / usr / local / APR / bin / APR config — with APR util = / usr / local / APR util / bin / APU config

If we see this error after execution

This is a prce config error; It is necessary to eliminate the error. First, check whether the software related to prce is installed in the system

Pcre-7.8-6.el6.x86 is installed here_ 64. It is necessary to see if there are PCRE config related files in the software

If you find that there is no PCRE config file, install PECR devel

After the installation is completed, install httpd so that the test passes smoothly, and then execute make

Execute makeinstall after make is completed

Then specify the header file

There are some executable files in / usr / local / Apache / bin directory. If you want to execute, you have to switch to this directory every time, which is very troublesome. If you want to execute directly, you need to modify the environment variable / etc / profile

The path search path in the system is indicated in section 55. We will indicate the current search path here

In this way, you can use. / etc / profile to read it again, and then echo to output the path value to see if it is loaded

As can be seen from the figure, it has been loaded

Then point out the location of the man manual for httpd and edit / etc / man.config

Add manpath / usr / local / Apache / man to it.

Now that httpd has been installed, it’s time to write a shell script to control the start and stop of httpd.

The script is stored in / etc / init. D. then we will create a httpd control script to control the startup of httpd services.

Script code:

#!/bin/bash [ -e /etc/init.d/functions] && . /etc/init.d/functions prog=/usr/local/apache/bin/httpd lockfile=/var/lock/subsys/httpd start(){        if [ -e $lockfile ];then        echo "httpd server isstarted"        else echo -n "httpd server isstarting... "        sleep 1        $prog &>/dev/null  && echo  "[ ok ]" && touch $lockfile||echo "[ failer ]"        fi } stop(){        if [ ! -e $lockfile ];then        echo "httpd server is stoped"        else echo -n "httpd server isstoping... "        sleep 1        killproc httpd && echo "[ok ]" && rm -rf $lockfile ||echo "[ failer ]"         fi } status(){        if [ -e $lockfile ];then        echo "httpd server isstarted"        else echo "httpd server nofound"        fi } case $1 in start)   start   ;; stop)   stop   ;; restart)   stop   start   ;; status)   status   ;; *) echo"USAGE:start|stop|restart|status"  ;; esac

Start service:

By looking at port 80, it is found that httpd has started

It can be seen that our httpd is successfully installed through the source code, and there are no errors in the test.