建网站框架LAMP之:APACHE的安装

  1. 下载httpd:放在目录:/usr/local/src
    http://httpd.apache.org/download.cgi#apache24

建网站框架LAMP之:APACHE的安装
2. 下载apr:放在目录:/usr/local/src
http://apr.apache.org/download.cgi
建网站框架LAMP之:APACHE的安装

  1. 下载apr-util, 放在目录:/usr/local/src
    http://apr.apache.org/download.cgi
    建网站框架LAMP之:APACHE的安装

  2. mkdir /usr/local/zwk_apache

  3. 解压下载好的源码包:
    tar -zxvf /usr/local/src/httpd-2.4.41.tar.gz
    tar -zxvf /usr/local/src/apr-1.7.0.tar.gz
    tar -zxvf /usr/local/apr-util-1.6.1.tar.gz

  4. mv /usr/local/src/httpd-2.4.41 /usr/local/zwk_apache
    mv /usr/local/src/apr-1.7.0 /usr/local/zwk_apache
    mv /usr/local/src/apr-util-1.6.1 /usr/local/zwk_apache

  5. 安装apr(进入apr目录):
    mkdir /usr/local/zwk_apache/apr
    cd /usr/local/zwk_apache/apr
    …/apr-1.7.0/configure --prefix=/usr/local/zwk_apache/apr-1.7.0

make && make install

  1. 安装apr-util(进入apr-util目录):
    mkdir /usr/local/zwk_apache/apr-util
    cd /usr/local/zwk_apache/apr-util
    …/apr-util-16.1/configure --prefix=/usr/local/zwk_apache/apr-util-16.1 --with-apr=/usr/local/zwk_apache/apr-1.7.0

make && make install

如果上面在安装时出现错误,可以试着去安装expat-devel,因为apr-util需要expat-devel依赖。
yum install expat-devel

  1. 继续安装httpd(进入httpd目录):
    mkdir /usr/local/zwk_apache/httpd
    cd /usr/local/zwk_apache/ httpd
    …/httpd-2.4.41/configure
    –prefix=/usr/local/zwk_apache/httpd-2.4.41
    –with-apr=/usr/local/zwk_apache/apr
    –with-apr-util=/usr/local/zwk_apache/apr-util
    –enable-so
    –enable-mods-shared=most

上面,
\ 表示转义字符,加上它可以将一行命令写成多行,更加直观
–prefix 指定安装目录
–enable-so 表示启用DSO,表示支持扩展模块,动态扩展模块,apache和php都支持以一个模块的形式存在
–enable-mods-shared=most 表示指定需要哪些动态扩展的模块,需要加载哪些呢?most就是绝大多数

为了避免在make的时候出错,我们可以提前安装pcre和pcre-devel:
yum install -y pcre pcre-devel

最后编译和安装:
make
make install

此要分开执行,不要使用 make & make install, 这安装失败。

安装完之后,我们可以查看httpd的目录结构及modules目录下面的模块文件:

ls /usr/local/zwk_apache/httpd-2.4.41

bin build cgi-bin conf error htdocs icons include logs man manual modules

bin 命令放置的目录
conf 主要存放了配置文件httpd.conf,这个是最重要的配置文件,Apache的所有主要权限和功能都在这个文件中进行了详细的设置htdocs
logs 日志相关的目录
modules 模块放置的目录

  1. 查看apache加载了哪些模块,使用命令(两条命令一样):
    /usr/local/zwk_apache/httpd-2.4.41/bin/httpd -M
    /usr/local/zwk_apache/httpd-2.4.41/bin/apachectl -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
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)

前面以AH0058开头的行,并不是错误,仅仅是一个警告。带有 shared 字样的,表示该模块为动态共享模块;带有 static 字样的,它表示以静态形式存在。

两者区别在于,静态模块直接和主程序/usr/local/zwk_apache/httpd-2.4.41/bin/httpd绑定在一起,动态模块则是一个个独立存在的文件。

启动apache:

/usr/local/zwk_apache/httpd-2.4.41/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

暂且不管提示的这段信息,我们查看httpd服务是否启动:

ps aux |grep httpd

root 25761 0.0 0.1 70932 2240 ? Ss 20:45 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 25762 0.3 0.2 359896 4260 ? Sl 20:45 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 25763 0.3 0.2 359896 4248 ? Sl 20:45 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon 25768 0.3 0.2 359896 4248 ? Sl 20:45 0:00 /usr/local/apache2.4/bin/httpd -k start
root 25849 0.0 0.0 112720 980 pts/0 S+ 20:45 0:00 grep --color=auto httpd

netstat -lntp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 910/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1292/master
tcp6 0 0 :::3306 ::

上一篇:一起学习log4cxx


下一篇:apache安装错误error: APR not found解决办法