方法一:yum安装
1.添加源
rpm -Uvh https://centos7.iuscommunity.org/ius-release.rpm
2.yum上进行搜索php版本
yum search php7
3.yum安装(选择你要安装的版本)
yum install php70w
4.安装其他插件(选装)
这一步如果闲麻烦的话直接在上一步执行下面这条命令即可(提示有冲突的话按照提示过滤冲突即可)
yum install php70w* //意为安装全部插件
php70w php70w-opcache php70w-bcmath php70w-cli php70w-common php70w-dba php70w-devel php70w-embedded php70w-enchant php70w-fpm php70w-gd php70w-imap php70w-interbase php70w-intl php70w-ldap php70w-mbstring php70w-mcrypt php70w-mysql php70w-mysqlnd php70w-odbc php70w-opcache php70w-pdo php70w-pdo_dblib php70w-pear php70w-pecl-apcu php70w-pecl-imagick php70w-pecl-xdebug php70w-pgsql php70w-phpdbg php70w-process php70w-pspell php70w-recode php70w-snmp php70w-soap php70w-tidy php70w-xml php70w-xmlrpc
- 安装完毕,测试是否安装成功
php -v
6.要运行PHP网页,要启动php-fpm解释器
service php-fpm start
方法二:编译式安装
1.下载php版本安装包
wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror
2.解压包
tar -xvf php-7.1.1.tar.gz
3.进入php目录
cd php-7.1.1
4.安装依赖包
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
./configure \ --prefix=/usr/local/php \ --with-config-file-path=/etc \ --enable-fpm \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-soap \ --with-libxml-dir \ --with-xmlrpc \ --with-openssl \ --with-mcrypt \ --with-mhash \ --with-pcre-regex \ --with-sqlite3 \ --with-zlib \ --enable-bcmath \ --with-iconv \ --with-bz2 \ --enable-calendar \ --with-curl \ --with-cdb \ --enable-dom \ --enable-exif \ --enable-fileinfo \ --enable-filter \ --with-pcre-dir \ --enable-ftp \ --with-gd \ --with-openssl-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype-dir \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --with-gettext \ --with-gmp \ --with-mhash \ --enable-json \ --enable-mbstring \ --enable-mbregex \ --enable-mbregex-backtrack \ --with-libmbfl \ --with-onig \ --enable-pdo \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-zlib-dir \ --with-pdo-sqlite \ --with-readline \ --enable-session \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-wddx \ --with-libxml-dir \ --with-xsl \ --enable-zip \ --enable-mysqlnd-compression-support \ --with-pear \ --enable-opcache
6.正式安装
make && make install
7.配置环境变量
vi /etc/profile
在尾部添加
PATH=$PATH:/usr/local/php/bin export PATH
执行命令使得改动立即生效
source /etc/profile
8.配置php-fpm
cp php.ini-production /etc/php.ini cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm
9.启动php-fpm
/etc/init.d/php-fpm start
如果启动出现以下报错问题
Starting php-fpm [26-Nov-2017 12:14:22] ERROR: [pool www] cannot get uid for user 'nginx' [26-Nov-2017 12:14:22] ERROR: FPM initialization failed failed
添加用户nginx跟对应用户组即可
groupadd nginx useradd nginx -g nginx -s /sbin/nologin -M
卸载php
yum remove php
rpm -qa|grep php 列出所有的php相关的rpm包
rpm -e xxx --nodeps