Apache's source code installation detailed process full record _linux

Source: Internet
Author: User
Tags browser cache

Recently to begin to learn nagios monitoring knowledge, but Nagios and the combination of the relatively close, so this article will be the first Apache installation of the source study under.

We now install Apache in the following steps:

1, the installation of the compilation environment

2, uninstall the original Apache

3, download the source code to extract the package

4. Install Apache

5. Test Apache

6, view the Apache installation generated directory

7, view the Apache configuration file

8, Apache to join the system services

The installation of a compilation environment

Before installing Apache, we need to install the relevant software packages required to compile Apache as follows:

Yum-y install gcc gcc++ zlib zlib-devel

Second, uninstall the original Apache

Before we install Apache in the source code, we have to uninstall the Apache in the system that has been installed through the RPM package. As follows:

Rpm-qa |grep httpd

RPM-E--nodeps httpd-2.2.15-29.el6.centos.x86_64

RPM-E--nodeps httpd-tools-2.2.15-29.el6.centos.x86_64

Third, download the extract source package

To download the Apache source package, we've been experimenting with the 2.2.27 version of Apache as an example. Apache source package recommended directly to the Apache website download, as follows:

Download the Apache source package using the following command:

wget http://apache.fayea.com/httpd/httpd-2.2.27.tar.gz

Unzip the downloaded source package, because the download is the tar.gz source package, so we have two methods of decompression.

method One, use Gunzip for decompression , as follows:

Gunzip-c Httpd-2.2.27.tar.gz>httpd-2.2.27.tar

-C parameter can not delete the source file

TAR-XF Httpd-2.2.27.tar

method Two, directly using tar decompression , as follows:

TAR-ZXF httpd-2.2.27.tar.gz

or TAR-XF httpd-2.2.27.tar.gz.

Four, install Apache

To install Apache, we first compile and then install.

We can view compile-time help with the Configure command, as follows:

./configure--help

The specific compilation is as follows:

./configure--prefix=/usr/local/apache2--enable-rewrite--enable-so--enable-headers--enable-expires--with-mpm= Worker--enable-modules=most--enable-deflate

--PREFIX=/USR/LOCAL/APACHE2 Specifies the installation path for Apache, and the default installation path is/usr/local/apache2

--enable-rewrite provide URL rule rewrite more tender that, that is, according to the known URL address, converted to the other desired URL address

--ENABLE-SO Activate the Apache service DSO (dynamic shared objects), that is, in the future can be a DSO to compile and install the shared module, the module itself can not be a DSO way to compile.

--enable-headers provides control over HTTP request headers.

--enable-expires activation 荀彧 through the configuration file control http "Expires:" and "Cache-control:" header content, that is, the site pictures, JS, CSS and other content, provide client browser cache settings. This is one of the important options for Apache tuning.

--with-mpm=worker selects the Apache MPM mode as the worker mode. The principle of worker mode is that more threads are used to process requests, so more concurrent requests can be processed. The overhead of system resources is MPM prefork based on process. If you do not specify this parameter, the default mode is Prefork process mode. This is one of the important options for Apache tuning.

--enable-deflate provides compressed transmission coding support for the content, which is typically the site of HTML, JS, CSS, and so on. Use this parameter to increase the transmission speed and enhance the experience of visitor access. In a production environment, this is one of the important options for Apache tuning.

Make

Make install

After installing Apache, view the installed directory as follows:

Tree-l 1/usr/local/apache2/

Five, Test Apache

Copy the Apache startup script to the/ETC/RC.D/INIT.D directory, as follows:

Cp/usr/local/apache2/bin/apachectl/etc/init.d/httpd

In fact, Apache's startup is to invoke/usr/local/apache2/bin/httpd This command to view the contents of the script as follows:

Cat/etc/init.d/httpd|grep-v ^#|grep-v ^$

Start Apache, as follows:

/ETC/INIT.D/HTTPD start

Netstat-lntp|grep 80

Lsof-i: 80

You can also use/USR/LOCAL/APACHE2/BIN/HTTPD to start. As follows:

/usr/local/apache2/bin/httpd–k start

After the Apache has started, let's check it out and use the following command:

wget http://192.168.1.213

With the above diagram, we can clearly see that Apache has started normally.

Vi. View the directory generated by Apache installation

After the Apache startup, we'll look at the directories generated by the Apache installation. As follows:

Bin Main Store program command directory,.

Conf mainly hosts the Apache configuration file.

Htdocs main storage Site Directory.

Logs mainly holds default log files.

Modules mainly stores Apache's operating module. For example, PHP, memcache compiled modules are stored here.

Seven, view the Apache configuration file

The Apache configuration file httpd.conf is stored in the Conf directory, as follows:

View the httpd.conf configuration as follows:

Egrep-v ' ^[]*#|^$ '/usr/local/apache2/conf/httpd.conf | nl

ServerRoot "/usr/local/apache2" represents the Apache root directory, which should only be accessed by the root user and is generally not required to be modified.

Listen 80 represents the Apache listening port, which defaults to 80. If you monitor 81 ports at the same time, you can add one line: Listen 81.

AddType application/x-httpd-php. php LoadModule php5_module modules/libphp5.so is used when Apache is integrated with PHP.

User Daemon Group daemon represents Apache runtime users and groups, default to daemon, recommended modifications, such as Apache.

DocumentRoot "/usr/local/apache2/htdocs" represents the Apache Default Web site directory and does not add a slash at the end of the path.

ServerAdmin you@example.com represents the system administrator's mailbox, which is not an important option. When there is a problem with the site, this page address is displayed in the quilt.

DirectoryIndex index.php index.html Configures the default Apache home page. If the virtual host is not configured, the configuration here is applied by default.

ErrorLog "Logs/error_log" error log path.

LogLevel warn error log level.

scriptalias/cgi-bin/"/usr/local/apache2/cgi-bin/" configures the CGI alias.

Eight, Apache joined the system services

In order for Apache to boot, we can add the Apachectl startup script to the Rc.local file as follows:

echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.local

Cat/etc/rc.local

We can also start Apache by adding Apache to the system service. There are two ways to add Apache as a system service, the first is to add it through Chkconfig, and the second is to add the individual boot levels of the system directly.

Let's first introduce the first method, modify the startup httpd script to add the following two lines, as follows:

#chkconfig: 2345 70 60

#description: Apache

Description

The 2345 in chkconfig:2345 70 60 refers to the running level of the script, which can be run in 2345 of these 4 modes, 234 are text interfaces, and 5 is the graphical interface x.

70 refers to the script's future boot sequence number, if the other program's startup sequence number is smaller than 70 (such as 44, 45), the script needs to wait until these programs are started. 60 refers to the stop sequence number of the script when the system shuts down.

Description:apache A brief description of the script.

Add using Chkconfig, as follows:

Chkconfig--add httpd

Chkconfig |grep httpd

The function of the chkconfig--add httpd command is to add/etc/init.d/httpd to/ETC/RC.D/RC0.D directory. As follows:

Find/etc-name *httpd

Turn on Apache boot, using the following command:

Chkconfig httpd on

Chkconfig |grep httpd

After the above operation, Apache can boot.

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.