怎样在 CentOS 6.5 64位系统上安装Apache 2.2.15 + MySQL 5.1.73 + PHP 5.2.17

2014年12月17日 | 分类: 【技术】

有些老的系统,比如ECShop,需要PHP 5.3以下的版本,而PHP 5.2.17是最后的一个版本。

如果想快速安装LAMP,推荐参考:《怎样在 CentOS 6.5 64位系统上安装Apache 2.2.15 + MySQL 5.1.73 + PHP 5.3.3》

如果想安装指定最新版本的 PHP 5.6,请参考:《怎样在 CentOS 6.5 64位系统上安装Apache 2.4.12 + MySQL 5.5.44 + PHP 5.6》

准备工作

1. 重置系统(Rebuild CentOS)

在控制面板上rebuild CentOS,比如本教程采用 CentOS6.5 64位。https://en.wikipedia.org/wiki/CentOS

CentOS 6.5基于Red Hat Enterpris Linux (RHEL) 6.5。

CentOS 5.3 基于 Red Hat Enterpris Linux 5.3.0,其中包括 Kernel 2.6.18、Apache 2.2、PHP 5.1.6、MySQL 5.0、PostgreSQL 8、GNOME 2.16、KDE 3.5、OpenOffice.org 2.3、Firefox 3.0、Evolution 2.12 等等。CentOS 5.3 支持 i386 及 x86_64 架构。

2. CentOS更改root用户初始密码

以root用户SSH模式登录

passwd

输入2次新密码:

Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

3. 更新系统内核到最新

yum -y update

4. 确认必要的工具包已经安装

yum install gcc-c++ gcc make wget

第一步. 安装Apache

yum install httpd httpd-devel

安装完成后,启动Apache:

/etc/init.d/httpd start

设为开机启动:

chkconfig httpd on

查看apache http server的版本:

/usr/sbin/httpd -v

输出:

Server version: Apache/2.2.15 (Unix)
Server built:   Oct 16 2014 14:48:21

Apache 2.2.15 安装完成!

第二步. 安装MySQL

yum install mysql mysql-server mysql-devel

完成后,启动MySQL:

/etc/init.d/mysqld start

设置MySQL密码:

/usr/bin/mysqladmin -u root -h localhost password '新密码'

如果需要修改root密码,请查看《怎样在CentOS上修改MySQL的root密码》

让MySQL数据库更安全:

mysql -u root -p [此时会要求你输入刚刚设置的密码,输入后回车即可
mysql> DROP DATABASE test; [删除test数据库]
mysql> DELETE FROM mysql.user WHERE user =''; [删除匿名帐户]
mysql> FLUSH PRIVILEGES; [重载权限]
mysql> exit; [退出MYSQL]

设为开机启动:

chkconfig mysqld on

查看MySQL版本:

mysql -v -p
Enter password:

输出:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Reading history-file /root/.mysql_history
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL 5.1.73安装完毕!

第三步. 安装PHP

1. 安装aspell/pspell(http://aspell.net/http://aspell.sourceforge.net/

这两个扩展会识别单词的拼法是否正确并给出意见。

如果需要在编译PHP时添加pspell支持,必须安装aspell库。

编译php时加上 ./configure –with-pspell=/usr 如果是phpize 编译 –with-pspell=/usr

当然也可以跳过这个文件,直接把configure命令中的 –with-pspell 参数去掉即可。

wget http://mirrors.kernel.org/gnu/aspell/aspell-0.60.6.tar.gz
tar -xzvf aspell-0.60.6.tar.gz
cd aspell-0.60.6
./configure --prefix=/usr
make && make install

安装字典:

wget http://mirrors.kernel.org/gnu/aspell/dict/en/aspell6-en-6.0-0.tar.bz2
tar -xf aspell6-en-6.0-0.tar.bz2
cd aspell6-en-6.0-0
./configure
make && make install

2. 再安装几个组件,先安装Libmcrypt,再安装mhash,再安装mcrypt

Libmcrypt(http://sourceforge.net/projects/mcrypt/files/Libmcrypt/

yum install libmcrypt

或者通过安装包安装:

wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -xzvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install

mhash(http://sourceforge.net/projects/mhash/files/mhash/

yum install mhash

或者通过安装包安装:

wget http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar -xzvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make && make install

MCrypt(http://sourceforge.net/projects/mcrypt/files/MCrypt/

yum install mcrypt

或者通过安装包安装:

wget http://downloads.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar -xzvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make && make install

这三个扩展也可以通过第三方源rpmforge实现yum安装,在centos下配置该yum源,配置后即可尝试安装:

rpm -ivh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
yum clean all
yum makecache
yum install libmcrypt libmcrypt-devel mcrypt-devel

3. 确认已安装PHP编译安装需要的组件的开发包及编译工具等

yum -y install gcc gcc-c++ perl flex autoconf zlib libtiff-devel  pam-devel libtool libtool-ltdl libtool-ltdl-devel bison bison-devel libxslt libxslt libxslt-devel ncurses ncurses-devel zlib zlib-devel openssl openssl-devel gnutls-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel gmp-devel mysql-devel ncurses ncurses-devel unixODBC-devel pspell-devel net-snmp net-snmp-devel openldap-devel openldap-servers openldap-clients

4. 安装PHP

PHP各版本下载地址 http://www.php.net/releases/ ,本例中需要下载安装 php-5.2.17.tar.gz。

wget http://museum.php.net/php5/php-5.2.17.tar.gz
tar -xzvf php-5.2.17.tar.gz
cd php-5.2.17
./configure --prefix=/usr/local/php --with-apxs2=/usr/sbin/apxs --with-config-file-path=/usr/local/etc --with-config-file-scan-dir=/etc/php.d --without-sqlite --enable-mbstring --with-curl --with-gettext --with-bz2 --with-mysql=/usr/lib64/mysql -enable-shmop --enable-calendar --with-openssl --with-pspell --enable-ftp --with-openssl --with-zlib --enable-exif --with-gmp --enable-sysvmsg --enable-sockets --enable-wddx --with-xsl --with-mcrypt --with-mysqli --with-mime_magic --with-pdo-mysql --libdir=/usr/lib64 --with-libdir=lib64 --with-gd --with-jpeg-dir=/usr/lib64 --with-png-dir=/usr/lib64 --with-freetype-dir=/usr/lib64
make && make install

查看PHP版本:

/usr/local/php/bin/php -v

输出:

PHP 5.2.17 (cli) (built: Jul 14 2015 16:14:59)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

安装PHP 5.2.17完成!