前记:这几天用空闲的时间尝试的使用yum和手动的方式安装了下Apache服务器。yum方式的安装相对简单(不过yum源配置了好几次,每次都更新不到最新的httpd安装包,无奈yum方式安装是能选择2.2的版本。个大网站都升级了2.4无奈只能使用手动方式安装httpd,中间遇到的问题也是无比的纠结,之前安装的KDB服务器也也搞坏了。系统不知道重新安装了多少次,好在最后经过千辛万苦总算搞定,yum方式安装的修改目录地址权限问题暂时没有解决,反正我也不管了),手动安装相对麻烦,需要自己解决依赖关系,但是自己可以定义安装目录。以下是近期总结的安装心得。
总结:
①虚拟机系统备份一定要有调理
②安装调试过程遇到的问题最好记录
③有时不是你的错,真的就是你电脑性能不好
一、centos下安装Apache2.2服务器(yum方式)
第一步:查看本机是否安装
[root@localhost ~]# rpm -qa httpd
没有安装Apache的不会显示信息,安装过之后会显示相应的信息.
第二步:安装
①查询光盘自带httpd的版本
[root@localhost ~]# yum -y list httpd
Available Packages
httpd.x86_64 2.2.15-29.el6.centos
[root@localhost home]# rpm -qi httpd
Name : httpd Relocations: (not relocatable)
Version : 2.2.15 Vendor: CentOS
Release : 29.el6.centos Build Date: Wed 14 Aug 2013 01:30:33 AM CST
Install Date: Thu 31 Mar 2016 09:24:43 AM CST Build Host: c6b8.bsys.dev.centos.org
Group : System Environment/Daemons Source RPM: httpd-2.2.15-29.el6.centos.src.rpm
Size : 3076447 License: ASL 2.0
Signature : RSA/SHA1, Wed 14 Aug 2013 01:32:39 AM CST, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://httpd.apache.org/
Summary : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.
②安装
[root@localhost ~]# yum -y install httpd.x86_64
……
Installed:
httpd.x86_64 0:2.2.15-29.el6.centos
Dependency Installed:
apr.x86_64 0:1.3.9-5.el6_2 apr-util.x86_64 0:1.3.9-3.el6_0.1
apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 httpd-tools.x86_64 0:2.2.15-29.el6.centos
Complete!
看到如上信息说明安装成功!
第三步:启动及其配置
①启动
单次启动: service httpd start
随机启动: chkconfig httpd on
②配置
1.修改文档根目录为自己需要放置的位置
DocumentRoot "/home/www/html"
<Directory "/home/www/html">
2.修改默认欢迎页面
DirectoryIndex index.php index.html index.html.var
You don't have permission to access / on this server.
第306行
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
allow from all
Satisfy all
</Directory>
<Files ~ "^\.ht">
Order allow,deny
#Deny from all
Satisfy All
</Files>
几个重要目录:
1.默认文档安装目录
/var/www/html
2.配置文件的路径
/etc/httpd/conf/httpd.conf
3.其他的配置存储如下文件夹里
/etc/httpd/conf.d/
二、手动编译安装apache2.4服务器
第一步:前期准备
手动安装Apache需要相关的依赖apr和apr-util查看系统是否安装。没有安装需要去官网下载tar.gz格式的文件。
下载地址为:
http://apr.apache.org/download.cgi
下载好的文件上传到linux服务器
第二步:安装依赖文件
①解压相关文件
[root@localhost home]# # tar -xvf apr-1.5.2.tar.gz
[root@localhost home]# # tar -xvf apr-util-1.5.4.tar.gz
[root@localhost home]# # tar -xvf httpd-2.4.18.tar.gz
1.安装apr
进入apr的解压目录,编译安装(设置安装目录)
[root@localhost home]# cd apr-1.5.2
[root@localhost apr-1.5.2]# ./configure --prefix=/myapp/apr(设置安装目录)
安装时发下如下错误
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
表名系统里没有gcc编译器,需要安装gcc编译器
[root@localhost apr-1.5.2]# yum install gcc
重新配置
[root@localhost apr-1.5.2]# ./configure --prefix=/myapp/apr
出现如下错误
rm: cannot remove `libtoolT': No such file or directory
config.status: executing default commands
将$RM "$cfgfile" 注释掉
重新配置
[root@localhost apr-1.5.2]# ./configure --prefix=/myapp/apr
编译安装
[root@localhost apr-1.5.2]# make & make install
。。。。。
[1]+ Done make
2.安装apr-util
进入apr-util解压目录,将apr的安装目录配置上
[root@localhost home]# cd apr-util-1.5.4
[root@localhost apr-util-1.5.4]# ./configure --prefix=/myapp/apr-util --with-apr=/myapp/apr
编译安装
[root@localhost apr-util-1.5.4]# make & make install
。。。。。。
[1]+ Done make
3.安装httpd
进入httpd的解压目录,配置安装目录,编译安装
[root@localhost home]# cd httpd-2.4.18
[root@ localhost httpd-2.4.18]# ./configure \
>--prefix=/myapp/httpd \
>--sysconfdir=/myapp/httpd/conf \
>--enable-so \
>--enable-rewirte \
>--enable-ssl \
>--enable-cgi \
>--enable-cgid \
>--enable-modules=most \
>--enable-modules-shared=most \
>--enable-mpms-shared=all \
>--with-apr=/myapp/apr \
>--with-apr-util=/myapp/apr-util
执行发现如下错误:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
说明缺少pcre包,安装pcre包,若查询本机已经安装了pcre包,说没系统还缺少pcre-devel包
[root@localhost httpd-2.4.18]# yum install pcre-devel
安装完成之后重新执行上述配置;
又出现如下问题
checking for OpenSSL... checking for user-provided OpenSSL base directory... none
checking for OpenSSL version >= 0.9.8a... FAILED
configure: WARNING: OpenSSL version is too old no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
说明需要更新OpenSSL和安装OpenSSL-devel
[root@localhost httpd-2.4.18]# yum install openssl-devel
重新配置,完成之后,进行编译安装。
[root@localhost httpd-2.4.18]# make & make install
make[1]: Leaving directory `/home/httpd-2.4.18'
[1]+ Done make
第三步:配置启动脚本
1.使用init脚本管理httpd
[root@localhost httpd-2.4.18]# cp build/rpm/httpd.init /etc/init.d/httpd
2.修改httpd
[root@localhost httpd-2.4.18]# vi /etc/init.d/httpd
httpd=${HTTPD-/usr/sbin/httpd} 修改成 httpd=${HTTPD-/myapp/httpd/bin/httpd}
pidfile=${PIDFILE-/var/run/${prog}.pid} 修改成pidfile=${PIDFILE-/myapp/httpd/logs/${prog}.pid}
lockfile=${LOCKFILE-/var/lock/subsys/${prog}}
RETVAL=0
# check for 1.3 configuration
check13 () {
CONFFILE=/etc/httpd/conf/httpd.conf 修改成CONFFILE=/myapp/httpd/conf/httpd.conf
[root@localhost httpd-2.4.18]# chmod 755 /etc/init.d/httpd //增加执行权限
[root@localhost httpd-2.4.18]# chkconfig --add httpd //添加httpd到服务开机启动
[root@localhost httpd-2.4.18]# cd /usr/sbin/
[root@localhost httpd-2.4.18]# ln -s /myapp/httpd/bin/* .
为日志文件创建软链接
[root@NFSServer sbin]# ln -s /myapp/httpd/logs /var/log/httpd
3.启动
启动时出现如下错误信息
[root@localhost httpd]# service httpd start
Starting httpd: 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 [ OK ]
这是需要修改两处信息
修改/etc/hosts,增加一行
127.0.0.1 localhost
修改 /myapp/httpd/conf/httpd.conf,增加一行
ServerName localhost
4.无法访问问题
当httpd服务启动之后无法访问网页,可能是linux服务器访问80端口被防火墙限制,可以开通80端口的防火墙,或者把防火墙关闭。
将80端口添加到策略中
[root@localhost ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state –-state NEW -m tcp -p tcp –-dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
将80端口添加到22端口后面,如果直接添加到最后边,防火墙可能启动会失败。
重启防火墙
[root@localhost ~]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
查看防火墙状态,可以看到80端口已经进入到策略里面
[root@localhost ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
6 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
重新访问,可以访问到默认的欢迎页面
╮(╯▽╰)╭还要去写头痛的前端
来自weduoo 点击打开链接