模拟生产环境LAMP环境搭建实例


apache版本:httpd-2.2.20
mysql版本:mysql-5.1.58
PHP版本:php-5.3.6
其它要用到的相关软件:
freetype-2.4.6
jpegsrc.v6b
libpng-1.2.8-config
gd-2.0.35

PS:在安装之前最好把httpd、mysql、php等RPM包安装的软件卸载掉!!
yum remove php php-devel httpd httpd-devel mysql mysql-server

一、apache安装
1、安装:
[root@centos5 httpd-2.2.20]# ./configure --prefix=/usr/local/apache \
> enable-so --enable-rewrite --with-pmp=worker

[root@centos5 httpd-2.2.20]# make;make install

2、验证相关定义的功能模块是否被正确安装

静态模块查看:
[root@centos5 ~]# /usr/local/apache/bin/apachectl -l
Compiled in modules:
 core.c
 mod_authn_file.c
 mod_authn_default.c
 mod_authz_host.c
 mod_authz_groupfile.c
 mod_authz_user.c
 mod_authz_default.c
 mod_auth_basic.c
 mod_include.c
 mod_filter.c
 mod_log_config.c
 mod_env.c
 mod_setenvif.c
 mod_version.c
 worker.c
 http_core.c
 mod_mime.c
 mod_status.c
 mod_autoindex.c
 mod_asis.c
 mod_cgid.c
 mod_negotiation.c
 mod_dir.c
 mod_actions.c
 mod_userdir.c
 mod_alias.c
 mod_rewrite.c
 mod_so.c

查看动态模块:
[root@centos5 httpd-2.2.20]# ll /usr/local/apache/modules/
总计 12
-rw-r--r-- 1 root root 9063 09-07 05:09 httpd.exp

3、验证apache是否安装成功:

[root@centos5 httpd-2.2.20]# /usr/local/apache/bin/apachectl -t
Syntax OK


二、mysql安装

1、在安装之前先创建一个用户和组,专门用于启动mysql。

[root@centos5 mysql-5.1.58]# groupadd mysql
[root@centos5 mysql-5.1.58]# useradd -g mysql -M -s /sbin/nologin mysql

2、创建安装目录和数据库目录

[root@centos5 mysql-5.1.58]# mkdir -p /data/mysql
[root@centos5 mysql-5.1.58]# chown mysql:mysql /data/mysql -R


3、安装
[root@centos5 mysql-5.1.58]# ./configure --prefix=/usr/local/mysql \
--localstatedir=/data/mysql_db \
--with-extra-charsets=gbk,gb2312,utf8 \
--with-pthread --enable-thread-safe-client

PS: --enable-thread-safe-client
[root@centos5 mysql-5.1.58]# make && make install

4、编辑my.cnf配置文件,设置mysql数据存放目录,在[mysqld]标签外添加高亮处!!

先复制一份配置文件到安装目录下:
[root@centos5 mysql-5.1.58]# cd /usr/local/mysql
[root@centos5 mysql]# cp ./share/mysql/my-medium.cnf my.cnf
[root@centos5 mysql]# vi my.cnf
[mysqld]
port            = 3306
socket          = /tmp/mysql3306.sock
skip-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
read_buffer_size = 256K
sort_buffer_size = 64K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128k
basedir = /data/mysql/      
datadir = /data/mysql/data

5、初使化数据库,所用工具在安装目录中的 /usr/local/mysql/bin/mysql_install_db

[root@centos5 mysql]# /usr/local/mysql/bin/mysql_install_db --defaults-

file=./my.cnf --user=mysql

6.修改环境变量PATH路径,把mysql的命令路径加入到PATH变量中

[root@centos5 mysql]# vi /etc/profile

在适当位置添加 PATH=$PATH:/usr/local/mysql/bin(注意:= 即等号两边不能有任何空

格)
保存后执行:source /etc/profile 让配置立即生效!!

7、为了文便启动mysql服务,我们把它加到系统服务当中

[root@centos5 mysql]# cp /usr/local/mysql/share/mysql/mysql.server

/etc/rc.d/init.d/mysqld

把mysql 添加到服务项,并随开机启动
[root@centos5 mysql]# chkconfig --add mysqld
[root@centos5 mysql]# chkconfig mysqld on

这样我们就可以方便的用 service mysqld start 来启动mysqld服务了!!


三、PHP安装

在安装PHP之前,先把一些必备的组件安装好,要注意安装顺序!反正GD一般要最后安装。

1、freetype安装

[root@centos5 freetype-2.4.6]# ./configure --prefix=/usr/local/freetype
[root@centos5 freetype-2.4.6]# make;make install

2、jpeg安装

