1. 更新系统内核到最新
1
|
yum -y update
|
2. 安装必要的工具包
1
|
yum
install
gcc
-c++
gcc
make
wget
|
3. 安装Apache
1
|
yum
install
httpd httpd-devel
|
安装完成后,启动Apache:
1
|
/etc/init
.d
/httpd
start
|
设为开机启动:
1
|
chkconfig httpd on
|
3. 安装MySQL:
1
|
yum
install
mysql mysql-server mysql-devel
|
完成后,启动MySQL:
1
|
/etc/init
.d
/mysqld
start
|
设置MySQL密码:
1
|
/usr/bin/mysqladmin
-u root -h localhost password
'新密码'
|
让MySQL数据库更安全:
1
2
3
4
5
|
mysql -u root -p [此时会要求你输入刚刚设置的密码,输入后回车即可
mysql> DROP DATABASE
test
; [删除
test
数据库]
mysql> DELETE FROM mysql.user WHERE user =
''
; [删除匿名帐户]
mysql> FLUSH PRIVILEGES; [重载权限]
mysql>
exit
; [退出MYSQL]
|
设为开机启动:
1
|
chkconfig mysqld on
|
4. 安装PHP
PHP各版本下载地址 http://www.php.net/releases/
一般下载 tar.gz 的包,比如本例中下载 php-5.2.17.tar.gz:
1
|
wget http:
//museum
.php.net
/php5/php-5
.2.17.
tar
.gz
|
解压缩,并转到目录中:
1
2
|
tar
-xzvf php-5.2.17.
tar
.gz
cd
php-5.2.17
|
先安装aspell(http://aspell.net/)
1
2
3
4
5
|
wget
ftp
:
//ftp
.gnu.org
/gnu/aspell/aspell-0
.60.6.1.
tar
.gz
tar
-xzvf aspell-0.60.6.1.
tar
.gz
cd
aspell-0.60.6.1
.
/configure
--prefix=
/usr
make
&&
make
install
|
再安装几个组件,先安装Libmcrypt,再安装mhash,再安装mcrypt
Libmcrypt(http://sourceforge.net/projects/mcrypt/files/Libmcrypt/)
1
2
3
4
5
|
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/)
1
2
3
4
5
|
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/)
1
2
3
4
5
|
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源,配置后即可尝试安装:
1
2
3
4
|
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
|
安装PHP编译安装需要的组件的开发包及编译工具等:
1
|
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
|
编译三步骤 configure、make、make install
1、configure
1
|
.
/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
|
这里注意:
a、指定安装路径,方便换版本及删除,也方便自己查找文件。
b、指定apache的相关文件apxs2的路径,这个文件安装了httpd-devel才有
c、指定配置文件路径,方便配置
d、指定相关lib文件的路径,本文是在64位系统下的lib64
2、make
make的时候可能会提示什么xxx没找到,解决方法一般是安装xxx-devel的包就可以了。
1
|
make
|
3、make install
1
|
make
install
|
编辑完成后,看提示:
1
|
libtool --finish
/root/php-5
.2.17
/libs
|
问题:libiconv.so.2: cannot open shared object file解决办法
错误如下:
1
2
3
|
error
while
loading shared libraries: libiconv.so.2: cannot
open
shared object
file
: No such
file
or directory
make
[1]: *** [
install
-pear-installer] 错误 127
make
: *** [
install
-pear] Error 2
|
find发现/usr/local/lib里面有库文件,但是/usr/lib里面没有
1
2
|
find
/ -name libiconv.so.2
/usr/local/lib/libiconv
.so.2
|
于是用软链接:
1
|
ln
-s
/usr/local/lib/libiconv
.so.2
/usr/lib/libiconv
.so.2
|
之后
1
|
make
clean
|
再编译 生成 安装,一切正常。
使用此方法的时候需要考虑到在configure时的支持选项–with-iconv-dir=/usr/local,所以创建连接这方式可能是无效的
解决方法是将/usr/local/lib路径添加到/etc/ld.so.conf文件中,然后用ldconfig命令加载,再重新输入make install命令就可以了
1.在/etc/ld.so.conf中加一行/usr/local/lib,
1
2
3
4
5
6
7
|
include ld.so.conf.d/*.conf
/usr/local/lib
1
2.然后运行
1
/sbin/ldconfig
|
问题:IP无法访问,关闭防火墙试试
1
|
service iptables stop
|
让apache调用这个php版本
1. 在httpd.conf中检查php模块有没有被调用
1
|
LoadModule php5_module modules
/libphp5
.so
|
2. 在httpd.conf中添加对PHP的解析
1
2
|
AddType application
/x-httpd-php
.php .phtml
AddType application
/x-httpd-php-source
.phps
set
-variable = max_connections=100
|
3. 在httpd.conf中添加 index.php 为默认首页
1
|
DirectoryIndex index.php index.html
|
参考资料: