Compiling and installing Apache services

Source: Internet
Author: User

about Apache

Apache httpd can also be referred to as httpd or Apache, which is one of the most widely used Web servers in the Internet, using the Web server provided by Apache is the daemon httpd, through the HTTP protocol for text transmission, the default use of 80-port clear text transmission, of course, later, in order to ensure the security and reliability of data, and added 443 encryption the way to lose, Apache provides the server is also known as: Patch Server, the reason is very simple, it is a highly modular software, want to add to it the corresponding function just add the corresponding module, so that its Apache main program to load the corresponding modules, unnecessary modules can not be loaded, to ensure the simplicity of Apache, lightweight, efficient, when there is a large number of access to a service multiple multiplexing modes are available to ensure that the server can respond quickly to client requests, such as MPM, Port Multiplexing technology.


1. Installation Dependent environment

[[email protected] ~]# yum install-y gcc* # #安装gcc because it is a minimal installation of CentOS 7, so you need to install Gcc[[email protected] ~]# yum Groupinstall "D Evelopment Tools "" Server Platform Development "y # #安装开发依赖包 [[email protected] ~]# yum install pcre*-y # #支持正则表达式


2. Install Apr

[[Email protected] ~]# cd /usr/local/src/[[email protected] src]# wget  http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz[[email protected] src]# wget  http://mirror.bit.edu.cn/apache/apr/apr-1.6.3.tar.bz2[[email protected] src]# tar - xf apr-1.6.3.tar.bz2 [[email protected] src]# cd apr-1.6.3[[email protected ] apr-1.6.3]# ./configure --prefix=/usr/local/apr# #如果出现rm: cannot remove  ' Libtoolt ':  no such file or directory Problem Resolution: [[email protected] apr-1.6.3]#  vim configure rm= ' $RM ' modified to rm= ' $RM  -f '   (note that there must be a space in front of-f) [[email protected] apr-1.6.3 ]# make && make install[[email protected] src]# tar -xf  apr-util-1.6.1.tar.gz [[email protected] src]# cd apr-util-1.6.1[[email  Protected] apr-util-1.6.1]#&nbSp; ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr[[email protected]  apr-util-1.6.1]#  make && make install# #如果编译不成功, try installing expat-devel and compiling again [[Email protected] apr-util-1.6.1]# yum install expat-devel -y


3. Download Apache installation package and unzip

[Email protected] ~]# cd/usr/local/src/[[email protected] src]# wget http://mirrors.hust.edu.cn/apache/httpd/ Httpd-2.4.28.tar.gz[[email protected] src]# tar-xf httpd-2.4.28.tar.gz


4. Compile and install

[[email protected] src]# cd httpd-2.4.28[[email protected] httpd-2.4.28]# . /configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/ apr-util --with-pcre --enable-so --enable-ssl --enable-cgi --enable-rewrite -- with-zlib --enable-deflate --enable-expires --enable-headers --enable-modules=most -- enable-mpms-shared=all --with-mpm=worker# #如果出错, try installing Openssl-devel again [[email protected]  httpd-2.4.28]# yum install -y openssl-devel[[email protected] httpd-2.4.28]#  make && make install# #如果make时出现以下的错误collect2:  error: ld returned  1 exit statusmake[2]: *** [htpasswd] Error 1make[2]: Leaving  directory  '/usr/local/src/httpd-2.4.28/support ' make[1]: *** [all-recursive] error  1make[1]: leaving directory  '/usr/local/src/httpd-2.4.28/support ' make: *** [all-recursive] error  1 Workaround: Add--with-included-apr[[email protected] httpd-2.4.28]# ./configure --prefix=/usr/later local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre -- Enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --enable-deflate  --enable-expires --enable-headers --enable-modules=most --enable-mpms-shared=all -- With-mpm=worker --with-included-apr but with the--WITH-INCLUDED-APR compiled, the following issues occur configure: error:  Bundled apr requested but not found at ./srclib/. download and  unpack the corresponding apr and apr-util packages to ./srclib/. workaround [[email protected] httpd-2.4.28]# cd /usr/local/src/[[email protected] src]#  cp -r apr-1.6.3 /usr/local/src/httpd-2.4.28/srclib/apr[[email protected] src]# cp -r  Apr-util-1.6.1 /usr/local/src/httpd-2.4.28/srclib/apr-util and then compile again without problems and no problem with make. Note:--with-pcre                             #支持perl的正则表达式, or you'll get an error--enable-so                             #激活apache服务的DSO (full name Dynamic shared object, dynamic shared object) support, that is, in the future can be the DSO to compile the installation of the shared module, the module itself can not be compiled by DSO. --enable-ssl                           #基于ssl加密传输--enable-cgi                            #开启CGI脚本--enable-rewrite                      #  provides rewrite functionality based on URL rules. That is, depending on the known URL address, convert the other desired URL address. The pseudo-static function described in the previous article is the implementation of this module. This is an important feature that must be used in the Apache production environment. --with-zlib                            #支持压缩--enable-deflate                      #  To provide the content of compressed transmission encoding support, general HTML,JS,CSS and other content of the site, the use of this parameter function will greatly improve the transmission speed, improve the visitor experience. In a production environment, this is one of the important options for Apache tuning. --enable-expires                      #  activation allows the "Expires:" and "Cache-control:" header content to be controlled via the configuration file, that is, the content of the website picture, JS, CSS, etc. Provides settings that are cached in the client browser. This is one of the important options for Apache tuning. --enable-headers                       #提供允许对HTTP请求头的控制--enable-modules=most                  #支持大多数模块--enable-mpms-shared=all               #mpm模块的动态切换--with-mpm=worker                       #选择apache   The MPM mode is worker mode. Because the worker mode principle is that more threads are used to process requests, more concurrent requests can be processed, and system resources are less expensive than process-based mpm prefork. If you do not specify this parameter, the default mode is Prefork process mode.


