CentOS 7 编译安装PHP 7.0.2

php7  

一、安装

  • 下载
    wget http://cn2.php.net/distributions/php-7.0.2.tar.gz
  • 安装依懒库
    yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel mhash gd gd-devel

  • 解压设置环境变量

tar zxf php-7.0.2.tar.gz  
cd php-7.0.2  
export LIBS="-lm -ltermcap -lresolv"  
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64/lib"  
export LD_LIBRARY_PATH="/usr/local/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64/lib"  
  • 编译参数配置
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts -with-mcrypt=/usr/include --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --enable-ftp --enable-session --with-gettext --with-jpeg-dir --with-freetype-dir --enable-fastcgi --without-gdbm --disable-fileinfo
  • 编译安装
    make clean && make && make install
  • PHP7的配置文件php.ini、和php-fpm脚本
cp php.ini-production /usr/local/php/etc/php.ini  
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  
chmod +x /etc/init.d/php-fpm  
chkconfig --add php-fpm  
chkconfig --level 35 php-fpm on  
  • 配置 php-fpm.conf
[global]
pid = /var/run/php-fpm.pid  
error_log = /var/log/php/php-fpm.log  
log_level = notice

[www]
listen = /var/run/php-fpm.sock  
;listen = 127.0.0.1:9000
user = www  
group = www  
listen.owner = www  
listen.group = www  
listen.mode = 0666  
pm = dynamic  
pm.max_children = 400  
pm.start_servers = 32  
pm.min_spare_servers = 32  
pm.max_spare_servers = 400  
pm.max_requests = 10240  

二、添加php的环境变量和启动

  • profile 配置
    echo "export PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH">> /etc/profile
    source /etc/profile

  • service php-fpm start