Linux Apache compilation and Installation

Source: Internet
Author: User
Tags builtin

Link: httpd-2.2.15.tar.gz

[Root @ test-AS4 ~] # Mkdir-P/usr/local/src/Apache/# create a directory for storing the source package

[Root @ test-AS4 ~] # Cd/usr/local/src/Apache/samples put httpd-2.2.15.tar.gz in this directory

[Root @ test-AS4 Apache] # tar zxvf httpd-2.2.15.tar.gz # extracting files will generate a httpd-2.2.15 directory

[Root @ test-AS4 Apache] # ll
Total 6464
Drwxr-XR-x 11 angel 4096 Mar 10 httpd-2.2.15
-RW-r -- 1 Root 6593633 Mar 10 2010 httpd-2.2.15.tar.gz

[Root @ test-AS4 httpd-2.2.15] # cd httpd-2.2.15

[Root @ test-AS4 httpd-2.2.15] #./configure -- prefix =/usr/local/Apache-2.2.15 -- enable-so -- enable-mods-shared = most -- With-MPM = worker

[Root @ test-AS4] # Make

[Root @ test-AS4] # make install

# -- Prefix = <install_path> indicates that the compiled binary file is installed in the <install_path> directory and replaced with the actual installation path <install_path>, for example, -- prefix =/usr/local/Apache-2.2.15. If this configuration parameter is omitted, it is installed in the/usr/local/apache2 directory by default.

# -- Enable-so indicates that the dynamic compilation load module (DSO) supports httpd binary files. This module enables the functional modules of Apache to be compiled separately from the core and dynamically loaded during runtime. With DSO support, you only need to compile the relevant modules when upgrading and adding modules. You do not have to re-compile the entire system. The latest version of Apache compiles this module to the httpd binary file by default. If you are using an earlier version of Apache and need DSO support, you may need to explicitly specify this option.

# -- enable-mod-shared = specify the module to be compiled in DSO mode, List of module names separated by spaces, all or most. "All" indicates that all modules are included, and "most" indicates that most modules are included, for example, -- enable-mod-Share = "rewrite deflate", -- enable-mod-Share = most, the effect is equivalent to multiple -- enable- = share
# -- With-MPM = select the Apache multiplexing module, ={ BEOs | event | worker | prefork | mpmt_os2}. The prefork is the default processing module in Unix systems. It runs a non-thread-type, pre-derived web server, suitable for systems that do not have a thread security library and need to avoid thread compatibility issues. It requires that each request be independent of each other. In this way, if a request fails, other requests will not be affected. Worker is a multi-path processing module that supports mixed multi-thread, multi-process processing. because it uses threads to process requests, it can process massive requests. the overhead of system resources is less than the MPM Based on processes, it also uses multiple processes, and each process has multiple threads to obtain the stability of the process-based MPM. If your system is thread-safe, I suggest using worker instead of prefork, which will improve your system performance.

2. Set the Automatic startup Service Control script
After Apache is installed, you can use the apachectl script in the bin directory of its installation path to control the start and stop of the service. In this example, Apache is installed in/usr/local/Apache-2.2.15, and the service control script is:
Run the following command to start the apache service:
/Usr/local/Apache-2.2.15/bin/apachectl start
Run the following command to stop the apache service:
/Usr/local/Apache-2.2.15/bin/apachectl stop
You can simply add the Apache startup command to the/etc/rc. Local file to enable Apache to start automatically as the system starts:
Echo "/usr/local/Apache-2.2.15/bin/apachectl start">/etc/rc. Local

The following describes how to add Apache to the system service and use the service command to control Apache startup and stop.

# Note here! If httpd is installed on the Linux server by default (use rpm-Qa | grep httpd to view it ),

# There will be the/etc/init. d/httpd script file, so you can directly generate this file to overwrite it using the following method

# Next time you can start it with service httpd start

# Use the following method to differentiate them
First, generate the apache service control script using the apachectl script as the template:
Grep-V "#"/usr/local/Apache-2.2.15/bin/apachectl>/etc/init. d/Apache
Use VI to edit the apache service control script/etc/init. d/Apache:
VI/etc/init. d/Apache
Insert the following line at the beginning of the file to support the chkconfig command:
#! /Bin/sh
# Chkconfig: 2345 85 15
# Description: Apache is a World Wide Web server.
Save and exit the VI editor. Run the following command to add the apache service control script execution permission:
Chmod + x/etc/init. d/Apache
Run the following command to add the apache service to the System Service:
Chkconfig -- add Apache
Run the following command to check whether the apache service has taken effect:
Chkconfig -- list Apache
Command output is similar to the following result:
Apache 0: off 1: off 2: On 3: On 4: On 5: on 6: Off
It indicates that the apache service has taken effect and is automatically started at the 2, 3, 4, and 5 running levels as the system starts. In the future, you can use the service command to control the start and stop of Apache.
Start the apache service:
Service Apache start
Stop the apache service:
Service Apache stop
Run the following command to disable automatic startup:
Chkconfig Apache off
Run the following command to change the self-starting running level to 3 and 5:
Chkconfig -- level 35 Apache on

3. Apache configuration

Install the directory structure using the source code package
When installing the source code package, the following directory structure is usually created in the directory specified by the -- prefix option in the configure command, except for the specially specified directory:
./Icons # directory of Apache Icon files
./Modules # dynamically load the Module Directory
./Lib # library file directory
./Logs # log file directory
./Build #
./Conf # main configuration file directory
./CONF/extra # extension and module configuration file directory
./Error # default error response file directory
./Manual # Apache document directory
./Include # contains the header file directory
./Htdocs # default web document root directory
./Cgi-bin # default CGI File directory
./Bin # Apache binaryProgramAnd service program directory
./Man # man help file directory

4. configuration file HTTP. conf

Serverroot "/usr/local/Apache-2.2.15" # set the basic directory of the server. The default directory is the Apache installation directory.
Listen 80 # Set the IP address and port of the server listener
Loadmodule authn_file_module modules/
Loadmodule authn_dbm_module modules/
Loadmodule authn_anon_module modules/
Loadmodule authn_dbd_module modules/
Loadmodule authn_default_module modules/
Loadmodule authz_host_module modules/
Loadmodule authz_groupfile_module modules/
Loadmodule authz_user_module modules/
Loadmodule authz_dbm_module modules/
Loadmodule authz_owner_module modules/
Loadmodule authz_default_module modules/
Loadmodule auth_basic_module modules/
Loadmodule auth_digest_module modules/
Loadmodule dbd_module modules/
Loadmodule dumpio_module modules/
Loadmodule reqtimeout_module modules/
Loadmodule ext_filter_module modules/
Loadmodule include_module modules/
Loadmodule filter_module modules/
Loadmodule substitute_module modules/
Loadmodule deflate_module modules/
Loadmodule log_config_module modules/
Loadmodule logio_module modules/
Loadmodule env_module modules/
Loadmodule expires_module modules/
Loadmodule headers_module modules/
Loadmodule ident_module modules/
Loadmodule setenvif_module modules/
Loadmodule version_module modules/
Loadmodule mime_module modules/
Loadmodule dav_module modules/
Loadmodule status_module modules/
Loadmodule autoindex_module modules/
Loadmodule asis_module modules/
Loadmodule info_module modules/
Loadmodule cgid_module modules/
Loadmodule dav_fs_module modules/
Loadmodule vhost_alias_module modules/
Loadmodule negotiation_module modules/
Loadmodule dir_module modules/
Loadmodule imagemap_module modules/
Loadmodule actions_module modules/
Loadmodule speling_module modules/
Loadmodule userdir_module modules/
Loadmodule alias_module modules/
Loadmodule rewrite_module modules/
<Ifmodule! Mpm_netware_module>
User daemon # Set the user of the sub-process that actually provides the service.
Group daemon # Set the user group for running Apache sub-processes that provide services.
Serveradmin # sets the Administrator email address included in all error messages returned to the client.
Servername # Set the server to identify its host name and port number (replaced by IP ).
DocumentRoot "/usr/local/Apache-2.2.15/htdocs" # Set the web document root directory.
<Directory/>### <directory> and </directory> are used to encapsulate a group of commands to take effect only for a directory and Its subdirectories.
Options followsymlinks
AllowOverride none
Order deny, allow
Deny from all
<Directory "/usr/local/Apache-2.2.15/htdocs"> # Set the attributes of the specified directory of DocumentRoot
Options indexes followsymlinks # It is recommended to remove Indexes
AllowOverride none
Order allow, deny
Allow from all
<Ifmodule dir_module> # Set the default directory resource list file
Directoryindex index_top.html entrance.html index.html index. php index.htm index. asp index. php3
<Filesmatch "^ \. ht"> # deny access to files starting with. ht to protect. htaccess files
Order allow, deny
Deny from all
Satisfy all
Errorlog "logs/error_log" # specify the Error Log File
Loglevel warn # specify the message level recorded in the error log
<Ifmodule log_config_module> # define the access log format
Logformat "% H % L % u % t \" % R \ "%> S % B \" % {Referer} I \ "\" % {User-Agent} I \ "" combined
Logformat "% H % L % u % t \" % R \ "%> S % B" common
<Ifmodule logio_module>
Logformat "% H % L % u % t \" % R \ "%> S % B \" % {Referer} I \ "\" % {User-Agent} I \ "% I % O" combinedio
Customlog "logs/access_log" common # specify the access log and the format used
<Ifmodule alias_module> # Set the default CGI script directory and alias
ScriptAlias/cgi-bin/"/usr/local/Apache-2.2.15/cgi-bin /"
<Ifmodule cgid_module>
<Directory "/usr/local/Apache-2.2.15/cgi-bin"> # Set the attributes of the default CGI script directory
AllowOverride none
Options none
Order allow, deny
Allow from all
Defaulttype text/plain # Set the default mime content type
<Ifmodule mime_module>
Typesconfig CONF/mime. Types
Addtype application/X-compress. Z
Addtype application/X-gzip. GZ. tgz
<Ifmodule ssl_module>
Sslrandomseed startup builtin
Sslrandomseed connect builtin