[root@centos5 jpeg-6b]# ./configure --prefix=/usr/local/jpeg
[root@centos5 jpeg-6b]# make
[root@centos5 jpeg-6b]# make install
....
....
/usr/bin/install: cannot create regular file `/usr/local/jpeg/bin/cjpeg.1': No

such file or directory
make: *** [install] Error 1
安装时候出现了错误,这个错误是比较明显的,根据上面的提示可以知道,找不到jpeg/bin

这个目录,既然没有,我们就自己创建:
[root@centos5 jpeg-6b]# make -p /usr/local/jpeg/bin

下面我们继续安装:
[root@centos5 jpeg-6b]# make install
....
....
/usr/bin/install: cannot create regular file `/usr/local/jpeg/man/man1/cjpeg.1':

No such file or directory
make: *** [install] Error 1

与上面一样:
[root@centos5 jpeg-6b]# make -p /usr/local/jpeg/man/man1

下面我们继续安装就OK了!!
[root@centos5 jpeg-6b]# make install

3、libpng安装

[root@centos5 libpng-1.2.8-config]# ./configure --prefix=/usr/local/libpng
[root@centos5 libpng-1.2.8-config]# make
[root@centos5 libpng-1.2.8-config]# make install

4、GD2安装,这个安装相对前面几个组件要复杂些

在安装前做头文件的软链接
[root@centos5 gd-2.0.35]# ln -sv /usr/local/libpng/include/pngconf.h

/usr/include/
[root@centos5 gd-2.0.35]# ln -sv /usr/local/libpng/include/png.h /usr/include/

[root@centos5 gd-2.0.35]# ln -sv /usr/local/libpng/include/pngconf.h

/usr/include/
创建指向“/usr/local/libpng/include/pngconf.h”的符号链接

“/usr/include/pngconf.h”
ln: 正在创建指向“/usr/local/libpng/include/pngconf.h”的符号链接

“/usr/include/pngconf.h”: 文件已存在
[root@centos5 gd-2.0.35]# ln -sv /usr/local/libpng/include/png.h /usr/include/
创建指向“/usr/local/libpng/include/png.h”的符号链接“/usr/include/png.h”
ln: 正在创建指向“/usr/local/libpng/include/png.h”的符号链接

“/usr/include/png.h”: 文件已存在

可以看到,我这个以经存在了!!!这是RPM安装时安装的,我们要删除掉再做链接!不然

make时会出错!
[root@centos5 gd-2.0.35]# rm -rf /usr/include/pngconf.h                        
[root@centos5 gd-2.0.35]# rm -rf /usr/include/png.h  

再做链接:
[root@centos5 gd-2.0.33]# ln -sv /usr/local/libpng/include/pngconf.h

/usr/include/
[root@centos5 gd-2.0.33]# ln -sv /usr/local/libpng/include/png.h /usr/include/


安装gd

[root@centos5 gd-2.0.35]# ./configure --prefix=/usr/local/gd2 \
--with-freetype=/usr/local/freetype \
--with-png=/usr/local/libpng \
--with-jpeg=/usr/local/jpeg

[root@centos5 gd-2.0.35]# make;make install


前期的工作基本上完成了。。。一切就绪,下面开始安装PHP!

1、安装

[root@centos5 php-5.3.6]# ./configure --prefix=/usr/local/php \
--with-gd=/usr/local/gd2 \
--with-apxs2=/usr/local/apache/bin/apxs \
--enable-mbregex --enable-bcmath \
--with-mysql=/usr/local/mysql \
--with-zlib-dir --enable-mbstring=all \
--with-pdo-mysql=/usr/local/mysql \
--with-freetype-dir=/usr/local/freetype \
--with-mysqli=/usr/local/mysql/bin/mysql_config


configure: error: GD build test failed. Please check the config.log for details.

[root@centos5 php-5.3.6]# make
[root@centos5 php-5.3.6]# make install


2、验证安装

在安装完PHP之后,会在apache安装目录的modules目录下生成数据库文件libphp5.so,同时

会在apache主配置文件httpd.conf下插入:Load Module php5_module modules/libphp5.so

[root@centos5 apache]# ll /usr/local/apache/modules/
总计 20096
-rw-r--r-- 1 root root     9063 09-07 05:09 httpd.exp
-rwxr-xr-x 1 root root 20538740 09-07 12:13 libphp5.so

3、apache与PHP的整合

在apache主配置文件httpd.conf中的适当位置插入以下语句(查找AddType):
AddType application/x-httpd-php .php

[root@centos5 wordpress]# vi /usr/local/apache/conf/httpd.conf
在如下位置:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php

4、验证

启动apache服务
[root@centos5 wordpress]# /usr/local/apache/bin/apachectl start
[root@centos5 wordpress]# vi /usr/local/apache/htdocs/index.php
输入以下内容:

<?
phpinfo();
?>

在浏览器地址栏中输入服务器的IP地址或域名进行测试!!



四、LAMP实例(wordpress/disscz)
略。。。。
可以参照:http://oldboy.blog.51cto.com/2561410/587414


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++