当前位置:首页 > 嵌入式培训 > 嵌入式学习 > 讲师博文 > Linux 下搭建Apache 服务器

Linux 下搭建Apache 服务器 时间:2018-09-25      来源:未知

在开发过程中尤其实在开发web程序时,我们经常需要测试web程序是否运行·正常或者测试结果是否正确,因此我们需要有一个可以运行web程序的服务器。大家也都知道web服务器的种类很多,可以根据不同的需求来选择不同的web server。但是长用的莫过于Apache和Nginx了。对于这两个服务器我们都可以到对应的官方站点进行下载安装。

直接安装下载好的二进制包的确很方便和简单,但是有时候现成的安装包可能无法提供我们需要的一些特定的功能,那么怎么办呢?今天我们就分享一下在linux下如何通过源码来编译安装Apache和所需的模块。具体步骤,如下:

一、安装apache

1、安装apache

#tar -zxvf httpd-2.2.22.tar.gz

#cd httpd-2.2.22

#./configure --enable-moudle=so --prefix=/usr/local/apache

出现错误 apr not found 错误:

解决办法:

1.下载所需软件包:

wget //archive.apache.org/dist/apr/apr-1.4.5.tar.gz

wget //archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz

wget //jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip

a:解决apr not found问题>>>>>>

[root@xt test]# tar -zxf apr-1.4.5.tar.gz

[root@xt test]# cd apr-1.4.5

[root@xt apr-1.4.5]# ./configure --prefix=/usr/local/apr

[root@xt apr-1.4.5]# make && make install

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

[root@xt test]# tar -zxf apr-util-1.3.12.tar.gz

[root@xt test]# cd apr-util-1.3.12

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

[root@xt apr-util-1.3.12]# make && make install

c:解决pcre问题>>>>>>>>>

[root@xt test]#unzip -o pcre-8.10.zip

[root@xt test]#cd pcre-8.10

[root@xt pcre-8.10]#./configure --prefix=/usr/local/pcre

[root@xt pcre-8.10]#make && make install

2、#./configure --enable-moudle=so --prefix=/usr/local/apache --with-apr=/usr/local/apr \

--with-apr-util=/usr/local/apr-util \

--with-pcre=/usr/local/pcre

3、 make && make install

4、

添加:exportPATH添加:export PATH=/usr/local/apache/bin:$PATH

启动:httpd -k start

停止:httpd -k stop

重启:httpd -k restart

5、修改/usr/local/apache/conf/httpd.conf文件,

设置:ServerName localhost:80

二、安装php

1、解压配置

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs \

--with-mysql=/usr(如果是使用apt-get 安装的mysql) --with-mysqli=/usr/bin/mysql_config \

--with-pear --with-libxml-dir --disable-fileinfo

出现错误,提示缺少 libxm12

apt-get install -y libxml2 libxml2-dev

2、make

make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

编译PHP5.5 make 时出现错误

make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

解决办法

这是由于内存小于1G所导致.

在./configure加上选项:

--disable-fileinfo

Disable fileinfo support 禁用 fileinfo

3、make install

4、 将php源码包中的php.ini-development 复制到/usr/local/lib/中

cp php-5.6.13/php.ini-development /usr/local/lib/php.ini

5、修改Apache配置文件(/usr/local/apache/conf/httpd.conf)以支持对PHP的解析。

如果httpd.conf中没有下列语句,就将它们分别添加到LoadModule和AddType项的后面。

LoadModule php5_module modules/libphp5.so

AddType application/x-httpd-php .php

在DirectoryIndex index.html index.html.var一行后加入index.php,即改为:

DirectoryIndex index.html index.html.var index.php

重启Apache服务器:

#/usr/local/apache2/bin/apachectl restart

6、测试

在Apache服务器的文件根目录(/usr/local/apache2/htdocs/)下新建一个PHP文件test.php,并输入以下内容:

phpinfo();

?>

在浏览器中输入//localhost/test.php。

上一篇:Linux内核中的数据结构的一点认识

下一篇:Java中内部类的几种表现形式

热点文章推荐
华清学员就业榜单
高薪学员经验分享
热点新闻推荐
前台专线:010-82525158 企业培训洽谈专线:010-82525379 院校合作洽谈专线:010-82525379 Copyright © 2004-2022 北京华清远见科技集团有限公司 版权所有 ,京ICP备16055225号-5京公海网安备11010802025203号

回到顶部