据说php5.4要比此前各版本的php快不少,所以有必要安装来测试一下(国内比较流行的一些php程序比如discuz等等对php5.4的支持貌似还不太友好,所以站长朋友们还是要慎重升级)。下面是在64位centos6.1上面编译安装的笔记,仅供参考。
1、下载
wget http://cn.php.net/get/php-5.4.8.tar.gz/from/this/mirror
wget http://pecl.php.net/get/memcache-2.2.7.tgz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
wget https://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"
wget ftp://ftp.kddlabs.co.jp/graphics/ImageMagick/ImageMagick.tar.gz
wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
wget http://pecl.php.net/get/imagick-3.1.0RC2.tgz
2、另外一些准备工作
yum install ncurses-devel libxml2-devel bzip2-devel libcurl-devel curl-devel libjpeg-devel libpng-devel freetype-devel net-snmp-devel -y
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/ (假定mysql已经安装。不加这个的话后面编译的时候可能会出错)
3、还有这些准备工作(编译一些php需要用到的支持库)
tar xzvf libic*
cd libic*
./configure --prefix=/usr/local
make
make install
cd ..
tar xzvf libmcry*
cd libmcry*
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure
--enable-ltdl-install
make
make install
cd ../../
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
4、开始编译安装php
tar xvzf php-5.4.*.tar.gz cd php-5.4.*
./configure --prefix=/usr/local/php --with-config-file-path=/etc \
--with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql/ --with-iconv-dir=/usr/local --enable-fpm \
--disable-phar --with-fpm-user=www --with-fpm-group=www --with-pcre-regex \
--with-zlib --with-bz2 --enable-calendar --with-curl --enable-dba --with-libxml-dir \
--enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir \
--enable-gd-native-ttf --enable-gd-jis-conv --with-mhash --enable-mbstring --with-mcrypt \
--enable-pcntl --enable-xml --disable-rpath --enable-shmop --enable-sockets --enable-zip \
--enable-bcmath --with-snmp --disable-ipv6
make ZEND_EXTRA_LIBS='-liconv'
make test
make install
cp php.ini-production /etc/php.ini
5、编译安装php的一些扩展模块
tar zxvf memcache-*.tgz
cd memcache-*/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
tar xzvf libevent*
cd libevent*
./configure --prefix=/usr/local
make
make install
cd ..
tar xvzf memcached-*.gz
cd memcached-*
./configure --with-libevent=/usr/local --prefix=/usr/local/memcached
make
make install
cd ../
tar zxvf ImageMagick.tar.gz
cd ImageMagick-*/
./configure
make
make install
cd ../
tar zxvf imagick-*.tgz
cd imagick-*/
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ /usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
6、修改php的一些参数配置
vi /etc/php.ini
增加这些:
extension_dir = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
extension = "memcache.so"
extension = "imagick.so"
修改这些:
cgi.fix_pathinfo=0
服务器安装好php之后,出于安全考虑,需要禁用掉一些有潜在危险的php函数。下面这些函数如果没有特殊需要,可以禁用掉:
exec,system,phpinfo,eval,passthru,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,fsocket,fsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
禁用方法:
修改php.ini,找到disable_functions,修改为:
disable_functions = exec,system,phpinfo,eval,passthru,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,fsocket,fsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
参考资料: