个人还是更喜欢使用Ubuntu apt-get官方源更新的比较快 基本与php新版本同步 而在centos中官方源的php版本严重停滞 所以需要编译安装php 下面是安装流程
同时学习开发php扩展之前必须先学会php的编译安装,php扩展开发可以使得php使用c里面写的函数,和c++里定义的类,使得php更加强大
首先在php官网下载 php的源码包php国内官网
cd 进入源码包
—安装php的依赖包—
yum install epel-release //扩展包更新包
yum update //更新yum源
yum install libmcrypt libmcrypt-devel mcrypt mhash
yum install -y libxml2 libxml2-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel
—编译和安装—
./configure 帮你创建Makefile文件
./configure –prefix=/usr/local/php56 –with-config-file-path=/usr/local/php56/etc –enable-fpm –with-fpm-user=www –with-fpm-group=www –enable-mysqlnd –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –enable-opcache –enable-mbstring –enable-soap –enable-zip –enable-bcmath –with-openssl –with-zlib –with-curl –with-gd –with-zlib-dir=/usr/lib –with-png-dir=/usr/lib –with-jpeg-dir=/usr/lib –with-mhash –with-mcrypt
参数说明
“”” 安装路径 “””
–prefix=/usr/local/php56
“”” php.ini 配置文件路径 “””
–with-config-file-path=/usr/local/php56/etc
“”” 优化选项 “””
–enable-inline-optimization
–disable-debug
–disable-rpath
–enable-shared
“”” 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) “””
–enable-opcache
“”” FPM “””
–enable-fpm
–with-fpm-user=www
–with-fpm-group=www
“”” MySQL “””
–with-mysql=mysqlnd
–with-mysqli=mysqlnd
–with-pdo-mysql=mysqlnd
“”” 国际化与字符编码支持 “””
–with-gettext
–enable-mbstring
–with-iconv
“”” 加密扩展 “””
–with-mcrypt
–with-mhash
–with-openssl
“”” 数学扩展 “””
–enable-bcmath
“”” Web 服务,soap 依赖 libxml “””
–enable-soap
–with-libxml-dir
“”” 进程,信号及内存 “””
–enable-pcntl
–enable-shmop
–enable-sysvmsg
–enable-sysvsem
–enable-sysvshm
“”” socket & curl “””
–enable-sockets
–with-curl
“”” 压缩与归档 “””
–with-zlib
–enable-zip
–with-bz2
“”” GNU Readline 命令行快捷键绑定 “””
–with-readline
编译和安装
make && make install
配置 PHP
配置文件:
cp php.ini-development /usr/local/php/etc/php.ini
php-fpm 服务:
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
chmod +x /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
启动 php-fpm
service php-fpm start
Starting php-fpm done
添加 PHP 命令到环境变量
编辑 ~/.bash_profile,将:
PATH=$PATH:$HOME/bin
改为:
PATH=$PATH:$HOME/bin:/usr/local/php/bin
使 PHP 环境变量生效:
source .bash_profile
三,安装PHP扩展
生成redis.so:
复制代码
1 | unzip phpredis-Version |
复制代码
将extension=redis.so加入到php.ini
重启服务器,查看phpinfo();
如果是使用php-fpm,则需要重启php-fpm:
ps aux|grep php-fpm #查看fpm进程号
kill -USR2 fpm进程号 #平滑重启php-fpm