方法一、简单安装(通过yum)
1.安装epel-release
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3.安装PHP7
yum install php70w
方法二:编译安装
1.下载php7
1 wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror
2.解压php7
1 tar -xvf php7.tar.gz
3.进入php目录
1 cd php-7.0.4
4.安装依赖包
1 # 直接复制下面一行(不包括本行) 2 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
5.编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致)
嫌麻烦的可以从这一步起参考PHP官方安装说明:http://php.net/manual/zh/install.unix.nginx.php
1 ./configure 2 --prefix=/usr/local/php 3 --with-config-file-path=/etc 4 --enable-fpm 5 --with-fpm-user=nginx 6 --with-fpm-group=nginx 7 --enable-inline-optimization 8 --disable-debug 9 --disable-rpath 10 --enable-shared 11 --enable-soap 12 --with-libxml-dir 13 --with-xmlrpc 14 --with-openssl 15 --with-mcrypt 16 --with-mhash 17 --with-pcre-regex 18 --with-sqlite3 19 --with-zlib 20 --enable-bcmath 21 --with-iconv 22 --with-bz2 23 --enable-calendar 24 --with-curl 25 --with-cdb 26 --enable-dom 27 --enable-exif 28 --enable-fileinfo 29 --enable-filter 30 --with-pcre-dir 31 --enable-ftp 32 --with-gd 33 --with-openssl-dir 34 --with-jpeg-dir 35 --with-png-dir 36 --with-zlib-dir 37 --with-freetype-dir 38 --enable-gd-native-ttf 39 --enable-gd-jis-conv 40 --with-gettext 41 --with-gmp 42 --with-mhash 43 --enable-json 44 --enable-mbstring 45 --enable-mbregex 46 --enable-mbregex-backtrack 47 --with-libmbfl 48 --with-onig 49 --enable-pdo 50 --with-mysqli=mysqlnd 51 --with-pdo-mysql=mysqlnd 52 --with-zlib-dir 53 --with-pdo-sqlite 54 --with-readline 55 --enable-session 56 --enable-shmop 57 --enable-simplexml 58 --enable-sockets 59 --enable-sysvmsg 60 --enable-sysvsem 61 --enable-sysvshm 62 --enable-wddx 63 --with-libxml-dir 64 --with-xsl 65 --enable-zip 66 --enable-mysqlnd-compression-support 67 --with-pear 68 --enable-opcache
6.正式安装
1 make && make install
7.配置环境变量
1 vi /etc/profile
在末尾追加
1 PATH=$PATH:/usr/local/php/bin 2 export PATH
执行命令使得改动立即生效
1 source /etc/profile
8.配置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
9.启动php-fpm
/etc/init.d/php-fpm start