> CentOS > CentOS教程 >

centos6.5安装php 7

创建用户和组

groupadd www

useradd -g www www

usermod -s /sbin/nologin www

 

安装组件

yum install -y libxml2 libxml2-devel libxml2-python curl curl-devel  libjpeg libjpeg-devel libpng libpng10 libpng10-devel libpng-devel freetype-devel libmcrypt libmcrypt-devel gd gd-devel

清理缓存

yum clean all

 

下载最新版本php-7.0.6

解压

tar zxvf php-7.0.6.tar.gz -C /usr/src/

cd /usr/src/php-7.0.6/

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc  \

--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \

--with-libxml-dir --enable-xml --enable-bcmath \

--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl \

--enable-mbregex  --enable-fpm  --enable-mbstring \

--with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash \

--enable-pcntl --enable-sockets \

--with-xmlrpc --enable-zip --enable-soap  --with-mysql-sock=/data/3306/mysqld.sock  \

--with-curl=/usr --with-gettext --with-iconv --enable-mysqlnd \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

安装

make

make install

 

++++++++++++++++++++++++++++++++++++++

重点讲一下,PHP7 正式移除了 mysql 扩展

使用mysqlnd驱动

如果继续使用老版本的编译方式

--with-mysql=/usr/local/mysql --enable-embedded-mysqli --with-mysqli=/usr/local/mysql/bin/mysql_config

在make的时候会报错

make: *** [ext/mysqli/mysqli_embedded.lo] Error 1

 

所以我更改为

--enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd

才可以编译成功

+++++++++++++++++++++++++++++++++++++++++

 

复制配置文件以及启动脚本

cp php.ini-production /usr/local/php/etc/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

cd /usr/local/php/etc/php-fpm.d

编辑配置文件

vi www.conf

修改用户和组为www

 

user = www

group = www

 

脚本设置权限,添加到开机自启动

chmod +x /etc/init.d/php-fpm

chkconfig --add php-fpm

chkconfig --level 2345 php-fpm on

启动php-fpm

/etc/init.d/php-fpm start

查看端口是否启动

netstat -anpt | grep php-fpm

 

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      25727/php-fpm




(责任编辑:IT)