MAC利用brew命令安装PHP7环境的方法
最近几年一直在LNMP环境下进行开发,其中的PHP还是5.5版本,有点老旧,去年12月PHP7已经正式发布,新增了一些语法特性,最大的亮点是性能的提升,所以一直想升级到PHP7,由于时间关系一直拖到现在。到写本文为止PHP最新版本为:7.0.9的stable,所以稳定性上基本不用担心。
之前写的 MAC下安装LNMP环境 是用brew安装的,这次升级PHP7继续使用brew, 安装/升级软件很方便。
升级brew
brew update
配置
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
安装PHP7
brew install php70
遇到的问题
安装提示:
➜ ~ brew install php70
==> Installing php70 from homebrew/php
Error: Cannot install homebrew/php/php70 because conflicting formulae are installed.
php55: because different php versions install the same binaries.
Please `brew unlink php55` before continuing.
Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.
根据提示执行: brew unlink php55
继续安装: brew install php70
配置文件
安装好后生成的配置文件都在 /usr/local/etc/php/7.0 目录里,分别如下:
php.ini /usr/local/etc/php/7.0/php.ini
php-fpm.conf /usr/local/etc/php/7.0/php-fpm.conf
php, phpize, php-config ls /usr/local/opt/php70/bin
php-fpm /usr/local/opt/php70/sbin/php-fpm
加入开机启动
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
命令行配置
vim ~/.zshrc
将
export PATH="$(brew --prefix php55)/bin:$PATH"
替换为
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
alias php-fpm.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist"
alias php-fpm.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php5.plist"
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
修改为
alias php-fpm.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist"
alias php-fpm.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist"
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
重新加载配置文件
source ~/.zshrc
验证版本
PHP版本
➜ ~ /usr/local/opt/php70/bin/php -v
PHP 7.0.9 (cli) (built: Jul 21 2016 14:50:47) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
php-fpm版本
➜ ~ /usr/local/opt/php70/sbin/php-fpm -v
PHP 7.0.9 (fpm-fcgi) (built: Jul 21 2016 14:50:51)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
启动PHP-FPM
执行: php-fpm.start
检查是否启动成功:
➜ ~ ps aux|grep php-fpm
qloog 60380 0.2 0.0 2432792 604 s001 R+ 6:00PM 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn php-fpm
qloog 60378 0.0 0.0 2473348 620 ?? S 6:00PM 0:00.00 /usr/local/opt/php70/sbin/php-fpm --fpm-config /usr/local/etc/php/7.0/php-fpm.conf
qloog 60377 0.0 0.0 2473348 648 ?? S 6:00PM 0:00.00 /usr/local/opt/php70/sbin/php-fpm --fpm-config /usr/local/etc/php/7.0/php-fpm.conf
qloog 60372 0.0 0.0 2475396 7844 ?? S 6:00PM 0:00.03 /usr/local/opt/php70/sbin/php-fpm --fpm-config /usr/local/etc/php/7.0/php-fpm.conf
安装扩展
yaf
brew install php70-yaf
配置文件
/usr/local/etc/php/7.0/conf.d/ext-yaf.ini
memcached
brew install php70-memcached
配置文件
/usr/local/etc/php/7.0/conf.d/ext-memcached.ini
redis
brew install php70-redis
配置文件
/usr/local/etc/php/7.0/conf.d/ext-redis.ini
xdebug
brew install php70-xdebug
配置文件
/usr/local/etc/php/7.0/conf.d/ext-xdebug.ini
swoole
brew install php70-swoole
配置文件
/usr/local/etc/php/7.0/conf.d/ext-swoole.ini
更多扩展执行 brew install 扩展名 进行安装
在php5.3.9添加了max_input_vars函数它限制了提交数据的长度了,如果我们长度限制100而提交的数据为200那么就会只保存前面100个字符哦,下面来看看。公司运营的论坛被网络攻击,无奈没有很好的解决方法,就只有一个个的封IP地址,最终封了1600多个ip段,2个月后网络攻击逐步减少,担心会屏蔽正常用户,所以开始解封一批国内的字段的ip地址,论坛程序是discuz,由于discuz在禁止ip字段页面没有做分页功能,其导致1600多个字段同时读取在页面上。
问题来了,删除ip字段时程序不响应,在记录数1000条以上,不管是提交一条删除记录,还是全部删除记录,都是没效果的。
1000条记录下,删除功能失效
最终在discuz官方论坛管理员帮助下解决!
discuz官方
max_input_vars,指的是表达提交的数量,默认值为 1000。官方添加这个变量的目的是为了更好的保护服务器不受攻击。避免堵塞。
max_input_vars = 2000
实例代码:
max_execution_time = 30 ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
max_input_vars = 2000
重启php-fpm后,功能正常了。
无论是从 PECL 安装 php5-memcached 还是从 apt-get 命令安装,安装上的 memcached 模块都是不带有 igbinary 序列化组件支持的,由于 igbinary 有很大的性能优势,所以尽量使用 igbinary 作为 memcached 的序列化组件。
环境说明
操作系统:Ubuntu Server 14.04 64-bit
PHP:PHP 5.5.9
构建过程
首先,安装 PHP 开发版
yuanyu@usvr:~$ sudo apt-get install php5-dev
然后安装依赖库
yuanyu@usvr:~$ sudo apt-get install libevent-dev
yuanyu@usvr:~$ sudo apt-get install pkg-config
接下来,安装 igbinary 模块
yuanyu@usvr:~$ sudo pecl install igbinary
从源码构建 libmemcached
获取 libmemcached 的源码,这里使用的是 1.0.18 版本
yuanyu@usvr:~$ cd tmp
yuanyu@usvr:~/tmp$ wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
解压缩,配置,并且进行构建
yuanyu@usvr:~/tmp$ tar xzvf libmemcached-1.0.18.tar.gz
yuanyu@usvr:~/tmp$ cd libmemcached-1.0.18
yuanyu@usvr:~/tmp/libmemcached-1.0.18$ ./configure
yuanyu@usvr:~/tmp/libmemcached-1.0.18$ make
yuanyu@usvr:~/tmp/libmemcached-1.0.18$ sudo make install
从源码构建 php5-memcached
使用 pecl 获取 php5-memcached 的源码,然后配置的时候启用 --enable-memcached-igbinary。
yuanyu@usvr:~/tmp$ pecl download memcached-2.2.0
yuanyu@usvr:~/tmp$ tar xzvf memcached-2.2.0.tgz
yuanyu@usvr:~/tmp$ cd memcached-2.2.0
yuanyu@usvr:~/tmp/memcached-2.2.0$ phpize
yuanyu@usvr:~/tmp/memcached-2.2.0$ ./configure --enable-memcached-igbinary --disable-memcached-sasl
yuanyu@usvr:~/tmp/memcached-2.2.0$ make
yuanyu@usvr:~/tmp/memcached-2.2.0$ sudo make install
配置 PHP,加入新构建的两个模块
上面的构建步骤完成之后,就会在 PHP 扩展模块产生 2 个 so 文件:igbinary.so 和 memcached.so,将这个两个文件配置到你的运行环境中即可。
下面我们来看一篇关于 安装php的parsekit扩展查看opcode的操作教程希望这篇文章能够对各位带来帮助,具体的如下。我们知道PHP是一门解释型语言,用它们编写的动态内容都需要依赖相应的解释器程序来运行,解释器程序需要对输入的脚本代码进行分析,便将它们生成可以直接运行的中间代码,也称为操作码(Operate Code,opcode)。
想要查看php程序的opcode,需要安装php的parsekit扩展。
安装过程如下:
[root@localhost ~]# wget http://pecl.php.net/get/parsekit-1.3.0.tgz
[root@localhost ~]# tar zxvf parsekit-1.3.0.tgz
[root@localhost ~]# cd parsekit-1.3.0
[root@localhost parsekit-1.3.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
[root@localhost parsekit-1.3.0]# ./configure -with-php-config=/usr/local/php/bin/php-config
[root@localhost parsekit-1.3.0]# make
[root@localhost parsekit-1.3.0]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
然后编辑php.ini文件,在里面加上
extension="parsekit.so"
[root@localhost parsekit-1.3.0]# vim /usr/local/php/etc/php.ini
这样我们就成功的安装了parsekit扩展了(注:楼主是在php5.2下安装的parsekit扩展,在php5.4,php5.5下会提示编译失败)。
当然还有一种更简单的安装parsekit的方法,那就是直接使用pecl。
在命令行下输入命令:
[root@localhost parsekit-1.3.0]# /usr/local/php/bin/pecl install parsekit
这样就可以自动帮你安装parsekit了。
然后,我们在命令行下输入:
[root@localhost parsekit-1.3.0]# /usr/local/php/bin/php -r "var_dump(parsekit_compile_string('print 1+1;'));"
这样就可以查看php代码的opcode了。
结果如下:
array(20) {
["type"]=>
int(4)
["type_name"]=>
string(14) "ZEND_EVAL_CODE"
["fn_flags"]=>
int(0)
["num_args"]=>
int(0)
["required_num_args"]=>
int(0)
["pass_rest_by_reference"]=>
bool(false)
["uses_this"]=>
bool(false)
["line_start"]=>
int(0)
["line_end"]=>
int(0)
["return_reference"]=>
bool(false)
["refcount"]=>
int(1)
["last"]=>
int(5)
["size"]=>
int(5)
["T"]=>
int(2)
["last_brk_cont"]=>
int(0)
["current_brk_cont"]=>
int(4294967295)
["backpatch_count"]=>
int(0)
["done_pass_two"]=>
bool(true)
["filename"]=>
string(17) "Parsekit Compiler"
["opcodes"]=>
array(5) {
[0]=>
array(8) {
["address"]=>
int(29981148)
["opcode"]=>
int(1)
["opcode_name"]=>
string(8) "ZEND_ADD"
["flags"]=>
int(197378)
["result"]=>
array(3) {
["type"]=>
int(2)
["type_name"]=>
string(10) "IS_TMP_VAR"
["var"]=>
int(0)
}
["op1"]=>
array(3) {
["type"]=>
int(1)
["type_name"]=>
string(8) "IS_CONST"
["constant"]=>
&int(1)
}
["op2"]=>
array(3) {
["type"]=>
int(1)
["type_name"]=>
string(8) "IS_CONST"
["constant"]=>
&int(1)
}
["lineno"]=>
int(1)
}
[1]=>
array(7) {
["address"]=>
int(29981268)
["opcode"]=>
int(41)
["opcode_name"]=>
string(10) "ZEND_PRINT"
["flags"]=>
int(770)
["result"]=>
array(3) {
["type"]=>
int(2)
["type_name"]=>
string(10) "IS_TMP_VAR"
["var"]=>
int(1)
}
["op1"]=>
array(3) {
["type"]=>
int(2)
["type_name"]=>
string(10) "IS_TMP_VAR"
["var"]=>
int(0)
}
["lineno"]=>
int(1)
}
[2]=>
array(7) {
["address"]=>
int(29981388)
["opcode"]=>
int(70)
["opcode_name"]=>
string(9) "ZEND_FREE"
["flags"]=>
int(271104)
["op1"]=>
array(4) {
["type"]=>
int(2)
["type_name"]=>
string(10) "IS_TMP_VAR"
["var"]=>
int(1)
["EA.type"]=>
int(0)
}
["op2"]=>
array(3) {
["type"]=>
int(8)
["type_name"]=>
string(9) "IS_UNUSED"
["opline_num"]=>
string(1) "0"
}
["lineno"]=>
int(1)
}
[3]=>
array(7) {
["address"]=>
int(29981508)
["opcode"]=>
int(62)
["opcode_name"]=>
string(11) "ZEND_RETURN"
["flags"]=>
int(16777984)
["op1"]=>
array(3) {
["type"]=>
int(1)
["type_name"]=>
string(8) "IS_CONST"
["constant"]=>
&NULL
}
["extended_value"]=>
int(0)
["lineno"]=>
int(1)
}
[4]=>
array(5) {
["address"]=>
int(29981628)
["opcode"]=>
int(149)
["opcode_name"]=>
string(21) "ZEND_HANDLE_EXCEPTION"
["flags"]=>
int(0)
["lineno"]=>
int(1)
}
}
}
相关文章
php 中file_get_contents超时问题的解决方法
file_get_contents超时我知道最多的原因就是你机器访问远程机器过慢,导致php脚本超时了,但也有其它很多原因,下面我来总结file_get_contents超时问题的解决方法总结。...2016-11-25- 相信很多站长都遇到过这样一个问题,访问页面时出现408错误,下面一聚教程网将为大家介绍408错误出现的原因以及408错误的解决办法。 HTTP 408错误出现原因: HTT...2017-01-22
- php如何实现抓取网页图片,相较于手动的粘贴复制,使用小程序要方便快捷多了,喜欢编程的人总会喜欢制作一些简单有用的小软件,最近就参考了网上一个php抓取图片代码,封装了一个php远程抓取图片的类,测试了一下,效果还不错分享...2015-10-30
- 下面我们来看一篇关于Android子控件超出父控件的范围显示出来方法,希望这篇文章能够帮助到各位朋友,有碰到此问题的朋友可以进来看看哦。 <RelativeLayout xmlns:an...2016-10-02
- ps软件是现在非常受大家喜欢的一款软件,有着非常不错的使用功能。这次文章就给大家介绍下ps把文字背景变透明的操作方法,喜欢的一起来看看。 1、使用Photoshop软件...2017-07-06
intellij idea快速查看当前类中的所有方法(推荐)
这篇文章主要介绍了intellij idea快速查看当前类中的所有方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-09-02- 1.在没有设置默认值的情况下: 复制代码 代码如下:SELECT userinfo.id, user_name, role, adm_regionid, region_name , create_timeFROM userinfoLEFT JOIN region ON userinfo.adm_regionid = region.id 结果:...2014-05-31
js导出table数据到excel即导出为EXCEL文档的方法
复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta ht...2013-10-13- 批量更新mysql更新语句很简单,更新一条数据的某个字段,一般这样写:复制代码 代码如下:UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_value';如果更新同一字段为同一个值,mysql也很简单,修改下where即...2013-10-04
- 本文涉及的主题虽然很基础,在许多人看来属于小伎俩,但在JavaScript基础知识中属于一个综合性的话题。这里会涉及到对象属性的封装、原型、构造函数、闭包以及立即执行表达式等知识。公有方法 公有方法就是能被外部访问...2015-11-08
- ps软件是一款非常不错的图片处理软件,有着非常不错的使用效果。这次文章要给大家介绍的是ps怎么制作倒影,一起来看看设计倒影的方法。 用ps怎么做倒影最终效果̳...2017-07-06
- 最近想自学PHP ,做了个验证码,但不知道怎么搞的,总出现一个如下图的小红叉,但验证码就是显示不出来,原因如下 未修改之前,出现如下错误; (1)修改步骤如下,原因如下,原因是apache权限没开, (2)点击打开php.int., 搜索extension=ph...2013-10-04
- 单个字符分割 string s="abcdeabcdeabcde"; string[] sArray=s.Split('c'); foreach(string i in sArray) Console.WriteLine(i.ToString()); 输出下面的结果: ab de...2020-06-25
安卓手机wifi打不开修复教程,安卓手机wifi打不开解决方法
手机wifi打不开?让小编来告诉你如何解决。还不知道的朋友快来看看。 手机wifi是现在生活中最常用的手机功能,但是遇到手机wifi打不开的情况该怎么办呢?如果手机wifi...2016-12-21使用percona-toolkit操作MySQL的实用命令小结
1.pt-archiver 功能介绍: 将mysql数据库中表的记录归档到另外一个表或者文件 用法介绍: pt-archiver [OPTION...] --source DSN --where WHERE 这个工具只是归档旧的数据,不会对线上数据的OLTP查询造成太大影响,你可以将...2015-11-24- javascript控制页面控件隐藏显示的两种方法,方法的不同之处在于控件隐藏后是否还在页面上占位 方法一: 复制代码 代码如下: document.all["panelsms"].style.visibility="hidden"; document.all["panelsms"].style.visi...2013-10-13
连接MySql速度慢的解决方法(skip-name-resolve)
最近在Linux服务器上安装MySql5后,本地使用客户端连MySql速度超慢,本地程序连接也超慢。 解决方法:在配置文件my.cnf的[mysqld]下加入skip-name-resolve。原因是默认安装的MySql开启了DNS的反向解析。如果禁用的话就不能...2015-10-21- 本篇文章是对C#方法进行了详细的总结与介绍,需要的朋友参考下...2020-06-25
- 步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
- grep命令是Linux系统中最重要的命令之一,功能是从文本文件或管道数据流中筛选匹配的行和数据,如果再配合正则表达式,功能十分强大,是Linux运维人员必备的命令,这篇文章主要介绍了Linux中grep详解,需要的朋友可以参考下...2023-02-15