Manually compile and install Apache, version httpd-2.4.29 (free installation package, lazy people benefits; provide installation script)

Source: Internet
Author: User

Environment deployment:
this experiment to redhat6.5 system as the installation object, (CentOS other series can also) install Apache source Package httpd-2.4.29.tar.bz2 Dependency Package pcre-8.41.tar.gz, apr-1.6.3.tar.bz2, APR-UTIL-1.6.1.TAR.BZ2
Get the installation package link: Baidu Cloud disk

Https://pan.baidu.com/s/1HPvV68ICTHkNf-ty1VGXyw

Https://pan.baidu.com/s/1h3LBtqCMEAcEugAx6YczGg

https://pan.baidu.com/s/1xSe-UVGowUVAtjfAolSK6w

Https://pan.baidu.com/s/1_HkJeSp1fiBIrirtjgoYow

Uninstall the httpd installed using RPM before installing

Rpm-q httpd #查看系统是否安装有httpd

Yum-y Remove httpd #卸掉rpm安装的httpd

Unzip the source package and the dependency package

Tar xzvf/root/pcre-8.41.tar.gz-c/opt

Tar xjvf/root/apr-1.6.3.tar.bz2-c/opt

Tar xjvf/root/apr-util-1.6.1.tar.bz2-c/opt

Tar xjvf/root/httpd-2.4.29.tar.bz2-c/opt

To move a dependency package to the httpd-2.4.29/srclib/directory

Install the configuration compilation environment component using the Yum command, GCC gcc-c++ expat-devel pcre-devel


Go to the HTTPD-2.4.29/directory and configure the compilation installation. Depending on the actual application needs of the server, the configuration can be flexibly set different customization options, such as specifying the installation path, enable character set support, and so on, to know in detail the various configuration options and meanings available, you can perform "./configure--help"

cd/opt/httpd-z.4.29

./configure \

--PREFIX=/USR/LOCAL/HTTPD \ #指定安装路径

--enable-expires \ #启用缓存模块mod_exprices

--ENABLE-SO \ #启用动态加载模块

--with-mpm=worker \ #更改apache运行模式为worker

--enable-rewrite \ #支持网站地址重写

--enable-charset-lite \ #启用字符集支持

--enable-cgi #启用CGI脚本程序支持

Make && make install

Confirm the installation results because the specified installation directory is/USR/LOCAL/HTTPD, the various programs, modules, Help files, configuration files, etc. of the httpd service are copied to this directory.

In the post-installation/USR/LOCAL/HTTPD directory, the main subdirectories are used as follows

Bin: Various execution Program files for HTTPD service, including main program httpd, Service Control tool APACHECTL, etc.

conf; Various configuration files for storing httpd services, including Master profile httpd,conf, enhanced configuration subdirectory extra, etc.

htdocs; Store Web page documents, including default home file index.html, etc.

logs; log files that store httpd services

Modules; Various module files for storing HTTDP services

Cgi-bin; storing various CGI program files

Optimize the execution path, add httpd to the system service, make it possible to use the service command to manage the HTTPD services installed through the source code, the program path is not in the default search path, in order to make the service easy to use, you can add it as a system service. To be managed through chkconfig. REDIRECT the Apachectl script to/etc/init.d/httpd, add the chkconfig recognition configuration at the beginning of the file, and then add it as a standard system service.

Grep-v "#" Bin/apachectl >/etc/init.d/httpd

Vim/etc/init.d/httpd

#!/bin/bash #shell脚本必要注释

#chkconfig: 2345 #服务识别参数, start in level 2345, and start and close in the order of 85,35

#description: Apache is a Web server #服务描述信息

chmod 755/etc/init.d/httpd #给服务脚本赋予执行权限

Chkconfig--add httpd #将httpd加入系统服务

Chkconfig httpd on #设置httpd开机自启

Ln-s/usr/local/httpd/conf/httpd.conf/etc/httpd.conf #给主配置文件httpd. conf generate a linked file for easy operation

This allows the service command to be used to manage httpd services.

Service httpd Start #开启

Service httpd Stop #关闭

Service httpd Restart #重启

Change the master configuration file for Apache httpd.conf

Vim/etc/httpd.conf

Listen 192.168.30.15:80
#Listen 80

ServerName www.example.com:80




Turn off firewall, SELinux function

Enter the IP in the browser to access, you can see the default homepage of Apache.

For easy installation later, an Apache installation script is organized.

Vim apache.sh

#!/bin/bash
#this is Apache

Date
#判断光盘是否挂载
df-h | Grep/mnt >/dev/null
If [$?-ne 0]
Then
Mount/dev/sr0/mnt >/dev/null
Fi
#创建yum仓库
rm-rf/etc/yum.repos.d/*
Echo-e "[a]\nname=test\nbaseurl=file:///mnt\nenabled=1\ngpgcheck=0" >/etc/yum.repos.d/a.repo
Yum-y install gcc gcc-c++ expat-devel make Pcre-devel &>/dev/null
Tar xzvf/root/pcre-8.41.tar.gz-c/opt &>/dev/null
Tar xjvf/root/apr-1.6.3.tar.bz2-c/opt &>/dev/null
Tar xjvf/root/apr-util-1.6.1.tar.bz2-c/opt &>/dev/null
Tar xjvf/root/httpd-2.4.29.tar.bz2-c/opt &>/dev/null
Cd/opt
MV APR-1.6.3/HTTPD-2.4.29/SRCLIB/APR
MV Apr-util-1.6.1/httpd-2.4.29/srclib/apr-util
MV Pcre-8.41/httpd-2.4.29/srclib/pcre
#进入到apache目录进行配置, compiling and installing
CD httpd-2.4.29/
./configure--prefix=/usr/local/httpd--enable-rewrite--enable-mods-shared=most--with-mpm=worker-- Enable-charset-lite--enable-so--enable-cgi
Make && make install &>/dev/null
#优化执行路径, join httpd to System services
Grep-v "#"/usr/local/httpd/bin/apachectl >/etc/init.d/httpd
Sed-i ' 1i #!/bin/bash\n#chkconfig:2345 40\n#description:apache is a Web server '/ETC/INIT.D/HTTPD
Chkconfig--add httpd
Chkconfig httpd on
Ln-s/usr/local/httpd/conf/httpd.conf/etc/httpd.conf
#监听地址根据实际情况进行更改
Sed-i ' 51c Listen 192.168.30.15:80 '/etc/httpd.conf
Sed-i ' 52c #Listen: '/etc/httpd.conf
Service httpd Start
Service Iptables Stop
Setenforce 0
Date
echo "Apache has been installed"

Gives script execution permissions.

chmod 755 apache.sh

Manually compile and install Apache, version httpd-2.4.29 (free installation package, lazy people benefits; provide installation script)

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.