您的位置:首页 > 理论基础 > 计算机网络

linux安装apache httpd

2015-07-17 10:17 495 查看
本以为linux下安装apache是件很简单的过程。三命令就可以搞定,jxvf解压,make 编译,make install 安装就OK了。没想到这个过程还颇费周折。可能和环境有关吧。先说一下我的环境。

---------------------------

linux :    cenos5.5  (验证4.8也会碰到以下问题)

apache:  httpd-2.4.1.tar.bz2

---------------------------

[root@localhost apache]# tar jxvf httpd-2.4.1.tar.bz2      //解压apache的压缩包

[root@localhost apache]# cd httpd-2.4.1       //定位到httpd-2.4.1 文件夹下

[root@localhost httpd-2.4.1]# ls       //查看显示httpd-2.4.1 文件夹下内容

[root@localhost httpd-2.4.1]#./configure --help | more      //查看安装apache配置参数

[root@localhost httpd-2.4.1]#./configure  --prefix=/usr/local/apache  --enable-so      //  配置apache路径 ,后面跟 --enable-so 参数表示让apache核心装载DSO

[root@localhost httpd-2.4.1]# make   //编译apache 

出错了!提示:

configure: error: APR not found. Please read the documentation 

在apache官网上可以下载到 apr-1.4.6.tar.gz 

解决apr not found问题>>>> 

APR和APR-UTIL的下载地址:http://apr.apache.org/download.cgi

   [root@localhost apache]# tar -zxf apr-1.4.6.tar.gz

   [root@localhost apache]# cd apr-1.4.6

   [root@localhost apr-1.4.6]# ./configure --prefix=/usr/local/apr

   [root@localhost apr-1.4.6]# make

   [root@localhost apr-1.4.6]# make install

 

安装完成后,再来编译apache 

  [root@localhost httpd-2.4.1]# make

又出错了!提示:

configure: error: APR-util not found. Please read the documentation 

好吧!还是上面的apache官网地址再下载 apr-util-1.4.1.tar.gz 

解决APR-util not found问题>>>>

   [root@localhost apache]# tar -zxf  apr-util-1.4.1.tar.gz

