首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

linux 64位 redhat5.3上安装apache2.2+mysql5.5+php5+GD库

2012-09-29 
linux 64位 redhat5.3下安装apache2.2+mysql5.5+php5+GD库本身php就不熟,还要在linux下安装php的运行环境,

linux 64位 redhat5.3下安装apache2.2+mysql5.5+php5+GD库
    本身php就不熟,还要在linux下安装php的运行环境,这个过程是在太痛苦了,幸亏linux有镜像恢复功能,在试验安装过程中遇到各种错误,恢复了不下三次。
    最先选择的是lnmp一键包(http://lnmp.org/),可是总是遇见各种错误,试了三四次之后放弃了,还是按部就班一步一步来吧。

服务器操作系统:linux 64位 版本redhat5.3
需要准备的安装包:

MySQL-server-5.5.15-1.rhel5.x86_64.rpm
MySQL-client-5.5.15-1.rhel5.x86_64.rpm
MySQL-devel-5.5.15-1.rhel5.x86_64.rpm

xpm-3.4k-2.i386.rpm
zlib-1.2.3.tar.gz
libxml2-2.7.8.tar.gz
libpng-1.5.4.tar.gz
jpegsrc.v6b.tar.gz
freetype-2.1.9.tar.gz
gettext-0.18.tar.gz
gd-devel-2.0.33-9.4.el5_4.2.i386.rpm
gd-2.0.35.tar.gz

httpd-2.2.19.tar.gz

php-5.2.17.tar.gz


一、安装mysql
下载:http://www.mysql.com/downloads/

安装server:rpm -ivh MySQL-server-5.5.15-1.rhel5.x86_64.rpm
安装client:rpm -ivh MySQL-client-5.5.15-1.rhel5.x86_64.rpm
rpm -ivh MySQL-devel-5.5.15-1.rhel5.x86_64.rpm(如果不安装,后面安装php时有可能出错)

安装后有提示不要忘记修改密码:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h bogon password 'new-password'

启动:
service mysql start
service mysql stop
service mysql restart

二、安装GD库
(http://www.alixixi.com/ePrint.asp?from=dev&id=11559)
1、安装XPM支持

#rpm -ivh xpm-3.4k-2.i386.rpm

2、安装libxml2 (记得PHP5只支持libxml2-2.5.10以上版本)
#tar zxvf libxml2-2.7.8.tar.gz
#cd libxml2-2.7.8
#./configure
#make
#make install

3、安装zlib
# tar xvzf zlib-1.2.3.tar.gz
# cd zlib-1.2.3
# ./configure
64位系统,需要在configure之后修改Makefile在CFLAGS="-O3 -fPIC" (添加红色部分)(http://cxd263.blog.163.com/blog/static/34186249200922005443141/)
# make && make install

4、安装freetype
# tar xvzf freetype-2.1.9.tar.gz
# cd freetype-2.1.9
# ./configure
# make && make install

5、安装libpng
# tar xvzf libpng-1.5.4.tar.gz
# cd libpng-1.5.4
# ./configure
64位系统,需要在configure之后修改Makefile在CFLAGS="-O3 -fPIC" (添加红色部分)(http://cxd263.blog.163.com/blog/static/34186249200922005443141/)
#make libdir=/usr/lib64
#make libdir=/usr/lib64 install

6、安装jpegsrc
# tar xvzf jpegsrc.v6b.tar.gz
# cd jpegsrc.v6b
# ./configure  –enable-shared –enable-static
64位系统,需要在configure之后修改Makefile在CFLAGS="-O3 -fPIC" (添加红色部分)(http://cxd263.blog.163.com/blog/static/34186249200922005443141/
#make libdir=/usr/lib64
#make libdir=/usr/lib64 install

如果发生以下错误:
引用
# make && make install
./libtool --mode=compile gcc -O2  -I. -c ./jcapimin.c
make: ./libtool:命令未找到
make: *** [jcapimin.lo] 错误 127
./libtool --mode=compile gcc -O2  -I. -c ./cjpeg.c
make: ./libtool:命令未找到make: *** [cjpeg.lo] 错误 127
解决办法:
首先看有没有安装libtool 及 libtool-ltdl-devel
rpm   -qa | grep   libtool

然后进入jpeg-6b的源码目录,然后执行以下步骤,切记!COPY到当前目录注意后面的点(.)
cp   /usr/share/libtool/config.sub  .
cp   /usr/share/libtool/config.guess  .
也就是把 libtool里面的两个配置文件拿来覆盖掉jpeg-6b目录下的对应文件
make clean (切记。make clean)再重新configure




还可能出现错误:
引用
/usr/bin/install: cannot create regular file `/usr/local/man/man1/cjpeg.1': No such file or directory
make: *** [install] Error 1
解决办法:
mkdir /usr/local/man
mkdir /usr/loca/man/man1    创建完了再来
make libdir=/usr/lib64 install   (没报错就成功)



7、安装gettext(有的直接就有,可以先安装GD库,报错再返回来安装)

# tar xvzf gettext-0.18.tar.gz
# cd gettext-0.18
# ./configure
# make && make install

8、安装GD
# tar xvzf gd-2.0.35.tar.gz
# cd gd-2.0.35
# ./configure --with-png --with-freetype --with-jpeg
# make
# make install
configure...这一步可能的错误:configure.ac:64: error: possibly undefined macro: AM_ICONV,这个就必须安装gettext


三、安装apache
#tar zxvf httpd-2.2.19.tar.gz
#cd httpd-2.2.19
#./configure --prefix=/usr/local/apache2 --enable-module=so
#make
#make install

四、安装php

#mkdir /usr/local/php
#tar zxvf php-5.2.17.tar.gz
#cd php-5.2.17
#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-jpeg-dir=/usr/local  --with-gd=/usr/local  --with-zlib-dir=/usr/local --with-mysql=/var/lib/mysql

编译中可能出现错误:

引用
1、configure之后提示找不到libjpeg(a|so)
# rpm -qa | grep jpeg
libjpeg-6b-37
# updatedb
# locate libjpeg.so
/usr/lib64/libjpeg.so.62
/usr/lib64/libjpeg.so.62.0.0
/usr/lib64/libjpeg.so
/usr/lib/libjpeg.so
# locate libjpeg.a
/usr/lib64/libjpeg.a
/data0/software/jpeg-6b/libjpeg.a

(也可以find / -name “libjpeg* -print”查找)
通过上面的搜索其实就知道一些原因了,configure一般的搜索编译路径为/usr/lib/下,因为php默认就在/usr/lib/下找相关库文件,而x64机器上是在:/usr/lib64.这时你就可以直接把需要的库文件从/usr/lib64中拷贝到/usr/lib/中去就可以了.
那么记得要在configure前执行如下的命令:
cp -frp /usr/lib64/libjpeg.* /usr/lib/

(同样png一样处理)


2、configure: error: Cannot find libmysqlclient under /usr.
libmysqlclient 明明是安装在/usr/lib64/mysql下面的,后来在网上查了一下,貌似configure脚本的这个--with-mysql参数在RHEL5.3下有问题。
所以,索性搞两个软链接,问题解决
ln -s /usr/lib64/mysql/libmysqlclient.a /usr/lib/libmysqlclient.a
ln -s /usr/lib64/mysql/libmysqlclient_r..a /usr/lib/libmysqlclient_r.a
(http://www.cnblogs.com/welkinwalker/archive/2011/06/27/2091408.html)

3、找不到mysql头文件:Cannot find MySQL header files under /var/lib/mysql
安装mysql-devel
rpm -ivh MySQL-devel-5.5.15-1.rhel5.x86_64.rpm


#make
#make test
#make install

安装完成后有如下提示:根据提示来就好

引用
Installing PHP SAPI module:       apache2handler
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' libphp5.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool --mode=install cp libphp5.la /usr/local/apache2/modules/
cp .libs/libphp5.so /usr/local/apache2/modules/libphp5.so
cp .libs/libphp5.lai /usr/local/apache2/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /usr/local/php-5.2.17/libs'
chmod 755 /usr/local/apache2/modules/libphp5.so
[activating module `php5' in /usr/local/apache2/conf/httpd.conf]
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/man/man1/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:          /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages:             /usr/local/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment:      /usr/local/php/lib/php/
              [PEAR] Archive_Tar    - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.2.3
[PEAR] Structures_Graph- installed: 1.0.3
[PEAR] XML_Util       - installed: 1.2.1
[PEAR] PEAR           - installed: 1.9.1
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
Installing PDO headers:          /usr/local/php/include/php/ext/pdo/


五、配置apache及php

1、复制PHP.INI文件到正确位置
在PHP目录下运行
#cp php.ini-dist /usr/local/php/lib/php.ini

2、编辑apache配置文件httpd.conf
#vi /usr/local/apache2/conf/httpd.conf

1)一般都在#AddType application/x-tar .tgz下加一行
#LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php

如果你搜索其它地方没有以下这行LoadModule php5_module modules/libphp5.so,把上面的#号去掉

2)DirectoryIndex index.html index.html.var 在后面加 index.php 让它把index.php做为默认页

3)找到ServerName ,改为ServerName 192.168.1.111:80

4)DocumentRoot "/home/wwwroot",/home/wwwroot是要访问的网页的存放路径

5)<Directory "/home/wwwroot">同上

