下载完安装包后,建议将安装包存放在统一的目录(如/usr/local )下,然后将其解压。以上面给出的资源为例:
Unzip Lamp_All_file.zip -d /usr/local/src //将文件解压到指定目录
cd /usr/local/src
ls *.tar.gz |xargs -n1 tar xzvf //解压该目录下所有的tar.gz 包。(有点占内存)
解压完成后,开始对源代码进行配置与安装。
Linux 下源代码的配置与安装大体都是使用 ./configure 、make 和 make install命令
在源码包的目录下,首先./configure 配置相应的路径,如:
./configure --prefix=/usr/local/lamp/libxml2
然后就运行make 命令 在运行make install 进行安装,make和make install 安装可以同时进行,如:
make && make install
顺序安装源码包:
libxml2-2.9.0
./configure --prefix=/usr/local/lamp/libxml2-2.9.0
make && make install
libmcrypt-2.5.8
./configure --prefix=/usr/local/lamp/libmcrypt-2.5.8
make && make install
zlib-1.2.7
./configure --prefix=/usr/local/lamp/zlib-1.2.7
make && make install
libpng-1.5.14
./configure --prefix=/usr/local/lamp/libpng-1.5.14
make && make install
jpegsrc.v8b(注意;jpeg 源码包安装的时候是不会自动生成目录的,所以需要在安装之前先创建相应的目录。同时需要将其设置成共享库和静态库,因为接下来gd安装的时候需要用到jpeg库,如果没有设置的话,最后检测的时候会检测不到jpeg库的)
mkdir /usr/local/lamp/jpeg
mkdir /usr/local/lamp/jpeg/bin
mkdir /usr/local/lamp/jpeg/lib
mkdir /usr/local/lamp/jpeg/include
mkdir /usr/local/lamp/jpeg/man
mkdir /usr/local/lamp/jpeg/man/man1
./configure --prefix=/usr/local/lamp/jpeg/ --enable-shared --enable-static
make && make install
freetype-2.4.10
./configure --prefix=/usr/local/lamp/freetype
make && make install
autoconf-2.69(autoconf 安装的时候,可能会提示找不到M4,如果出现这样的情况的话,需要下载M4 的源文件并安装)
./configure --prefix=/usr/local/lamp/autoconf
make && make install
gd-2.0.35(gd库在安装的时候,除了需要配置安装路径,还需要将前面安装jpeg库和freetype库的路径也给附上)
./configure --prefix=/usr/local/lamp/gd2 --with-jpeg=/usr/local/lamp/jpeg8/ --with-freetype=/usr/local/lamp/freetype/
make && make install
至此,Lamp的开发环境就搭建成功了
后期配置:
配置默认首页(在DirectoryIndex 中加入index.php):
vi /etc/httpd/httpd.conf
DirectoryIndex index.php index.Html index.html
以下是LZ 安装时曾经遇到过的错误以及解决方案:
1、安装php时出错:
In file included from /usr/local/src/php-5.4.6/ext/gd/gd.c:103:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c: 在函数‘_php_image_stream_putc’中:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:51: 错误:‘struct gdIOCtx’没有名为‘data’的成员
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c: 在函数‘_php_image_stream_putbuf’中:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:58: 错误:‘struct gdIOCtx’没有名为‘data’的成员
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c: 在函数‘_php_image_stream_ctxfree’中:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:67: 错误:‘struct gdIOCtx’没有名为‘data’的成员
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:68: 错误:‘struct gdIOCtx’没有名为‘data’的成员
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:69: 错误:‘struct gdIOCtx’没有名为‘data’的成员
In file included from /usr/local/src/php-5.4.6/ext/gd/gd.c:103:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c: 在函数‘_php_image_output_ctx’中:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:153: 错误:‘gdIOCtx’没有名为‘data’的成员
make: *** [ext/gd/gd.lo] 错误 1
这个是php5.4的一个bug,需要修改gd的一个文件
解决方法:
vi /usr/local/gd2/include/gd_io.h
typedef struct gdIOCtx
{
int (*getC) (struct gdIOCtx *);
int (*getBuf) (struct gdIOCtx *, void *, int);
void (*putC) (struct gdIOCtx *, int);
int (*putBuf) (struct gdIOCtx *, const void *, int);
int (*seek) (struct gdIOCtx *, const int);
long (*tell) (struct gdIOCtx *);
void (*gd_free) (struct gdIOCtx *);
void (*data);
}
gdIOCtx;
在该文件中加入红色字体的语句,在重新make即可
2、httpd 启动时错误
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs