This article mainly introduces the httpd source code installation and testing methods in CentOS, and mainly introduces the software package installation and source code installation labels: CentOS
Environment: CentOS6.4 x86_64
Applications required: APR (http://apr.apache.org/), APR-UTIL (http://apr.apache.org/), httpd (http://httpd.apache.org /)
In Linux, there are two main types of software installation: software package installation and source code installation. Package installation encapsulates compiled binary data into rpm packages and can be directly installed using the rpm tool and yum tool. Source code installation means that it is not compiled into binary and needs to be compiled manually. There are two reasons for source code installation. one is to use the latest software, and the other is to customize its functions.
Steps for installing source code:
Expand the compressed file. generally, decompress all the files to/uer/local/src and use them in the decompressed file directory. /configure option to check the compiling environment and generate the makefiel file. use make to compile and install make install.
The following describes how to install httpd and test httpd through source code in CentOS.
To install Software with source code, you must first install the corresponding compiling environment in the system. the Tools required to build the compiling environment in RedHat are DevelopmentLibraries, Development Tools, Legacy Software Development, and X Software Development, these development environments are indispensable in RehdHat. There are mainly two Development tools required in CentOS: AdditionalDevelopment and Development tools. Therefore, you must build a compiling environment for 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 for mounting the CD is: after the mount/dev/cdrom/media/cdrom disc is mounted successfully, we can query the required software package groups through yum -- disablerepo = \ * -- enablerepo = c6-media grouplist. By querying, we can find two necessary development software packages in the middle. Then install the two software packages, run the command yum-disablerepo = \ * -- enablerepo = c6-media groupinstall "AdditionalDevelopment" "Development tools"
After the installation is complete, install httpd. before installing httpd, install apr and apr-util.
Here, we use apr-1.4.6.tar.gz?apr-util-1.5.1.tar.gzand httpd-2.4.4.tar.bz2 as an example. first, extract these compressed files to the/usr/local/src directory and use the command
Decompress three compressed files
After decompression, go to the/usr/local/src directory to find the directory formed by the three files we just decompressed.
First install apr, then first enter the/usr/local/src/apr-1.4.6 Directory
We can see that the configure file is used to configure options and check the compiling environment. Another README or INSTALL file tells us how to use it. Now we will execute configure, and add -- prefix to specify the installation directory during execution. the usage is to input in the decompressed directory. /configure-prefix =/usr/local/apr, by default, it is installed in/desired/path/of/apr. if you want to uninstall it using the default installation path, it is troublesome) if no error is prompted during this process, you can proceed to the next step.
Then, make is used for compilation.
Make is a long process.
The compilation is complete, and the installation is completed using make install.
After this is done, go to the/usr/local/directory and check it out.
We have seen the apr We just installed. go to the apr directory and check it out.
We can look at some bin directories, including directories and lib directories.
If we want other software to use the apr library, we need. so. conf. d/create a directory. conf file to specify its library path, then we will create a file
After the file is created, write the path in the file.
Then use the ldconfig command to refresh the cache;
We can see that it has been loaded.
If you want your program to call the header file of apr, create a link in/usr/include pointing 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
By querying, we can see the link we just created.
Now that apr has been installed, you need to install apr-util.
First switch to the/usr/local/src/apr-util-1.5.1 Directory
The configure and README files are also displayed in this directory.
Next we will execute the same method as the previous apr method. /configure -- prefix =/usr/local/apr-util, of course, this will not work, and an error will be prompted. 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. /configure -- prefix =/usr/local/apr-util -- with-apr =/usr/local/apr/bin/apr-config
After detection, execute make;
Next, install
After the installation is complete, specify the library file path like the previous apr.
Cache Refresh
Next, specify the header file
Create successfully, and finally install httpd
Switch to/usr/local/src/httpd-2.4.4
You can view configure install readme and then execute it. /configure -- prefix =/usr/local/httpd. of course, this is definitely not the case. here we need to point out the full path of apr-config and the full path of apu-config, so we should write it. /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 an error about prce-config. eliminate the error. First, check whether the prce-related software is installed in the system.
If the pcre-7.8-6.el6.x86_64 is installed here, check if there are any files related to pcre-config in this software.
If there is no file about pcre-config, install pecr-devel.
After the installation is complete, install httpd to successfully pass the detection and then execute make
Run makeinstall after make is complete.
Then specify the header file
There are some executable files in the/usr/local/apache/bin directory. it is very troublesome to switch to this directory every time you want to execute the file. If you want to directly execute the command, you need to modify the environment variable/etc/profile.
In 55th, the PATH search PATH is specified in the system. here, the current search PATH is specified.
In this way, you can use./etc/profile to re-read and use echo to output the PATH value to see if it has been loaded.
We can see that it has been loaded.
Then, specify the location of the httpd man manual and edit/etc/man. config.
Add MANPATH/usr/local/apache/man to it.
Now that httpd has been installed, write a shell script to control the startup and stop of httpd.
The script is stored in/etc/init. d, so we will create an httpd control script in it to control the startup of the httpd service.
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 the service:
Check port 80 to find that httpd has been started
It can be seen that our httpd has been successfully installed through the source code, and there is no error in the test.