6)AddDefaultCharset utf-8,防止出现乱码

3、修改 httpd.conf 、php.ini、my.cnf,解决php的乱码问题
1)修改php.ini
default_charset = &quot;UTF-8&quot;

[mbstring]
; language for internal character representation.

mbstring.language = utf-8
; internal/script encoding.
; Some encoding cannot work as internal encoding.
; (e.g. SJIS, BIG5, ISO-2022-*)

mbstring.internal_encoding = utf-8
; http input encoding.

mbstring.http_input = auto
; http output encoding. mb_output_handler must be
; registered as output buffer to function
mbstring.http_output = utf-8

; enable automatic encoding translation according to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
;       portable libs/applications.
mbstring.encoding_translation = On

; automatic encoding detection order.
; auto means
mbstring.detect_order = auto

; substitute_character used when character cannot be converted
; one from another
mbstring.substitute_character = utf-8;

; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
mbstring.func_overload = 1

2)修改my.cnf
如果通过find找不到my.cnf,就从安装的mysql包中copy一份my-huge.cnf,例如:
#find / -name “my-huge.cnf” –print
# cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
然后修改my.cnf文件
在[ mysqld ] 下增加一行
character_set_server=utf8
重启mysql

3)修改httpd.conf
AddDefaultCharset utf-8

4、重启apache并测试
# /usr/local/apache2/bin/apachectl start

如果没有出错,写一个测试页放到你网页目录下
#vi /home/wwwroot/index.php
phpinfo();


热点排行