CentOS下编译安装Apache
2015-04-17 17:20
489 查看
与Apache 2.2.x相比,Apache 2.4.x提供了很多性能方面的提升,包括支持更大流量、更好地支持云计算、利用更少的内存处理更多的并发等。除此之外,还包括性能提升、内存利用、异步 I/O的支持、动态反向代理设置、与时间驱动的Web服务器相当或更好的性能、更强大的处理资源分配能力,更便捷的缓存支持以及可定制的高速服务器和代理 等。其它的功能还包括更简单的错误分析、更灵活的设置项、更强大的验证机制和更完整的文档。
Apache服务器项目管理委员会和Apache基金会主席Jim Jagielski表示,他们希望终端用户能真正地看到性能进步,Apache 2.4.x比许多以速度见长的Web服务器更快,例如 Nginx。
apache-2.2与新出的apache-2.4安装不同的地方在于,2.4版的已经不自带apr库,所以在安装apache-2.4之前,需要下载apr。
所需源码包
apr-1.4.6.tar.gz(可从http://apr.apache.org/download.cgi下载到最新版本)
apr-util-1.4.1.tar.gz(可从http://apr.apache.org/download.cgi下载到最新版本)
httpd-2.4.6.tar.gz(可从http://www.apache.org/dist/httpd/下载到最新版本)
pcre-8.33.tar.gz(可从ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下载到最新版本)
#安装 apr
#安装 apr-util
#安装 pcre
注意:可能会出现"configure: error: You need a C++ compiler for C++ support.",运行以下命令安装c++编译器,再重新执行configure即可。
安装 Apache2.4.6
编译参数解释:
--prefix=/usr/local/apache :指定安装目录
--with-apr=/usr/local/apr : apr库
--with-apr-util=/usr/local/apr-util :apr-util库
--with-pcre=/usr/local/pcre : pcre库
--enable-so : 允许运行时加载DSO模块(注意:so模块需静态编译)
--enable-deflate=shared : 将deflate模块编译为DSO
--enable-expires=shared : 将expires模块编译为DSO
--enable-ssl=shared : 将ssl模块编译为DSO
--enable-headers=shared : 将headers模块编译为DSO
--enable-rewrite=shared : 将rewrite模块编译为DSO
--enable-static-support : 使用静态连接(默认为动态连接)编译所有二进制支持程序
--with-mpm=prefork : 使用prefork形式的mpm
更详细的编译参数解释:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/configure.html
安装尚未成功,还需进行以下的操作:
修改init命令文件
主要是修改文件中pidfile参数的值(进程文件指向)
把其中的
修改为
配置防火墙,开启80端口
#添加如下规则到22端口这条规则的下面即可
#重启防火墙
启动Apache
安装过程中可能会出现以下问题:
编译Apache时出现:
解决办法:
启动Apache时出现:
解决办法:
#vi /etc/httpd/conf/httpd.conf (在这里/etc/httpd是我安装apache的目录)
找到#ServerName www.example.com:80 把#去掉,再重启apache即可没事了。
Apache服务器项目管理委员会和Apache基金会主席Jim Jagielski表示,他们希望终端用户能真正地看到性能进步,Apache 2.4.x比许多以速度见长的Web服务器更快,例如 Nginx。
apache-2.2与新出的apache-2.4安装不同的地方在于,2.4版的已经不自带apr库,所以在安装apache-2.4之前,需要下载apr。
所需源码包
apr-1.4.6.tar.gz(可从http://apr.apache.org/download.cgi下载到最新版本)
apr-util-1.4.1.tar.gz(可从http://apr.apache.org/download.cgi下载到最新版本)
httpd-2.4.6.tar.gz(可从http://www.apache.org/dist/httpd/下载到最新版本)
pcre-8.33.tar.gz(可从ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下载到最新版本)
#安装 apr
cd /usr/local/src/Apache-2.4.6 tar -xzvf ./apr-1.4.6.tar.gz cd ./apr-1.4.6 mkdir /usr/local/apr ./configure --prefix=/usr/local/apr make && make install
#安装 apr-util
cd /usr/local/src/Apache-2.4.6 tar -xzvf ./apr-util-1.4.1.tar.gz cd ./apr-util-1.4.1 mkdir /usr/local/apr-util ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config make && make install
#安装 pcre
cd /usr/local/src/Apache-2.4.6 tar -xzvf ./pcre-8.33.tar.gz cd ./pcre-8.33 mkdir /usr/local/pcre ./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config make && make install
注意:可能会出现"configure: error: You need a C++ compiler for C++ support.",运行以下命令安装c++编译器,再重新执行configure即可。
yum install -y gcc gcc-c++
安装 Apache2.4.6
cd /usr/local/src/Apache-2.4.6 tar -xzvf ./httpd-2.4.6.tar.gz cd ./httpd-2.4.6 ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-deflate=shared --enable-expires=shared --enable-ssl=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support --with-mpm=prefork make && make install
编译参数解释:
--prefix=/usr/local/apache :指定安装目录
--with-apr=/usr/local/apr : apr库
--with-apr-util=/usr/local/apr-util :apr-util库
--with-pcre=/usr/local/pcre : pcre库
--enable-so : 允许运行时加载DSO模块(注意:so模块需静态编译)
--enable-deflate=shared : 将deflate模块编译为DSO
--enable-expires=shared : 将expires模块编译为DSO
--enable-ssl=shared : 将ssl模块编译为DSO
--enable-headers=shared : 将headers模块编译为DSO
--enable-rewrite=shared : 将rewrite模块编译为DSO
--enable-static-support : 使用静态连接(默认为动态连接)编译所有二进制支持程序
--with-mpm=prefork : 使用prefork形式的mpm
更详细的编译参数解释:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/configure.html
安装尚未成功,还需进行以下的操作:
cp ./build/rpm/httpd.init /etc/init.d/httpd #使用init脚本管理httpd chmod 755 /etc/init.d/httpd #增加执行权限 chkconfig --add httpd #添加httpd到服务项 chkconfig --level 2345 httpd on #设置开机启动 chkconfig --list httpd #查看是否设置成功 mv /etc/httpd /etc/httpd_old #移走旧的httpd文件夹 ln -s /usr/local/apache /etc/httpd #建立httpd的软链接, #到时候,Apache的配置文件路径为 /etc/httpd/conf/httpd.conf,其实真实路径为 /usr/local/apache/conf/httpd.conf ln -sf /usr/local/apache/bin/httpd /usr/sbin/httpd #设置软链接以适应init脚本 ln -sf /usr/local/apache/bin/apachectl /usr/sbin/apachectl rm -rf /var/log/httpd/ ln -s /usr/local/apache/logs /var/log/httpd groupadd apache #添加apache用户组及用户 useradd -g apache -s /usr/sbin/nologin apache chown -R apache:apache /usr/local/apache
修改init命令文件
主要是修改文件中pidfile参数的值(进程文件指向)
vim /etc/init.d/httpd
把其中的
pidfile=${PIDFILE-/var/run/${prog}.pid}
修改为
pidfile=${PIDFILE-/usr/local/apache/logs/${prog}.pid}
配置防火墙,开启80端口
vim /etc/sysconfig/iptables
#添加如下规则到22端口这条规则的下面即可
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
#重启防火墙
service iptables restart # 或 /etc/init.d/iptables restart
启动Apache
service httpd start # 或 /etc/init.d/httpd start
安装过程中可能会出现以下问题:
编译Apache时出现:
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
解决办法:
yum install openssl-devel
启动Apache时出现:
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
解决办法:
#vi /etc/httpd/conf/httpd.conf (在这里/etc/httpd是我安装apache的目录)
找到#ServerName www.example.com:80 把#去掉,再重启apache即可没事了。
相关文章推荐
- centos下编译安装apache
- centos6下源码编译安装LAMP平台(apache2.4+php5.4+mysql5.5.30)
- centos6.3编译安装Apache2.4.3+PHP5.4.8+Mysql5.5.8
- CentOS6.8 x64+Nginx1.3.8/Apache-httpd 2.4.3+PHP5.4.8(php-fpm)+MySQL5.5.28+CoreSeek4.1源码编译安装
- [Centos]编译安装apache 2.4
- CentOS 4.4下源码编译安装apache+php+mysql
- CentOS 源码编译安装LAMP(Apache MySQL PHP)
- centos将自编译安装的apache添加为linux系统服务
- Centos5.9下编译安装LAMP(apache 2.4.4 mysql 5.6.10 php 5.4.12) 推荐
- centos 编译安装apache
- Centos编译安装Apache 2.4.7
- Linux---CentOS下编译安装Apache后只显示测试页面解决方法
- centos6.6编译安装apache
- centos编译安装apache
- LAMP环境配置三步曲之(一) CentOS 编译安装 Apache
- 在centos6.5mini系统上编译安装Apache
- Centos编译安装Apache 2.4.6笔记 配置
- 详解Centos源码编译安装Apache、PHP 推荐
- CentOS6.3 编译安装LAMP(2):编译安装 Apache2.2.25
- CentOS 下编译安装 Apache 并配置 SSL 模块以支持 HTTPS