CentOS7编译安装php7.1的教程详解

这篇文章主要介绍了CentOS7编译安装php7.1的教程详解,非常不错,具有一定的参考借鉴价值 ,需要的朋友可以参考下

1.首先安装依赖包:

  1. yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel

2.下载PHP压缩包并解压:

  1. wget http://php.net/distributions/php-7.1.0.tar.gz
  2. tar -zxvf php-7.1.0.tar.gz
  3. cd php-7.1.0

3.编译安装,编译的时候可能会出现各种报错情况,下一篇主要写编译是常见的错误及解决办法:

  1. ./configure \
  2. --prefix=/usr/local/php \
  3. --with-config-file-path=/etc \
  4. --enable-fpm \
  5. --enable-inline-optimization \
  6. --disable-debug \
  7. --disable-rpath \
  8. --enable-shared \
  9. --enable-soap \
  10. --with-libxml-dir \
  11. --with-xmlrpc \
  12. --with-openssl \
  13. --with-mcrypt \
  14. --with-mhash \
  15. --with-pcre-regex \
  16. --with-sqlite3 \
  17. --with-zlib \
  18. --enable-bcmath \
  19. --with-iconv \
  20. --with-bz2 \
  21. --enable-calendar \
  22. --with-curl \
  23. --with-cdb \
  24. --enable-dom \
  25. --enable-exif \
  26. --enable-fileinfo \
  27. --enable-filter \
  28. --with-pcre-dir \
  29. --enable-ftp \
  30. --with-gd \
  31. --with-openssl-dir \
  32. --with-jpeg-dir \
  33. --with-png-dir \
  34. --with-zlib-dir \
  35. --with-freetype-dir \
  36. --enable-gd-native-ttf \
  37. --enable-gd-jis-conv \
  38. --with-gettext \
  39. --with-gmp \
  40. --with-mhash \
  41. --enable-json \
  42. --enable-mbstring \
  43. --enable-mbregex \
  44. --enable-mbregex-backtrack \
  45. --with-libmbfl \
  46. --with-onig \
  47. --enable-pdo \
  48. --with-mysqli=mysqlnd \
  49. --with-pdo-mysql=mysqlnd \
  50. --with-zlib-dir \
  51. --with-pdo-sqlite \
  52. --with-readline \
  53. --enable-session \
  54. --enable-shmop \
  55. --enable-simplexml \
  56. --enable-sockets \
  57. --enable-sysvmsg \
  58. --enable-sysvsem \
  59. --enable-sysvshm \
  60. --enable-wddx \
  61. --with-libxml-dir \
  62. --with-xsl \
  63. --enable-zip \
  64. --enable-mysqlnd-compression-support \
  65. --with-pear \
  66. --enable-opcache

4.编译成功后安装:

make && make install

5.安装成功后配置环境变量:

为了使用方便,可以在 /etc/profile文件末尾添加php环境变量 :

PATH=$PATH:/usr/local/php/bin

export PATH

保存后刷新环境变量:

source /etc/profile  #更新

查看环境变量:

echo $PATH

看到php环境变量的路径后,以后就可以直接使用php命令了,查看php版本:

php -v

6.现在的PHP没有.ini文件和配置文件,还需要配置PHP-FPM:

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

php-fpm的启动、停止和重启:

service php-fpm start  #启动

service php-fpm stop   #停止

service php-fpm restart #重启