<Ifmodule mpm_worker_module> # Use the worker. c module when compiling the parameter -- With-MPM = worker
Serverlimit 25 #/usr/local/Apache-2.2.15/bin/apachectl-l view modules
Threadlimit 200
Startservers 3
Maxclients 2000
Minsparethreads 50
Maxsparethread S 200
Threadsperchild 100
Maxrequestsperchild 1000

Timeout 15
Keepalive on
Maxkeepaliverequests 100
Keepalivetimeout 3
UseCanonicalName off
Accessfilename. htaccess
ServerTokens Prod
Serversignature off
Hostnamelookups off

Namevirtualhost *: 80
<Virtualhost *: 80>
<Virtualhost *: 80>

Bytes -----------------------------------------------------------------------------------------

4. authentication and authorization Configuration

# Add the following content to the httpd. conf configuration file:Code 

AllowOverride none # not used. htaccess file
authtype basic # specify the basic authentication method
authname "Apache. passwd "# specify the authentication domain name
authuserfile/usr/local/Apache-2.2.15/htdocs/protect/Apache. passwd # authentication password storage location
require valid-user # authorize all users in the authentication Password File
# order allow, deny
# Allow from all

** Because DocumentRoot "/usr/local/Apache-2.2.15/htdocs" in the text already specifies your document root directory

** Therefore, create a directory in this directory as the specified file protection location.

** You can also use the alias to specify another directory.

[Root @ test-AS4 ~] # Cd, USR, local, APACHE-2.2.15, and htdocs

[Root @ test-AS4 htdocs] # mkdir protect

[Root @ test-AS4 protect] # htpasswd-C Apache. passwd angel

[Root @ test-AS4 protect] # ll
Total 8
-RW-r -- 1 Root 20 Mar 14 21:14 Apache. passwd
[Root @ test-AS4 protect] # Cat Apache. passwd
ANGEL: grka1xfi6y5rm
[Root @ test-AS4 protect] #

# Open the browser URL: http: //

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.