1.3 Apache安装:
- Apache是一个基金会的名字,httpd才是我们要安装的软件包,早期它的名字就叫apache
Apache官网www.apache.org
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz
wget http://mirrors.hust.edu.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.5.4.tar.gz - apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows)
tar zxvf httpd-2.4.26.tar.gz
tar zxvf apr-util-1.5.4.tar.gz
tar zxvf apr-1.5.2.tar.gz - cd /usr/local/src/apr-1.5.2
./configure --prefix=/usr/local/apr
make && make install - cd /usr/local/src/apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install - cd /usr/local/src/httpd-2.4.25
./configure \ //这里的反斜杠是脱义字符,加上它我们可以把一行命令写成多行
--prefix=/usr/local/apache2.4 \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-so \ //表示支持动态扩展模块
--enable-mods-shared=most //加载大部分动态扩展模块 - make && make install
ls /usr/local/apache2.4/modules
/usr/local/apache2.4/bin/httpd -M //查看加载的模块
apr函数库安装:
[root@Dasoncheng ~]# cd /usr/local/src/
[root@Dasoncheng src]# tar -zxf apr-1.5.2.tar.gz
[root@Dasoncheng src]# tar -zxf apr-util-1.5.4.tar.gz
[root@Dasoncheng src]# tar -zxf httpd-2.4.27.tar.gz
[root@Dasoncheng src]# ls
apr-1.5.2 apr-util-1.5.4.tar.gz mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-1.5.2.tar.gz httpd-2.4.27 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
apr-util-1.5.4 httpd-2.4.27.tar.gz
[root@Dasoncheng src]# cd apr-1.5.2
[root@Dasoncheng apr-1.5.2]# ./configure --prefix=/usr/local/apr ##编译安装,--prefix指定安装目录;
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring APR library
Platform: x86_64-unknown-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.5.2
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/apr-1.5.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
[root@Dasoncheng apr-1.5.2]# echo $?
1
[root@Dasoncheng apr-1.5.2]# cat config.log
##报错,查看报错信息 再查看日志,未安装gcc库;
[root@Dasoncheng apr-1.5.2]# yum install -y gcc
……
[root@Dasoncheng apr-1.5.2]# ./configure --prefix=/usr/local/apr/
……
[root@Dasoncheng apr-1.5.2]# echo $?
0
[root@Dasoncheng apr-1.5.2]# make && make install ##安装;
[root@Dasoncheng apr-1.5.2]# echo $?
0
##安装成功;
apr-util函数库安装:
[root@Dasoncheng apr-1.5.2]# cd ../apr-util-1.5.4
[root@Dasoncheng apr-util-1.5.4]#
[root@Dasoncheng apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
##编译安装,--prefix指定安装路径、--with-apr指定关联文件目录;
[root@Dasoncheng apr-util-1.5.4]# echo $?
0
[root@Dasoncheng apr-util-1.5.4]# make && make install ##安装;
[root@Dasoncheng apr-util-1.5.4]# echo $?
0
##安装成功;
httpd安装:
因为安装httpd有依赖apr和apr-util(可以理解为一个通用的函数库) ,所以提前安装了。不安装的话 httpd无法正常工作!
[root@Dasoncheng httpd-2.4.27]# ./configure \
> --prefix=/usr/local/apache2.4 \
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-so \ ##这个表示支持启用DSO,即支持动态拓展模块;
> --enable-mods-shared=most ##表示加载大部分动态模块(故安装有点慢);
……
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
##这里报错了,需要安装一些库文件;
[root@Dasoncheng httpd-2.4.27]# yum install -y pcre prce-devel
[root@Dasoncheng httpd-2.4.27]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-so --enable-mods-shared=most
#安装库文件之后,重新编译:
……
……
[root@Dasoncheng httpd-2.4.27]# echo $?
0
[root@Dasoncheng httpd-2.4.27]# make && make install
……
……
[root@Dasoncheng httpd-2.4.27]# echo $?
0
##到这里安装就完成了;
httpd模块查看:
[root@Dasoncheng ~]# ls /usr/local/apache2.4/ ##查看httpd目录结构;
bin build cgi-bin conf error htdocs icons include logs man manual modules
[root@Dasoncheng ~]# ls /usr/local/apache2.4/modules/ ##这个是动态模块目录;
httpd.exp mod_dbd.so mod_proxy_http.so
mod_access_compat.so mod_dir.so mod_proxy_scgi.so
mod_actions.so mod_dumpio.so mod_proxy.so
mod_alias.so mod_env.so mod_proxy_wstunnel.so
mod_allowmethods.so mod_expires.so mod_ratelimit.so
mod_auth_basic.so mod_ext_filter.so mod_remoteip.so
……
[root@Dasoncheng ~]# /usr/local/apache2.4/bin/httpd -M ##查看已加载的模块;
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
##这上面不是报错,而是让你在配置文件设置servername哦!
Loaded Modules:
core_module (static) ##这个static表示静态模块,直接和httpd主程序绑定在一起 是找不到这些模块的目录的哦!
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared) ##这个shared表示动态模块,在目录modules下;
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
……
##其中:动态和静态的区别在于
##静态模块直接和主程序(/usr/local/apache2.4/bin/httpd)绑定在一起,我们看不到。
##而动态的模块都是一个个独立存在的(modules)目录下的.so文件;
启动httpd:
[root@Dasoncheng ~]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@Dasoncheng ~]# ps aux |grep httpd
root 34165 0.0 0.2 70864 2200 ? Ss 03:56 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 34166 0.1 0.4 359828 4244 ? Sl 03:56 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 34167 0.1 0.4 359828 4244 ? Sl 03:56 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 34168 0.1 0.4 359828 4240 ? Sl 03:56 0:00 /usr/local/apache2.4/bin/httpd -k start
root 34251 0.0 0.0 112664 968 pts/0 S+ 03:56 0:00 grep --color=auto httpd
[root@Dasoncheng ~]# netstat -lntp |grep httpd
tcp6 0 0 :::80 :::* LISTEN 34165/httpd
apache dso https://yq.aliyun.com/articles/6298
apache apxs http://man.chinaunix.net/newsoft/ApacheMenual_CN_2.2new/programs/apxs.html
apache工作模式 http://www.cnblogs.com/fnng/archive/2012/11/20/2779977.html