Ubuntu下安装Apache 和 php

闲来无事,配置LAMP练练手。本想着手到擒来,不想还颇费了一番功夫。特此记录。

Ubuntu的版本是10.04.4:

1 ~$ cat /etc/issue
2 Ubuntu 10.04.4 LTS \n \l

1、安装Apache:

从官网下载了Apache的最新版本,这里有 .tar.gz和 .tar.bz2 两种格式的。如果电脑上面没有安装bzip2的话,可以选择第一种。我使用的是 .tar.gz 这种格式的。

1.1 解压缩Apache压缩包

解压缩的时候,最好把文件放在临时的地方,比如: ~/tmp 目录

1 gzip -d httpd-2_x_NN.tar.gz
2 tar -xf httpd-2_x_NN.tar

1.2 安装Apache

在指导手册上面有比较详细的安装指导,http://httpd.apache.org/docs/2.4/install.html

只是每台电脑都有不相同的地方。不知道会少些什么。我在安装的时候颇费了一些周折,到google上面搜索的时候碰到一位仁兄,安装的过程中出现了15个不同的错误。。。给我不小的鼓励。

简要安装的步骤是这样的。PREFIX是指安装的指定目录,手动安装的时候,我们一般会选择 /usr/local/apache2 作为主要目录。

1 $ cd httpd-NN
2 $ ./configure --prefix=PREFIX
3 $ make
4 $ make install
5 $ vi PREFIX/conf/httpd.conf
6 $ PREFIX/bin/apachectl -k start

如果安装软件都像写的这么简单就好了。不过没有关系,梁任公曾说过这么一句:要是饭都端到嘴边,还有什么意思?

错误1:在 ./configure 步骤时,没有发现APR:

1 ./configre --prefix=/usr/local/apache2 --with-apr=/usr/local/APR
2 checking for APR... no
3 configure: error: APR could not be located. Please use the --with-apr option.

APR是什么呢?官网上面有一个简单的介绍:

The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations. The primary goal is to provide an API to which software developers may code and be assured of predictable if not identical behaviour regardless of the platform on which their software is built, relieving them of the need to code special-case conditions to work around or take advantage of platform-specific deficiencies or features.

我想能看完的没几个人,能耐心看完140个字的人都不多了。简单来说,这是Apache安装所要依赖的lib库。APR(Apache portable Run-time libraries,Apache可移植运行库),目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。

从官网上面下载了APR http://apr.apache.org/ 编译的时候也是和和上面相同的步骤:

$ cd /apr-1.4.6
$ ./configure --prefix=/usr/local/apr
$ make
$ make install

错误2:在 ./configure 步骤时,没有发现APR-Utils:

1 $ ./configre --prefix=/usr/local/apache2 --with-apr=/usr/local/APR
2 $ checking for APR-util... no
3 $ configure: error: APR could not be located. Please use the --with-apr option.

从官网上面下载APR-Util,地址也是一样的 http://apr.apache.org/ 编译安装

1 $ cd /apr-util-1.4.1
2 $ ./configure --prefix=/usr/local/apr-util
3 $ make
4 $ make install

其实这部分我没有太仔细的看APR和APR-Util的关系,既然都需要,为什么没有bind在一起而是要分开安装呢?

错误3:在./configure 步骤时,没有发现PCRE:

1 $ ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/APR --with-apr-util=/usr/local/apache2
2
$ configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

从官网上面下载PCRE,地址在另外一个地方 https://sourceforge.net/projects/pcre/files/pcre/ 编译安装

1 $ cd /pcre-8.30
2 $ ./configure --prefix=/usr/local/pcre
3 $ make
4 $ make install

继续安装Apache

1 $ ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/APR --with-apr-util=/usr/local/APR-U --with-pcre=/usr/local/pcre
2
3 config.status: executing default commands

继续进行Make和Make Install步骤。这两步没出什么问题,就不赘述了。至此Apache安装完成。

2、安装php5

有了上面的基础操作,就不再说 .tar.gz包是如何处理的了。简单说一下在安装php的时候遇到的错误吧

错误1:

1 configure: error: Cannot find MySQL header files under yes.
2
3 Note that the MySQL client library is not bundled anymore!

解决办法:

1 sudo apt-get install libmysql++-dev

 

错误2:

1 configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/

解决办法:

1 sudo apt-get install libcurl4-gnutls-dev

之后的安装就比较顺利了。我安装时遇到的错误也不算多。在这里有一篇,这位兄弟总结了各种错误。对比起成功的经验,我相信失败的经验和解决办法肯定会对大家更有好处:

http://fengyin.name/2012/02/06/ubuntu11-10-%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85php5-3-8.html

3、安装Mysql:

本是打算全部手动安装的,结果看到mysql的安装包有170多MB,时间也比较晚了,就退缩了。直接就sudo apt-get install了一下。


今天先到这里,明天继续说使用的问题吧。学习不是一朝一夕的事情,慢慢来,比较快





 



posted @ 2012-03-14 08:58  提枪四顾  阅读(877)  评论(0编辑  收藏  举报