下载 PHP 源码包
1# wget
http://cn2.php.net/distributions/php-5.6.0.tar.xz
1# xz -d PHP-5.6.0.tar.xz
1# tar xf PHP-5.6.0.tar -C /usr/local/src/
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel
libiconv-devel(源码包,编译安装)
(./configure make make install )
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel bz2-devel
(yum install epel-release.noarch )
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel mhash mcrypt
创建 www 用户
1# groupadd www
1# useradd -g www -s /sbin/nologin -M www
编译安装
1# cd /usr/local/src/PHP-5.6.0/
1# ./configure \
--prefix=/usr/local/PHP56 \
--with-config-file-path=/usr/local/PHP56/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-MysqL=MysqLnd \
--with-MysqLi=MysqLnd \
--with-pdo-MysqL=MysqLnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline\
--with-gd
提示 : 某些包 缺少 , yum install 包
加号中部分可以先忽略 :
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
配置redis PHP
wget https://github.com/phpredis/phpredis/archive/develop.zip --no-check-certificate
unzip develop.zip
cd PHPredis-develop/
PHPize
./configure --with-PHP-config=/usr/local/PHP56/bin/PHP-config
make && make install
vim /usr/local/PHP56/etc/PHP.ini
[redis]extension=redis.so
配置 memcache
./configure --with-PHP-config=/usr/local/PHP56/bin/PHP-config
[memcache]
extension=memcache.so
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
参数说明:
""" 安装路径 """
--prefix=/usr/local/PHP56 \
""" PHP.ini 配置文件路径 """
--with-config-file-path=/usr/local/PHP56/etc \
""" 优化选项 """
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) """
--enable-opcache \
""" FPM """
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
""" MysqL """
--with-MysqL=MysqLnd \
--with-MysqLi=MysqLnd \
--with-pdo-MysqL=MysqLnd \
""" 国际化与字符编码支持 """
--with-gettext \
--enable-mbstring \
--with-iconv \
""" 加密扩展 """
--with-mcrypt \
--with-mhash \
--with-openssl \
""" 数学扩展 """
--enable-bcmath \
""" Web 服务,soap 依赖 libxml """
--enable-soap \
--with-libxml-dir \
""" 进程,信号及内存 """
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
""" socket & curl """
--enable-sockets \
--with-curl \
""" 压缩与归档 """
--with-zlib \
--enable-zip \
--with-bz2 \
""" GNU Readline 命令行快捷键绑定 """
--with-readline
如果你的 Web Server 使用的 Apache 请添加类似:--with-apxs2=/usr/local/apache-xx/bin/apxs 参数。
关于 MysqLnd 请查看 什么是 PHP 的 MysqL Native 驱动? 或查看 MysqL 官方介绍:MysqL native driver for PHP, 或 Installation on Unix。
PHP 5.6 內建了 PHPdbg 交互式调试器,通过 --enable-PHPdbg 开启,会在 PREFIX/bin 目录下产生一个 PHPdbg 命令,感兴趣的可以试一下。
更多编译参数请使用 ./configure --help 查看。
1# make -j8
1# make install
如果想重新安装:
make过程中报错,解决错误后,
1# make clean
然后再 make
1# ./configure ...
1# make -j8
1# make install
配置 PHP
cd /usr/local/src/PHP-5.6源码包
配置文件:
1# cp PHP.ini-development /usr/local/PHP56/etc/PHP.ini
PHP-fpm 服务
1# cp /usr/local/PHP56/etc/PHP-fpm.conf.default /usr/local/PHP56/etc/PHP-fpm.conf
1# cp sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm56 (PHP-fpm的可执行文件)
1# chmod +x /etc/init.d/PHP-fpm56
启动 PHP-fpm(Nginx与 PHP沟通 )
1# service PHP-fpm56 start
Starting PHP-fpm done
PHP-fpm 可用参数 start|stop|force-quit|restart|reload|status
+++++++++++++++++++++++++++++++++++++++++++
添加 PHP 命令到环境变量
编辑 /etc/profile ,将:
PATH=$PATH:$HOME/bin
改为:
PATH=$PATH:$HOME/bin:/usr/local/PHP56/bin
使 PHP 环境变量生效:
source /etc/profile