5. View the relevant configuration file

[[email protected] ~]# cd/usr/local/apache/[[email protected] apache]# lsbin build cgi-bin conf error htdocs icons Include Lib logs man manual modules

Note:

Ab:apache comes with a stress test.

Apachectl: Startup script.

APXS: Dynamic load module.

HTPASSWD: Encryption.

Httpd:apache Background start service.

Rotatelogs: Log slicing.


6, modify the user

For security reasons, we need to specify the user to be run, modify it to another custom user, and modify it as a Web user.

[[Email protected] ~]# vim /usr/local/apache/conf/httpd.conf<ifmodule unixd_module >User webGroup web</IfModule>[[email protected] ~]# ps -ef |  Grep httpdroot      61726      1  0  11:12 ?        00:00:00 /usr/local/apache/bin/httpdweb        61727  61726  0 11:12 ?         00:00:00 /usr/local/apache/bin/httpdweb        61728  61726  0 11:12 ?         00:00:00 /usr/local/apache/bin/httpdweb       61729   61726  0 11:12 ?        00:00:00 /usr/local/ Apache/bin/httpdroot      61812    982  0 11:12 pts/0     00:00:00 grep --color=auto httpd


7. Start Apache Service

[[email protected] ~]#/usr/local/apache/bin/apachectl AH00558:httpd:Could not reliably determine the server ' s fully qua Lified domain name, using Localhost.localdomain. Set the ' ServerName ' directive globally to suppress this message# #出现报错, need to uncomment [[email protected] ~]# vim/usr/local/apache/ conf/httpd.conf ServerName localhost:80[[email protected] ~]#/usr/local/apache/bin/apachectl-t # # Check Apache configuration for errors Syntax Ok[[email protected] ~]#/usr/local/apache/bin/apachectl # #启动 httpd (PID 61571) already running


8. Configure Startup scripts

[Email protected] ~]# Cat/usr/lib/systemd/system/httpd.service [Unit]description=httpdafter=network.target [ Service]type=forkingexecstart=/usr/local/apache/bin/apachectl Execstop=/usr/local/apache/bin/apachectl Stopprivatetmp=true [install]wantedby=multi-user.target[[email protected] ~]# chmod a+x/usr/lib/systemd/system/ Httpd.service # #给执行权限 [[email protected] ~]# systemctl enable httpd # #设为开机自启


9. Module Directory

To store the Apache module, we want to support this feature and must load a response module.

[Email protected] ~]# vim/usr/local/apache/conf/httpd.conf # #查看配置文件LoadModule Mpm_worker_module modules/mod_mpm_ Worker.soloadmodule unixd_module modules/mod_unixd.so#loadmodule dav_module modules/mod_dav.soloadmodule status_ Module Modules/mod_status.soloadmodule autoindex_module modules/mod_autoindex.so Note: When compiling, use-with-module or APXS to dynamically load


10. Configuration file Description

(1), loading module: alias_module

[Email protected] ~]# vim/usr/local/apache/conf/httpd.conf<ifmodule alias_module> scriptalias/cgi-bin/"/usr/ local/apache/cgi-bin/"</IfModule>


(2), log processing module

[[Email protected]calhost ~]# vim /usr/local/apache/conf/httpd.conf<ifmodule log_ config_module>    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>      # you need to enable mod_ logio.c to use %i and %o      logformat  "%h % L %u %t \ "%r\"  %>s %b \ "%{referer}i\"  \ "%{user-agent}i\"  %I %O " combinedio    </IfModule>    CustomLog " Logs/access_ Log " common    #    # If you prefer a  logfile with access, agent, and referer information    #  (Combined  Logfile format)  you can use the following directive.     #     #CustomLog   "Logs/access_log"  combined</ifmodule>### You can customize the log format:logformat  "%h %l %u %t \"%r\ " %>s %b"  commoncustomlog   "Logs/access_log"  common    # #日志存放路径, we need to add comon before using a custom log to make it effective.


(3), support PHP

[[email protected] ~]# vim/usr/local/apache/conf/httpd.conf Find the AddType place and add the following 2 lines: AddType application/x-httpd-php. php. PhP3. phtml. Incaddtype Application/x-httpd-php-source. Phps


Compiling and installing Apache services

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.