ubuntu下使用源码安装apache 服务器

来源:互联网 发布:进化论不能 知乎 编辑:程序博客网 时间:2024/06/08 08:31

1、下载

http://httpd.apache.org/download.cgi
我下载的是 httpd-2.4.2.tar.bz2

2、Ubuntu apache解压

将下载的文件放在主目录下然后解压

tar zxvf httpd-2.2.11.tar.gz 

解压后在主目录下得到一个名为httpd-2.4.2的文件

3、建立目标文件夹

mkdir /usr/local/apache

也就是说等下安装的Ubuntu apache要安装到这个文件夹里面

4、Ubuntu apache配置

回到原来解压之后产生的文件夹即 

cd  httpd-2.4.2./configure --prefix=/usr/local/apache --enable-module=shared

要加上后面的参数,否则无法使用php

这里会报错。

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

主要是说没有安装APR包的原因。

4.1于是下载APR包。网址为 http://apr.apache.org/download.cgi
我下载的是apr-1.4.6.tar.gz放在主目录下然后解压 

tar -zxvf apr-1.4.6.tar.gz 

在主目录下得到一个名为apr-1.4.6的文件

cd apr-1.4.6    sudo ./configuresudo  makesudo make install

安装完apr包之后 继续回到第4步安装 cd httpd-2.4.2 然后 

./configure --prefix=/usr/local/apache --enable-module=shared

发现又报错 

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

主要是说没有安装APR-util包的原因。
4.2 于是下载 APR-util包 网址为 http://apr.apache.org/download.cgi
我下载的是apr-util-1.4.1.tar.gz 放在主目录下然后解压 

tar -zxvf apr-1.4.2.tar.gz 

在主目录下得到一个名为apr-util-1.4.1的文件

cd   apr-1.4.6    sudo ./configuresudo  makesudo make install

./configure仍提示APR-util not found,增加–with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util参数输入

./configure --prefix=/usr/local/apache --enable-module=shared --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

出现

configure: error: pcre-config for libpcre not found. PCREis required and available from http://pcre.org

这是因为没有安装pcre的原因。

4.3 于是下载pcre 网址为ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 我下载的是 pcre-8.20.zip放在主目录下然后 cd pcre-8.10

sudo ./configure --prefix=/usr/local/pcre  sudo  make  sudo make install

安装过程中会提示没有安装 libtool 可以利用 sudo apt-get install libtool 安装。然后又会有

libtool: ignoring unknown tag CXX
libtool: unrecognized option `-DHAVE_CONFIG_H’
Try `libtool –help’ for more information.
make1: * [pcrecpp.lo] Error 1

这个错误,基本可以断定是缺少系统包造成的 这个错误是缺少安装gcc-c++,只需sudo apt-get install g++ ,重新configure,make && make install即可完成pcre的装。

然后继续安装第4步刚开始的部分 ,

cd  httpd-2.4.2 

然后

./configure --prefix=/usr/local/apache --enable-module=shared  --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre

然后

    sudo make    sudo make install 

完成 apache服务器的安装。

5、启动,重启和停止

/usr/local/apache/bin/apachectl -k start     (不加参数k也行) /usr/local/apache/bin/apachectl -k restart/usr/local/apache/bin/apachectl -k stop

启动过程中会提示程序“apachectl” 尚未安装。 您可以使用以下命令安装:

sudo apt-get install apache2.2-common

然后在终端输入

sudo apt-get install apache2.2-common

完成后就可以启动了。启动的时候要用sudo 否则会报 (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80no listenin sockets available错误 。还有一个解决办法是 Edit the config file to change the port Apache uses to a number greater than 1024.

简单启动apache命令。

复制Apache启动文件到usr/sbin里面 前面为你安装的apache的目录。

cp /usr/local/apache/bin/apachectl   /usr/sbin/

启动Apache时就可以简单的输入,而不用输入很长一段了。

sudo apachectl start 

就可以启动了

设置Apache开机自启动

vi /etc/rc.d/rc.local

增加一行 /sbin/apachectl start

6、配置文件

gedit /usr/local/apache/conf/httpd.conf

修改以下配置(当然这些修改是最基本的修改,如果要更高级的,参照其他Ubuntu apache配置手册)

6.1、
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在后面添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

6.2、
找到:
DirectoryIndex index.html
在后面添加: index.php

6.3、
找到:
#ServerName www.example.com:80
修改为:
ServerName 127.0.0.1:80或者ServerName localhost:80
记得要去掉前面的“#”
否则会出现以下错误提示:

httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

安装 PHP

1.下载PHP http://php.net/downloads.php 我下载的是 php-5.3.14.tar.bz2
放在主目录下,然后解压。

tar  -zjvf  php-5.3.14.tar.bz2

解压后在主目录下得到一个 php-5.3.14文件。

cd   php-5.3.14sudo ./configure --prefix=/usr/local/php --with-mysql=/usr/share/mysql --with-apxs2=/usr/local/apache/bin/apxs

直接这样执行后,将会看到这样一个错误

configure: error: xml2-config not found. Please check your libxml2 installation.

sudo apt-get install libxml2(按2次Tab键)会有 libxml2 libxml2-dev libxml2-headers libxml2-utils

安装 libxml2-dev

sudo apt-get install libxml2-dev  

然后继续安装php .configure…

然后会报一个错 Note that the MySQL client library is not bundled anymore!

这是由于安装mysql时没有安装mysql头文件,或者是路径指定不正确,php找不到mysql的头文件引起的错误提示。

解决方法。
1. 查看你的系统有没有安装mysql header

find / -name mysql.h

如果有。请指定–with-mysql=/跟你的正常路径。

如果没有。请看下一步。

2.redhat安装

rpm -ivh MySQL-devel-4.1.12-1.i386.rpm

3.debian安装

apt-get install libmysqlclient15-dev

我用的是ubuntu所以用的这条命令

4.最后一步php的配置选项添加–with-mysql=/usr即可!(这一步我没试,.configure 时还是原来的配置)然后继续

sudo ./configure --prefix=/usr/local/php --with-mysql=/usr/share/mysql --with-apxs2=/usr/local/apache/bin/apxs

然后

sudo makesudo make  install

完成安装。

完成安装后重启apache

sudo /usr/local/apache/bin/apachectl -k stop  sudo /usr/local/apache/bin/apachectl -k  start

2.测试一下是否可用。

编写一个php文件。

sudo gedit /usr/local/apache/htdocs/index.php

在里面填上

<?php  phpinfo();?>

然后在浏览器输入 。http://localhost/index.php 看到php相关信息即成功安装了。

0 0
原创粉丝点击