PHP7安装配置教程(非常详细)

PHP7算是非常新的版本了我们在windows版本中还没有PHP7了,只有在linux系统中才有关PHP7了,下面我来为各位介绍PHP7安装配置教程,希望对大家有帮助.

安装mcrypt

yum install -y php-mcrypt libmcrypt libmcrypt-devel

升级bison

  1. cd /var/soft/
  2. wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz
  3. tar -xvzf bison-2.6.4.tar.gz
  4. cd bison-2.6.4
  5. ./configure
  6. make && make install

升级re2c,解决You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.错误.

  1. cd /var/soft/
  2. wget http://sourceforge.net/projects/re2c/files/re2c/0.13.5/re2c-0.13.5.tar.gz/download
  3. tar zxf re2c-0.13.5.tar.gz && cd re2c-0.13.5
  4. ./configure
  5. make && make install

编译PHP7

  1. # 创建目录
  2. mkdir -p /var/soft/php7
  3. cd /var/soft/php7
  4. # 下载源代码
  5. git clone http://git.php.net/repository/php-src.git
  6. cd php-src //开源软件:phpfensi.com
  7. ./buildconf
  8. # 配置参数
  9. ./configure --prefix=/usr/local/php7 \
  10. --with-config-file-path=/usr/local/php7/etc \
  11. --with-mcrypt=/usr/include \
  12. --with-mysql=mysqlnd \
  13. --with-mysqli=mysqlnd \
  14. --with-pdo-mysql=mysqlnd \
  15. --with-gd \
  16. --with-iconv \
  17. --with-zlib \
  18. --enable-xml \
  19. --enable-bcmath \
  20. --enable-shmop \
  21. --enable-sysvsem \
  22. --enable-inline-optimization \
  23. --enable-mbregex \
  24. --enable-fpm \
  25. --enable-mbstring \
  26. --enable-ftp \
  27. --enable-gd-native-ttf \
  28. --with-openssl \
  29. --enable-pcntl \
  30. --enable-sockets \
  31. --with-xmlrpc \
  32. --enable-zip \
  33. --enable-soap \
  34. --without-pear \
  35. --with-gettext \
  36. --enable-session \
  37. --with-curl \
  38. --with-jpeg-dir \
  39. --with-freetype-dir \
  40. --enable-opcache
  41. #################################################################################

编译安装php时出现 /encodings.c:101: undefined reference to `libiconv_close’ 错误的解决方法.

在装php时出现以下的错误:

  1. # /root/Downloads/php-5.6.5/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv_open'
  2. # /root/Downloads/php-5.6.5/ext/xmlrpc/libxmlrpc/encodings.c:81: undefined reference to `libiconv'
  3. # /root/Downloads/php-5.6.5/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close'
  4. # /root/Downloads/php-5.6.5/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close'
  5. # collect2: error: ld returned 1 exit status
  6. # make: *** [sapi/cli/php] Error 1

根据php官网描述这是一个bug(https://bugs.php.net/bug.php?id=52611),在configure以后要手动修改下Makefile文件,找到EXTRA_LIBS 在最后添加 -liconv 即可顺利通过.

大约在Makefile文件的104.

  1. # EXTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lrt -lmysqlclient -lmcrypt -lltdl -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lfreetype -lmysqlclient -lz -lm -lssl -lcrypto -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcrypt -liconv
  2. #################################################################################

编译安装

make && sudo make install

配置:

  1. cp php.ini-production /usr/local/php7/etc/php.ini
  2. cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
  3. chmod +x /etc/init.d/php7-fpm
  4. cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
  5. cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

配置opcache

vim /usr/local/php7/etc/php.ini

加入:zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/opcache.so

启动:/etc/init.d/php7-fpm start

查看PHP版本:

/usr/local/php7/bin/php -v

结果:

  1. PHP 7.0.0-dev (cli) (built:www.phpfensi.com Mar 3 2015 10:02:26)
  2. Copyright (c) 1997-2015 The PHP Group
  3. Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
  4. with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies