一、下载文件
1、下载apache(现在版本都是以这样的方式表达的:httpd-*.*.*.tar.gz),去apache.org官网:http://apache.org/dist/httpd/
( 例如,下载的就是最新版本:httpd-2.4.23.tar.gz,放到你指定的目录/tmp/sotfware里面。)
2、准备apache安装之前的apr、apr-util和pcre(其中apr和apr-util去http://apr.apache.org/download.cgi下载,pcre去https://sourceforge.net/projects/pcre/files/pcre/8.39/下载)我下载的是apr-1.5.2.tar.gz、apr-util-1.5.4.tar.gz和pcre-8.39.tar.gz
3、我在window下载完成后用ssh连接到linux系统,将下载文件复制到/tmp/sotfware目录中
二、开始安装
1.安装apr-1.5.2.tar.gz 安装目录是/usr/local/apr
[root@localhost software]# tar -zxf apr-1.5.2.tar.gz
[root@localhost software]# cd apr-1.5.2
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.5.2]# make
[root@localhost apr-1.5.2]# make install
2.安装apr-util-1.5.4.tar.gz安装目录是/usr/local/apr-util
[root@localhost software]# tar -zxvf apr-util-1.5.4.tar.gz
[root@localhost software]# cd apr-util-1.5.4
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@localhost apr-util-1.5.4]# make
[root@localhost apr-util-1.5.4]# make install
3.安装pcre-8.39 安装目录是/usr/local/pcre
[root@localhost software]# tar -zxvf pcre-8.39.tar.gz
[root@localhost software]# cd pcre-8.39
[root@localhost pcre-8.39]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.39]# make
[root@localhost pcre-8.39]# make install
4.安装apache2.4.23安装目录是/usr/local/apache
[root@localhost software]# tar -zxvf httpd-2.4.23.tar.gz
[root@localhost software]# cd httpd-2.4.23
[root@localhost httpd-2.4.23]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --enable-module=so --enable-mods-shared=all --enable-module=rewirte --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --disable-cgid --disable-cgi
[root@localhost httpd-2.4.23]# make
[root@localhost httpd-2.4.23]# make install
三、修改httpd.conf
[root@localhost httpd-2.4.23]# cd /usr/local/apache/conf/
[root@localhost conf]# vi httpd.conf
将ServerName前的“#”去掉,将www.example.com改成 192.168.1.67:80(我的服务器地址就是192.168.1.67)
四、启动apache
[root@localhost conf]# cd /usr/local/apache/bin/
[root@localhost conf]# ./apachectl start
五、通过本机浏览器输入地址192.168.1.67:80
显示It works
表示apache正常启动完成了
如果有问题可以考虑防火墙是否开放了80端口
六、apache的安装命令详解
apache 安装好后 启动出错:
httpd: Syntax error on line 143 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/mod_dir.so into server: /usr/local/apache2/modules/mod_dir.so: undefined symbol: apr_array_clear
由于 apache编译时没有指定 --with-included-apr 参数
可是重新编译时又发现问题:
执行配置安装httpd时出错
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
是由于:需要下载apr和apr-utils 并解压到./srclib/, 再进行编译
cp -R /opt/software/apr-1.5.2 /opt/sotfware/httpd-2.4.23/srclib/apr
cp -R /opt/software/apr-util-1.5.4 /opt/sotfware/httpd-2.4.23/srclib/apr-util
再编译:
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-included-apr --enable-module=so --enable-mods-shared=all --enable-module=rewirte --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --disable-cgid --disable-cgi