Linux Apache compilation and Installation

Source: Internet
Author: User
Tags builtin

Link: http://liujiesmart.iteye.com/blog/636151

1.download 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:
/Usr/local/Apache-2.2.15/bin/apachectl
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/mod_authn_file.so
Loadmodule authn_dbm_module modules/mod_authn_dbm.so
Loadmodule authn_anon_module modules/mod_authn_anon.so
Loadmodule authn_dbd_module modules/mod_authn_dbd.so
Loadmodule authn_default_module modules/mod_authn_default.so
Loadmodule authz_host_module modules/mod_authz_host.so
Loadmodule authz_groupfile_module modules/mod_authz_groupfile.so
Loadmodule authz_user_module modules/mod_authz_user.so
Loadmodule authz_dbm_module modules/mod_authz_dbm.so
Loadmodule authz_owner_module modules/mod_authz_owner.so
Loadmodule authz_default_module modules/mod_authz_default.so
Loadmodule auth_basic_module modules/mod_auth_basic.so
Loadmodule auth_digest_module modules/mod_auth_digest.so
Loadmodule dbd_module modules/mod_dbd.so
Loadmodule dumpio_module modules/mod_dumpio.so
Loadmodule reqtimeout_module modules/mod_reqtimeout.so
Loadmodule ext_filter_module modules/mod_ext_filter.so
Loadmodule include_module modules/mod_include.so
Loadmodule filter_module modules/mod_filter.so
Loadmodule substitute_module modules/mod_substitute.so
Loadmodule deflate_module modules/mod_deflate.so
Loadmodule log_config_module modules/mod_log_config.so
Loadmodule logio_module modules/mod_logio.so
Loadmodule env_module modules/mod_env.so
Loadmodule expires_module modules/mod_expires.so
Loadmodule headers_module modules/mod_headers.so
Loadmodule ident_module modules/mod_ident.so
Loadmodule setenvif_module modules/mod_setenvif.so
Loadmodule version_module modules/mod_version.so
Loadmodule mime_module modules/mod_mime.so
Loadmodule dav_module modules/mod_dav.so
Loadmodule status_module modules/mod_status.so
Loadmodule autoindex_module modules/mod_autoindex.so
Loadmodule asis_module modules/mod_asis.so
Loadmodule info_module modules/mod_info.so
Loadmodule cgid_module modules/mod_cgid.so
Loadmodule dav_fs_module modules/mod_dav_fs.so
Loadmodule vhost_alias_module modules/mod_vhost_alias.so
Loadmodule negotiation_module modules/mod_negotiation.so
Loadmodule dir_module modules/mod_dir.so
Loadmodule imagemap_module modules/mod_imagemap.so
Loadmodule actions_module modules/mod_actions.so
Loadmodule speling_module modules/mod_speling.so
Loadmodule userdir_module modules/mod_userdir.so
Loadmodule alias_module modules/mod_alias.so
Loadmodule rewrite_module modules/mod_rewrite.so
<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.
</Ifmodule>
Serveradmin you@example.com # sets the Administrator email address included in all error messages returned to the client.
Servername 192.168.221.128 # 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>
<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
</Directory>
<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
</Ifmodule>
<Filesmatch "^ \. ht"> # deny access to files starting with. ht to protect. htaccess files
Order allow, deny
Deny from all
Satisfy all
</Filesmatch>
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
</Ifmodule>
Customlog "logs/access_log" common # specify the access log and the format used
</Ifmodule>
<Ifmodule alias_module> # Set the default CGI script directory and alias
ScriptAlias/cgi-bin/"/usr/local/Apache-2.2.15/cgi-bin /"
</Ifmodule>
<Ifmodule cgid_module>
</Ifmodule>
<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
</Directory>
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>
<Ifmodule ssl_module>
Sslrandomseed startup builtin
Sslrandomseed connect builtin
</Ifmodule>

<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
</Ifmodule>

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

Namevirtualhost *: 80
<Virtualhost *: 80>
DocumentRoot/usr/local/Apache-2.2.15/htdocs/Irene
Servername www.irene.com
</Virtualhost>
<Virtualhost *: 80>
DocumentRoot/usr/local/Apache-2.2.15/htdocs/angel
Servername www.angel.com
</Virtualhost>

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: // 192.168.221.128/protect/

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