RedHat 5上安装APACHE/MYSQL/PHP/GD库
本文测试环境Red Hat Enterprise 5.4,均为源码编译安装,以下下载安装包注意“保质期”,随时有可能连不上,也可能因为版本太老被转移地址,具体可到对应网站上查看最新地址。 以下安装过程少则一个小时,多则三五天都有可能,所以遇到问题不必着急。为保证在安装、编译过程系统干净性(亦有网友称天缘为强迫症的),下文操作一律在/tmp临时目录下进行,使用cd或cd..一定要对应,否则连续出错几次,自己都不清楚包被DOWN到哪里了。
一、准备编译环境
编译安装包之前,请确认您的gcc工具及版本情况:
gcc -v
至少应该包含gcc gcc/c++,libtool,autoconfi,automake等几个常用的。其中libtool是编译gd库和freetype时需要,版本太低也可能有问题。
安装编译环境命令如下:
# yum install gcc gcc-c++ glibc glibc-devel gd gd-devel zlib zlib-devel libtool-ltdl-devel flex autoconf automake
该命令对REDHAT没注册的用户而言,无法在线安装,只能去下载包一个个源码编译安装。也可以直接找RPM、DEB包安装。本文从略,注意安装或更新编译环境后,记得重启机子一次。
如果下文安装GD、FREETYPE时总是报错,请安装或更新libtool,编译安装Libtool,更新这个,机子需要重启一下,否则在安装GD时,总是报告freetype错误。
# cd /tmp # wget ftp://ftp.gnu.org/gnu/libtool/libtool-1.5.26.tar.gz # tar zxvf libtool-1.5.26.tar.gz # cd libtool-1.5.26 # ./configure # make # make install
二、安装apache
# cd /tmp # wget http://www.apache.org/dist/httpd/httpd-2.2.22.tar.gz # tar zxvf httpd-2.2.22.tar.gz # cd httpd-2.2.22 # ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite # make && make install
如果需要为APACHE开启SSL,还需增加--enable-ssl --with-ssl=/usr/local/openssl配置选项,所以openssl也需先安装,请参考稍后文章。
启动apache:
# /usr/local/apache2/bin/apachectl start
设APACHE为服务:
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
修改刚拷贝过去的httpd:
在#!/bin/sh一行下,增加:
# chkconfig: 2345 10 90
# description: Activates/Deactivates Apache Web Server
然后保存退出。使用chkconfig --add httpd即可设置为服务,开机启动。但是毕竟是apachectl,启动停止时均没有提示。
APACHE基本设置:
Apache安装完后,配置文件httpd.conf需添加对php解析支持,路径/usr/local/apache2/conf/httpd.conf。
添加:AddType application/x-httpd-php .php
修改:DirectoryIndex index.html index.php
三、安装mysql数据库
1、安装ncurse:
ncurse介绍,安装方法如下:
# cd /tmp # wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz # tar zxvf ncurses-5.6.tar.gz # cd ncurses-5.6 # ./configure # make && make install
要编译最新的MYSQL还需要使用CMAKE和BISON(BISON介绍),如果本机有则不必安装。
2、安装cmake:
# cd /tmp # wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz # tar zxvf cmake-2.8.7.tar.gz # cd cmake-2.8.7 # ./bootstrap # gmake # gmake install
cmake命令文件安装到了/usr/local/bin目录下
3、安装Bison:
# cd /tmp # wget http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz # tar zxvf bison-2.5.tar.gz # cd bison-2.5 # ./configure # make && make install
4、安装MYSQL:
# cd /tmp # wget http://mirror.trouble-free.net/mysql_mirror/Downloads/MySQL-5.5/mysql-5.5.22.tar.gz # tar zxvf mysql-5.5.22.tar.gz # cd mysql-5.5.22 # cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql # make && make install
cmake几个参数介绍:
- -DCMAKE_INSTALL_PREFIX=/data/mysql ->mysql的安装路径
- -DDEFAULT_CHARSET=utf8 ->默认字符集
- -DMYSQL_TCP_PORT=3306 ->监听端口
- -DMYSQL_UNIX_ADDR=/tmp/mysql.sock ->数据库unix socket
- -DWITH_DEBUG=0 ->关闭debug模式
- -DWITH_INNOBASE_STORAGE_ENGINE=1 ->打开innodb引擎
添加群组:
- # groupadd mysql
- # useradd -g mysql mysql
修改权限及归属:
- # chmod +w /usr/local/mysql
- # chown -R mysql:mysql /usr/local/mysql
增加链接:
- # ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16
准备配置文件:
- # cd /usr/local/mysql/support-files/
- # cp my-large.cnf /etc/my.cnf (有my-large.cnf和my-huge.cnf可供选择,随内存大小定)
- # cp mysql.server /etc/init.d/mysqld
MYSQL数据库初始化:
如需修改my.cnf,可以访问/etc/my.cnf,MYSQL初始化(特别注意参数中的几个路径与cmake配置,以及下文修改启动文件中路径需要统一):
- /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
设置开机启动:
- chmod +x /etc/init.d/mysqld
- vi /etc/init.d/mysqld (编辑此文件,查找并修改以下变量内容:)
- basedir=/usr/local/mysql
- datadir=/usr/local/mysql/data
- chkconfig --add mysqld
- chkconfig --level 345 mysqld on
启动 mysql:
- service mysqld start
测试进入:
- # /usr/local/mysql/bin/mysqladmin -u root password
- # /usr/local/mysql/bin/mysql -u root -p
修改root密码
- # /usr/local/mysql/bin/mysqladmin -u root password '111111'
四、安装GD库
1、编译安装libxml
# cd /tmp # wget http://xmlsoft.org/sources/libxml2-2.7.8.tar.gz # tar zxvf libxml2-2.7.8.tar.gz # cd libxml2-2.7.8 # ./configure --prefix=/usr/local/libxml2/ # make && make install
2、编译安装zlib
下面安装libpng前要安装zlib,参考:http://fruithardcandy.iteye.com/blog/1460647。
# cd /tmp # wget http://www.zlib.net/zlib-1.2.3.tar.gz # tar zxvf zlib-1.2.3.tar.gz # # cd zlib/1.2.3/ # ./configure --prefix=/usr/local/zlib2/ 64位要改: #vi Makefile 找到 CFLAGS=-O3 -DUSE_MMAP 在后面加入-fPIC,即变成CFLAGS=-O3 -DUSE_MMAP -fPIC # make && make install
3、编译安装jpeg
# cd /tmp
# wget http://quirkysoft.googlecode.com/files/jpegsrc.v6b.tar.gz
# mkdir -pv /usr/local/jpeg6{,bin,lib,include,man/man1,man1}
# tar zxvf jpegsrc.v6b.tar.gz
# cd jpeg-6b
64位系统要执行如下两句:
# cp /usr/local/share/libtool/config.sub ./
# cp /usr/local/share/libtool/config.guess ./
32位系统用:
# ./configure --prefix=/usr/local/jpeg6
64位系统用:
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make
# make install-lib
# make install
4、编译安装libpng
# cd /tmp # wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.4.11.tar.gz # tar zxvf libpng-1.4.11.tar.gz # cd libpng-1.4.11 下面这句,天缘测试不能执行,否则就会报告下面的错误,而且无法安装到/usr/lib/libpn/下 # cp scripts/makefile.linux makefile # ./configure --prefix=/usr/local/libpng/ # make && make install
如果执行上文的cp script...命令,最后安装PHP时会总是报告:
./conftest: error while loading shared libraries: libpng14.so.14: cannot open shared object file: No such file or directory
错误。
经查,libpng相关文件并没有安装到/usr/local/libpng下面,只是把库libpng14.so.14.11拷贝到/usr/local/lib/下,实际的libpng14.so.14文件却在原编译目录下,即使尝试为它创建链接也无法解决上述错误。最后干脆直接去掉该句,反倒好了。
5、编译安装freetype
# cd /tmp # wget http://oss.oetiker.ch/rrdtool/pub/libs/freetype-2.3.5.tar.gz # tar zxvf freetype-2.3.5.tar.gz # cd freetype-2.3.5 # ./configure --prefix=/usr/local/freetype2/ # make && make install
6、安装GD库:
注意configure参数对应上文各路径是否正确,如果没装可对应去掉该项参数。
# cd /tmp # wget http://google-desktop-for-linux-mirror.googlecode.com/files/gd-2.0.35.tar.gz # tar zxvf gd-2.0.35.tar.gz # cd gd/2.0.35/ # ./configure --prefix=/usr/local/gd2 --with-zlib=/usr/local/zlib2/ --with-png=/usr/local/libpng/ --with- jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype2/ --with-libart=/usr/local/libart/ --with- gettext=/usr/local/gettext/ --with-libxml=/usr/local/libxml2 我的配置: # ./configure --prefix=/usr/local/gd2 --with-zlib=/usr/local/zlib2/ --with-png=/usr/local/libpng/ --with- jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype2/ --with-libxml=/usr/local/libxml2 # cp /usr/lib/libattr.* /lib/ # make && make install
五、安装PHP及curl、ZendOptimizer支持
1、编译安装Curl支持:
# cd /tmp # wget http://dl.ambiweb.de/mirrors/curl.haxx.se/curl-7.15.0.tar.gz # tar zxvf curl-7.15.0.tar.gz # cd curl-7.15.0 # ./configure --prefix=/usr/local/curl # make && make install
2、libmcrypt库一般也需要:
# cd /tmp #tar zxvf libmcrypt-2.5.7.tar.gz #cd libmcrypt-2.5.7 #./configure --prefix=/usr/local/libmcrypt #make #make install
3、编译安装PHP:
# cd /tmp #wget http://download.huihoo.com/php/php-5.4.0.tar.gz #tar zxvf php-5.4.0.tar.gz #cd php-5.4.0 # ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache2/bin/apxs --with-jpeg-dir=/usr/local/jpeg6/ --with-freetype-dir=/usr/local/freetype2/ --with-zlib --with-png-dir=usr/local/libpn2 --with-libxml-dir=/usr/local/libxml2 --with-gd --with-mcrypt=/usr/local/libmcrypt/ --enable-ftp --enable-sockets 我的配置: # ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5 --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache2/bin/apxs --with-jpeg-dir=/usr/local/jpeg6/ --with-freetype-dir=/usr/local/freetype2/ --with-zlib-dir=/usr/local/zlib/ --with-png-dir=/usr/local/libpng/ --with-libxml-dir=/usr/local/libxml2 --with-gd=/usr/local/gd2/ --with-mysqli=/usr/local/mysql/bin/mysql_config #make && make install
其中--with-config-file-path指定加载PHP配置文件路径。如果不设置,那么PHP无法找到Loaded Configuration File路径(phpinfo里可查看)。
--with-mysqli=/usr/local/mysql/bin/mysql_config是为了增加mysqli支持,但是问题由此而来,测试编译php-5.2.6时总是出现某个变量未定义现象,之后改成5.4.0又出现struct gdIOCtx中没有data指针定义,最后修改/usr/local/gd2/include/gd_io.h,gdIOCtx结构中增加void *data;这才编译通过。
从源码中拷贝PHP配置文件:
- # cp php.ini-dist /usr/local/php5/php.ini
修改/usr/local/php5/php.ini文件,如果有额外模块需要加载,修改extension_dir- = "./" 为 extension_dir- = "./include/php/ext"。
4、安装ZendOptimizer:
# cd /tmp # tar zxvf ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz # cd ZendOptimizer-3.3.0a-linux-glibc21-i386 # ./install
5、安装phpmyadmin:
# cd /tmp # tar jxvf phpMyAdmin-2.11.9.4-all-languages-utf-8-only.tar.bz2 # mv phpMyAdmin-2.11.9.4-all-languages-utf-8-only /usr/local/apache/htdocs/ # cd /usr/local/apache/htdocs/ # cp libraries/config.default.php config.inc.php
phpmyadmin在使用前还需修改配置文件,config.inc.php,设置数据库访问名称、密码等,本文从略。
六、安装结束
重启apache服务:
service httpd restart
重启mysql:
service mysqld restart
此两步难顺利者十之八九,多次摸索之后一般均可解决。
参考资料:
http://www.oschina.net/question/17_87,几个问题都是从TA的文章中得到解决方法。
http://www.linuxidc.com/Linux/2012-04/58140.htm 介绍源码编译MYSQL 5.5.22
http://zhengdl126.iteye.com/blog/481183 介绍CentOS下安装LAMP
更多文章:
