Red Hat 9.0 下安装Apache 2.0.52 + Php 4.3.9 + MySQL 4.0.12 + Python 2.3.4 + Mysql-python 1.0.0 + GD库
为人民服务,分享安装经验!
说明:
安装顺序:
MySQL 4.0.12
GD库的所有软件
Apache 2.0.52
Php 4.3.9
Python 2.3.4
Mysql-python 1.0.1
一. 安装MySQL
说明:为了保证能顺利安装MySQL,本文采用的RPM包的形式来安装MySQL。(也是为了减少安装的复杂性)
所需软件:
MySQL-server-4.0.12-0.i386.rpm
MySQL-client-4.0.12-0.i386.rpm
MySQL-devel-4.0.12-0.i386.rpm
MySQL-shared-4.0.12-0.i386.rpm
安装过程:
[test@redhat9]#rpm –ihv MySQL-server-4.0.12-0.i386.rpm
[test@redhat9]#rpm –ihv MySQL-client-4.0.12-0.i386.rpm
[test@redhat9]#rpm –ihv MySQL-devel-4.0.12-0.i386.rpm
[test@redhat9]#rpm –ihv MySQL-shared-4.0.12-0.i386.rpm
或者用一个命令同时安装这4个rpm包,如下:(每个包名之间用空格相隔)
[test@redhat9]#rpm –ihv MySQL-server-4.0.12-0.i386.rpm MySQL-client-4.0.12-0.i386.rpm MySQL-devel-4.0.12-0.i386.rpm MySQL-shared-4.0.12-0.i386.rpm
用些方法安装mysql后,数据库文件默认的位置是/var/lib/mysql,可通过更改 mysql的配置文件来改变这个位置
测试:
安装成功之后会在 /etc/init.d/ 这个目录下有个mysql的启动控制脚本mysql,用这个脚本可以控制mysql服务器的启动和停止 如 ./mysql start或 ./mysql stop。下面看看mysql运行是否正常
[test@redhat9]#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 116 to server version: 4.0.12
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
如果出现以上信息,说明mysql运行正常。可以对其进行操作了。关于详细的mysql使用方法,请参考MySQL的中文使用手册
附:源代码安装(不做详细说明)
#源代码安装
./configure --prefix=/usr/local/mysql --with-pthread
make
make install
scripts/mysql_install_db
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
cd /usr/local
chmod 750 mysql -R
chgrp mysql mysql -R
chown mysql mysql/var -R
cd /usr/local/mysql/libexec
cp mysqld mysqld.old
strip mysqld
/sbin/chkconfig --add mysqld
/sbin/chkconfig --level 345 mysqld on
/sbin/service mysqld start
netstat -atln
ln -s /usr/local/mysql/bin/mysql /sbin/mysql
ln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin
mysqladmin -u root password "12345678"
mysql -u root -p
mysql>use mysql;
mysql>delete from user where password="";
mysql>flush privileges;
mysql>quit;
#可能会用到下列操作
#echo /usr/local/mysql/lib/mysql >> /etc/ld.so.conf
#ldconfig -v | grep libmysqlclient
#/etc/ld-elf.so.conf
# ldconfig
二. 安装GD库
所需软件:
gd-2.0.28.tar.gz
gd-devel-1.8.4-11.i386.rpm(gd-devel-2.0.28-1 RPM for i386De Fedora Core Development - i386)
freetype-2.1.3-6.i386.rpm
freetype-devel-2.1.3-6.i386.rpm
libpng-1.2.2-16.i386.rpm
libpng-devel-1.2.2-16.i386.rpm
zlib-1.1.4-8.i386.rpm
zlib-devel-1.1.4-8.i386.rpm
jpegsrc.v6b.tar.gz
如果你系统中已有上述软件的一个或多个,则不用再装安装,查看方法(限RPM包),例:
[test@redhat9]#rpm –qa |grep zlib
以上用RPM包安装的软件也可用源代码形式安装,效果相同。
安装过程:
第一步:安装GD库基本包
[test@redhat9]#rpm -ivh gd-devel-1.8.4-11.i386.rpm
第二:安装zlib
[test@redhat9]#rpm –ihv zlib-1.1.4-8.i386.rpm zlib-devel-1.1.4-8.i386.rpm
第三:安装 libpng
[test@redhat9]#rpm –ihv zlib-1.1.4-8.i386.rpm libpng-1.2.2-16.i386.rpm zlib-devel-1.1.4-8.i386.rpm
第四:安装freetype
[test@redhat9]#rpm –ihv freetype-2.1.3-6.i386.rpm libpng-devel-1.2.2-16.i386.rpm
第五步:安装 jpegsrc(源代码安装)
[test@redhat9]#tar zxvf jpegsrc.v6b.tar.gz
[test@redhat9]#cd jpeg-6b
[test@redhat9]#./configure
[test@redhat9]#make
[test@redhat9]#make install-headers
[test@redhat9]#make install-lib
[test@redhat9]#make install
第六步:安装GD库
[test@redhat9]#tar zxvf gd-2.0.28.tar.gz
[test@redhat9]#cd gd-2.0.28
[test@redhat9]#./configure --with-png=/usr/local --with-jpeg=/usr/local
[test@redhat9]#make
[test@redhat9]#make install
安装完成,如果安装过程出现错误,可能是缺少某个软件包,安装上相应的软件包即可
三. 安装Apache
所需软件:
httpd-2.0.52.tar.gz
安装过程:
[test@redhat9]#tar zxvf httpd-2.0.52.tar.gz
[test@redhat9]#cd httpd-2.0.52
[test@redhat9]#./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=most
[test@redhat9]#make
[test@redhat9]#make install
/*---配置Apache---*/
[test@redhat9]#vi /usr/local/apache2/conf/httpd.conf
(1)寻找Add Type application/x-tar .tgz 在下面添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
(2)显示中文,修改: AddDefaultCharset gb2312
(3)修改ServerAdmin q3boy@younet.com
(4)改变HTML文件主目录:DocumentRoot "/home/httpd/html/"
(5)Options FollowSymLinks MultiViews 为安全起见,去掉"Indexes"
(6)修改Apache主机地址:ServerName localhost
(7)设置apache的默认文件名次序DirectoryIndex default.php default.phtml default.php3 default.html default.htm
(8)设置php文件后缀
AddType application/x-httpd-php .cgis .php .phtml .php3 .inc
AddType application/x-httpd-php-source .phps
(9)重新启动Apache:
[test@redhat9]#/usr/local/apache2/bin/apachectl restart
(10)将Aapche添加到系统服务中
a.查看apache服务是否已在系统中
[test@redhat9]#/sbin/chkconfig –list |grep httpd
如果出现以下信息,则说明此Apache已被添加到服务服务中了,可略过此步聚
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
b.添加Aapche到系统启动菜单
[test@redhat9]#cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
[test@redhat9]#vi /etc/rc.d/init.d/httpd
在httpd文件的第三行,插入以下两句话(要有#号):
# chkconfig: 2345 77 19
# description: Starts and stops the Apache HTTP Server.
确保httpd为可执行文件:
[test@redhat9]#chmod +x /etc/rc.d/init.d/httpd
将httpd添加到系统服务中:
[test@redhat9]#chkconfig --add httpd
查看apache服务是否已在系统中
[test@redhat9]#chkconfig --list
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
c.说明:
httpd在运行级 2, 3, 4, 5 启动,启动优先权为77,停止优先权为19。
四. 安装PHP
所需软件:
php-4.3.7.tar.gz
安装过程:
[test@redhat9]#tar -zxvf php-4.3.9.tar.gz
[test@redhat9]#cd php-4.3.9
[test@redhat9]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-gd=/usr/local --with-zlib-dir=/usr/local --with-ttf --with-curl
--with-xml --with-mysql --enable-ftp --enable-memory-limit --enable-sockets --enable-debug=no
--enable-trace-vars [test@redhat9]#make
[test@redhat9]#make install
[test@redhat9]#cp php.ini-dist /usr/local/lib/php.ini
[test@redhat9]#vi /usr/local/lib/php.ini
把 #register-globals = Off
改为 register-globals = On
错误处理:
a. 如果连接mysql出现:mysql.sock 这样的错误,那么请修改:php.ini文件:
mysql.default_socket = /var/lib/mysql/mysql.sock
b. 如果出现如下字样的错误,请修改 gd.c文件,然后重新编译
In function `zm_deactivate_gd':
ext/gd/gd.c:385: undefined reference to `gdFreeFontCache'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php]Error 1
gd.c文件在php解压目录下
[test@redhat9]#vi ext/gd/gd.c
要修改的原代码:
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
#if HAVE_LIBGD20 && HAVE_GD_STRINGFT
PHP_RSHUTDOWN_FUNCTION(gd)
{
#if defined(HAVE_GD_THREAD_SAFE) || defined(HAVE_GD_BUNDLED)
gdFontCacheShutdown();
#else
gdFreeFontCache();
#endif
return SUCCESS;
}
#endif
/* }}} */
将: gdFreeFontCache();
修改为:/* gdFreeFontCache(); */
五. 安装Python
所需软件:
Python-2.3.4.tgz
安装过程:
[test@redhat9]#./configure
[test@redhat9]#make
[test@redhat9]#./python
[test@redhat9]#make install
[test@redhat9]#cp /usr/local/bin/python /usr/bin/python
六. Mysql-python
所需软件:
MySQL-python-1.0.0.tar.gz
安装过程:
[test@redhat9]#tar xfz MySQL-python-1.0.0.tar.gz
[test@redhat9]#cd MySQL-python-1.0.0
[test@redhat9]#export mysqlversion="4.0.12"
[test@redhat9]#export mysqlclient="mysqlclient_r"
[test@redhat9]#export mysqloptlibs="ssl crypto"
[test@redhat9]#python setup.py build
[test@redhat9]#python setup.py install
---注意--如果出现以下错误,则请安装openssl
gcc -pthread -shared build/temp.linux-i686-2.3/_mysql.o -L/usr/lib/mysql -L/usr/local/lib/mysql -L/usr/local/mysql/lib - L/usr/local/mysql/lib/mysql -lmysqlclient_r -lssl -lcrypto -lz -lcrypt -o build/lib.linux-i686-2.3/_mysql.so
/usr/bin/ld: cannot find -lssl