[root@localhost apache]#  cd  apr-util-1.4.1

   [root@localhost apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

  [root@localhost apr-util-1.4.1]# make

  [root@localhost apr-util-1.4.1]# make install

 

再来编译apache ,再次出错!提示:

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ , 我X !linux 安装软件之间关联性有时能让人崩溃。

../configure仍提示APR-util not found,增加--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util后出现>>>>>

[root@localhost apache]# ./configure –help | grep pcre

--with-pcre=PATH        Use external PCRE library

下载地址:http://ftp.exim.llorien.org/pcre/

下载pcre-8.30.zip ,列表文件较多,一般浏览器会有搜索功能,你可ctrl+f 搜索定位后下载。

[root@localhost apache]#unzip -o pcre-8.30.zip

[root@localhost apache]#cd pcre-8.30

[root@localhost pcre-8.30]#./configure --prefix=/usr/local/pcre

[root@localhost pcre-8.30]#make

[root@localhost pcre-8.30]#make install

编译Apache

  [root@yahoo httpd-2.3.12-beta]# ./configure --prefix=/usr/local/apache2  --with-apr=/usr/local/apr  --with-apr-util=/usr/local/apr-util/  
--with-pcre=/usr/local/pcre


  注意,这里后面跟的参数,一定要与前面安装apr 和apr-util的路径一致。

 [root@localhost httpd-2.4.1]# make

 [root@localhost httpd-2.4.1]# make install

 这次编译安装应该不会再报任何错误了。哈哈!!

 

启动apache

[root@localhost bin]# pwd

/usr/local/apache/bin

[root@localhost bin]# apachectl stop  停止

[root@localhost bin]# apachectl start  启动

 

查看80端口是否被占用

[root@localhost conf]#netstat -an | grep :80    

 

查看apache 启动服务是否启动

[root@localhost bin]# ps -aux | grep httpd

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ

root      2866  0.0  1.2  25164  9556 ?        Ss   22:45   0:00 /usr/sbin/httpd -k start

apache    2867  0.0  0.7  25300  5556 ?        S    22:45   0:00 /usr/sbin/httpd -k start

apache    2868  0.0  0.6  25300  5444 ?        S    22:45   0:00 /usr/sbin/httpd -k start

apache    2869  0.0  0.6  25300  5444 ?        S    22:45   0:00 /usr/sbin/httpd -k start

apache    2870  0.0  0.7  25300  5556 ?        S    22:45   0:00 /usr/sbin/httpd -k start

apache    2871  0.0  0.6  25164  4796 ?        S    22:45   0:00 /usr/sbin/httpd -k start

apache    2872  0.0  0.6  25164  4796 ?        S    22:45   0:00 /usr/sbin/httpd -k start

apache    2873  0.0  0.6  25164  4796 ?        S    22:45   0:00 /usr/sbin/httpd -k start

apache    2874  0.0  0.6  25164  4796 ?        S    22:45   0:00 /usr/sbin/httpd -k start

root      3141  0.0  0.0   4244   676 pts/1    R+   22:48   0:00 grep httpd

 

 

下面访问一下apache默认页是否能打开。http://ip:80/index.html

又提示了错误:



 

难道是端口被占用了?修改apache的配置文件

/usr/local/apache/conf/httpd.conf  配置文件

[root@localhost conf] vi httpd.conf

找到下面一行:

Listen 80   把80改成其它端口,如8080 、8800 只要没被占用就行。

找到下面一行:

ServerName www.example.com:80   改成本机ip加端口号,如:192.168.0.105:80

 

  端口改来改去,一直都报那个错误。由于之前没有在linux下安装apache的经验,与是想找一下apache默认运行的哪个页面。于是,找到了,..../apache/htdocs/index.html 文件(受tomcat的误导)!其实不然,真正运行的是 /var/www/html 目录下的文件

You don't have permission to access /index.html on this server 

真正的错误在这句提示上。因为我方位的文件权限不足够。那给文件加个权限吧!

在/var/www/html 创建个文件index.html

[root@localhost html]# chmod 766 index.html

Ok!再来方位apache ,页面正常打开了!过程很纠结,结局很美好!

 

-----------小结--------------

需要安装的文件:

apr-1.4.6

apr-util-1.4.1.tar.bz2

pcre-8.30.zip

 

/usr/local/apache     apache的安装目录

/usr/local/apache/conf/httpd.conf    配置文件

/usr/local/apache/bin/ apachectl   stop/start    停止/启动程序

/var/www/html/    在这个文件夹下创建可以访问的页面

Apache安装问题锦集

 

问题1:缺少包gcc-c++导致安装包apr-util不通过

 

[root@getlnx05 kerry]# unzip pcre-8.33.zip

[root@getlnx05 kerry]# cd pcre-8.33

[root@getlnx05 pcre-8.33]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config





一般出现这个错误是因为没有安装包gcc-c++,可以通过如下命令检查,

[root@getlnx05 pcre-8.33]# yum list gcc-c++

Loaded plugins: product-id, security, subscription-manager

Updating Red Hat repositories.

Available Packages

gcc-c++.x86_64                                                               4.1.2-51.el5                                                                rhel-debuginfo

[root@getlnx05 pcre-8.33]# yum list gcc

Loaded plugins: product-id, security, subscription-manager

Updating Red Hat repositories.

Installed Packages

gcc.x86_64                                                                    4.1.2-51.el5                                                                    installed

[root@getlnx05 pcre-8.33]# rpm -q gcc

gcc-4.1.2-51.el5

[root@getlnx05 pcre-8.33]# rpm -q gcc-c++

 

问题2:checking for APR-util... configure: error: the --with-apr-util parameter is incorrect

[root@getlnx05 httpd-2.4.6]#  ./configure --prefix=/usr/local/apache  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

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

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... yes

  setting CC to "gcc"

  setting CPP to "gcc -E"

  setting CFLAGS to " -g -O2 -pthread"

  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"

  setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable Runtime Utility library...

configure:

checking for APR-util... configure: error: the --with-apr-util parameter is incorrect. It must specify an install prefix, a build directory, or an apu-config file.

[root@getlnx05 httpd-2.4.6]#

一般是由于APR-util没有安装成功,可以通过验证该目录是否为空来判断,因为你有时候执行了make,忘了执行make isntall命令有可能导致这个错误。

[root@getlnx05 apr]# cd /usr/local/apr-util

[root@getlnx05 apr-util]# ls

 

问题3:没有指定PCRE参数

[root@getlnx05 httpd-2.4.6]#  ./configure --prefix=/usr/local/apache  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

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

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... yes

  setting CC to "gcc"

  setting CPP to "gcc -E"

  setting CFLAGS to " -g -O2 -pthread"

  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"

  setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable Runtime Utility library...

configure:

checking for APR-util... yes

checking for gcc... gcc

checking whether the C compiler works... yes

checking for C compiler default output file name... a.out

checking for suffix of executables...

checking whether we are cross compiling... no

checking for suffix of object files... o

checking whether we are using the GNU C compiler... yes

checking whether gcc accepts -g... yes

checking for gcc option to accept ISO C89... none needed

checking how to run the C preprocessor... gcc -E

checking for gcc option to accept ISO C99... -std=gnu99

checking for pcre-config... false

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@getlnx05 httpd-2.4.6]#

 

问题4:安装前忘了先安装APR相关包

[root@getlnx05 httpd-2.4.6]#  ./configure --prefix=/usr/local/appache/

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

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

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... no

configure: error: APR not found.  Please read the documentation.

[root@getlnx05 httpd-2.4.6]#

 

问题5:启动服务时报错

[root@getlnx05 httpd-2.4.6]#  /usr/local/apache/bin/apachectl start

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using getlnx05.gfg1.esquel.com. Set the 'ServerName' directive globally to suppress this message

这个时候需要编辑httpd.conf配置文件,添加SeraverName的具体IP地址。如下所示

[root@getlnx05 conf]# cd /usr/local/apache/conf/

[root@getlnx05 conf]# ls

extra  httpd.conf  magic  mime.types  original

[root@getlnx05 conf]# vi httpd.conf

ServerAdmin you@example.com

#

# ServerName gives the name and port that the server uses to identify itself.

# This can often be determined automatically, but we recommend you specify

# it explicitly to prevent problems during startup.

#

# If your host doesn't have a registered DNS name, enter its IP address here.

#

#ServerName www.example.com:80

ServerName 192.168.9.122:80

#

# Deny access to the entirety of your server's filesystem. You must

# explicitly permit access to web content directories in other

# <Directory> blocks below.

#

"httpd.conf" 502L, 18179C written

[root@getlnx05 conf]# /usr/local/apache/bin/apachectl restart

httpd not running, trying to start

[root@getlnx05 conf]# /usr/local/apache/bin/apachectl start

httpd (pid 7797) already running

如果从其它电脑连接访问Apache时,输入url地址:http://192.168.9.122页面没有显示正常,而上面配置也OK,那么你必须关闭防火墙,有时候甚至需要重启电脑才能OK,重启Apache服务都无效。

[root@getlnx05 conf]# chkconfig iptables off

[root@getlnx05 conf]# chkconfig iptables off

[root@getlnx05 conf]# /usr/local/apache/bin/apachectl restart

[root@getlnx05 conf]# /usr/local/apache/bin/apachectl restart

[root@getlnx05 conf]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  httpd apche