下载 PHP 源码包

# wget http://cn2.php.net/distributions/php-5.6.0.tar.xz
# xz -d php-5.6.0.tar.xz
# tar xf php-5.6.0.tar -C /usr/local/src/

添加 epel 源

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

安装依赖

# yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel

 

注:如果需要直接安装gd库,需要以下扩展

yum -y install gd gd2 gd-devel gd2-devel zlib freetype

 

注:如果你使用的 epel 7 的源,可能会没有 mcrypt mhash mhash-devel 几个包,在 http://dl.fedoraproject.org/pub/epel/6/x86_64/ 中下载,使用 yum localinstall xxx.rpm 或 rpm -Uvh xxx.rpm 手动安装即可。

创建 www 用户

# groupadd www
# useradd -g www -s /sbin/nologin -M www

编译安装

# cd /usr/local/src/php-5.6.0/

# ./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\
//需要gd库扩展,需添加以下参数
-with-png-dir --with-freetype-dir --with-jpeg-dir=/usr/local/jpeg -with-zlib-dir --with-gd

 

配置 PHP

# cp php.ini-development /usr/local/php56/etc/php.ini

php-fpm 服务

# cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56
# chmod +x /etc/init.d/php-fpm56

启动 php-fpm

# service php-fpm56 start
Starting php-fpm  done

php-fpm 可用参数 start|stop|force-quit|restart|reload|status

添加 PHP 命令到环境变量

编辑 ~/.bash_profile,将:

PATH=$PATH:$HOME/bin
改为:
PATH=$PATH:$HOME/bin:/usr/local/php56/bin

使 PHP 环境变量生效:

# . ~/.bash_profile

查看看 PHP 版本

# php -v

 

鉴于有些老铁忘记加上gd扩展,以下附上gd单独编译扩展

https://www.cnblogs.com/xiaoqian1993/p/6277766.html

 

 

参考网址:http://blog.aboutc.net/linux/65/compile-and-install-php-on-linux

https://www.douban.com/note/498893885/?type=like