首页 > 系统 > Linux > 正文

Linux——安装apache

2024-06-28 15:59:27
字体:
来源:转载
供稿:网友

1. 检查机器是否已经安装了apache(系统自带)Centos6.5

rpm -qa |grep httpd

rpm -qa |grep apache

并检查/etc/httpd/httpd.conf 配置文件是否存在

如果存在则先卸载,或者关闭centos自带的web服务,执行chkconfig httpd off

并修改httpd的服务端口80为其他端口

2. 在官网下载对应的release

http://httpd.apache.org/

选择现在当前最新版本: httpd-2.4.25.tar.gz

3.将安装包拷贝到VM上并解压

tar -zxvf httpd-2.4.25.tar.gz 

4. 正常安装(另有安装一些相关插件会在后面补充)

进入httpd-2.4.25文件夹(cd httpd-2.4.25)

执行命令 

./configure --PRefix=/usr/local/apache2
然后报错:(找不到apr)
checking for chosen layout... Apachechecking for working mkdir -p... yeschecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking target system type... x86_64-unknown-linux-gnuconfigure:configure: Configuring Apache Portable Runtime library...configure:checking for APR... noconfigure: error: APR not found.  Please read the documentation.

5. 处理apr问题

http://apr.apache.org/download.cgi 下载对应的安装包

以 apr-1.5.2.tar.gz 为例

和上段一致拷贝到文件夹下解压

tar -zxvf apr-1.5.2.tar.gz 

cd apr-1.5.2./configure --prefix=/usr/local/aprmakemake install成功后会出现很多文件安装   done 的字样注意如果没有安装权限要sudo make/sudo make install6. 处理apr-util问题

继续执行命令[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache2

出现以下报错

checking for chosen layout... Apachechecking for working mkdir -p... yeschecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking target system type... x86_64-unknown-linux-gnuconfigure: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... noconfigure: error: APR-util not found.  Please read the documentation.

继续安装apr-util依赖包 (参照apr下载地址)

以 apr-util-1.5.4.tar.gz为例

命令和安装apr类似

tar -zxf apr-util-1.5.4.tar.gz

cd apr-util-1.5.4

./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config

make

make install

7.继续编译安装apache

如果继续按照上文

./configure --prefix=/usr/local/apache2 可能仍然报错没安装apr-util
可是老娘刚才已经装了撒!
执行
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
即可
编译的时候没有将apr-util路径加上他不认得罢了
继续,[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
checking for chosen layout... Apachechecking for working mkdir -p... yeschecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking target system type... x86_64-unknown-linux-gnuconfigure: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... yeschecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables...checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking how to run the C preprocessor... gcc -Echecking for gcc option to accept ISO C99... -std=gnu99checking for pcre-config... falseconfigure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

在 http://pcre.org/ 安装pcre包

以pcre-8.40.tar.gz为例

tar -zxf pcre-8.40.tar.gz

cd pcre-8.40

./configure --prefix=/usr/local/pcremake

make install

8.继续编译安装apache

cd httpd-2.4.25

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre

make

make install

9.启动apache

/usr/local/apache2/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

vim /usr/local/apache2/conf/httpd.conf

添加

#ServerName www.examda.com:80 

改为

ServerName localhost:80即可

保存退出

重新启动

/usr/local/apache2/bin/apachectl restart

还是不行(此时能ping通)

最终发现,将iptables(防火墙)关闭即可

service iptables stop

在浏览器输入VM的IP地址访问,It works!

以上。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表