将PHP 7.0升级至7.1
参考)在MacOSX上,可以使用brew install php命令将版本升级到7.1。
链接:http://qiita.com/bohebohechan/items/720cc0f830f3222bf99d
大致步骤
由于之前已经通过brew安装了PHP7.0,所以这次不需要添加存储库。
-
brew update
brew upgrade
brew search php ※いちおうあるか確認しておく
brew unlink php70
brew install php71
以中文为母语的方式进行再表述:进行安装。
$ brew install php71
==> Installing php71 from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php71-7.1.6_18.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring php71-7.1.6_18.yosemite.bottle.tar.gz
==> Caveats
The php.ini file can be found in:
/usr/local/etc/php/7.1/php.ini
✩✩✩✩ Extensions ✩✩✩✩
If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
PATH="/usr/local/bin:$PATH"
PHP71 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP.
✩✩✩✩ PHP CLI ✩✩✩✩
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file:
export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"
✩✩✩✩ FPM ✩✩✩✩
To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
The control script is located at /usr/local/opt/php71/sbin/php71-fpm
OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
PATH="/usr/local/sbin:$PATH"
You may also need to edit the plist to use the correct "UserName".
Please note that the plist was called 'homebrew-php.josegonzalez.php71.plist' in old versions of this formula.
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-httpd24 option. See brew options php71 for more details.
To have launchd start homebrew/php/php71 now and restart at login:
brew services start homebrew/php/php71
==> Summary
? /usr/local/Cellar/php71/7.1.6_18: 349 files, 40MB
顺便说一句,在我搜索 php 时,也找到了 php72,但因为它仍处于α版阶段,所以我决定不安装它。
确认 (què
嗯,我觉得应该没有无法安装的问题。
$ php -v
PHP 7.1.6 (cli) (built: Jun 23 2017 08:41:51) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
好的。没问题。
我在一个使用以下框架的个人现有项目中进行了轻量级的操作确认,没有遇到任何问题。
-
CodeIgniter 4dev
CodeIgniter 2.x (フレームワークのコアは昨年PHP7.0最適化済み)
随后
去年安装了PHP7.0之后,我忘记了如何修改php.ini文件和安装了哪些扩展模块,所以可能不需要,不过还是要确认一下。
PHP配置文件差异化
$ diff /usr/local/etc/php/7.1/php.ini /usr/local/etc/php/7.0/php.ini
146c146
< ; session.sid_bits_per_character
---
> ; session.hash_bits_per_character
160a161,165
> ; url_rewriter.tags
> ; Default Value: "a=href,area=href,frame=src,form=,fieldset="
> ; Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> ; Production Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
>
242,258d246
< ; URL rewriter function rewrites URL on the fly by using
< ; output buffer. You can set target tags by this configuration.
< ; "form" tag is special tag. It will add hidden input tag to pass values.
< ; Refer to session.trans_sid_tags for usage.
< ; Default Value: "form="
< ; Development Value: "form="
< ; Production Value: "form="
< ;url_rewriter.tags
<
< ; URL rewriter will not rewrites absolute URL nor form by default. To enable
< ; absolute URL rewrite, allowed hosts must be defined at RUNTIME.
< ; Refer to session.trans_sid_hosts for more details.
< ; Default Value: ""
< ; Development Value: ""
< ; Production Value: ""
< ;url_rewriter.hosts
<
300,303c288
< ; The value is also used for json_encode when encoding double values.
< ; If -1 is used, then dtoa mode 0 is used which automatically select the best
< ; precision.
< serialize_precision = -1
---
> serialize_precision = 17
341c326
< ;realpath_cache_size = 4096k
---
> ;realpath_cache_size = 16k
703a689
> ; mbstring or iconv output handler is used.
777,781d762
< ; if cgi.discard_path is enabled, the PHP CGI binary can safely be placed outside
< ; of the web tree and people will not be able to circumvent .htaccess security.
< ; http://php.net/cgi.dicard-path
< ;cgi.discard_path=1
<
802,808d782
< ; cgi.check_shebang_line controls whether CGI PHP checks for line starting with #!
< ; (shebang) at the top of the running script. This line might be needed if the
< ; script support running both as stand-alone script and via PHP CGI<. PHP in CGI
< ; mode skips this line and ignores its content if this directive is turned on.
< ; http://php.net/cgi.check-shebang-line
< ;cgi.check_shebang_line=1
<
895d868
< ;extension=php_ftp.dll
1202,1214d1174
< ; Records communication from all extensions using mysqlnd to the specified log
< ; file.
< ; http://php.net/mysqlnd.debug
< ;mysqlnd.debug =
<
< ; Defines which queries will be logged.
< ; http://php.net/mysqlnd.log_mask
< ;mysqlnd.log_mask = 0
<
< ; Default size of the mysqlnd memory pool, which is used by result sets.
< ; http://php.net/mysqlnd.mempool_default_size
< ;mysqlnd.mempool_default_size = 16000
<
1224,1232d1183
< ; Timeout for network requests in seconds.
< ; http://php.net/mysqlnd.net_read_timeout
< ;mysqlnd.net_read_timeout = 31536000
<
< ; SHA-256 Authentication Plugin related. File with the MySQL server public RSA
< ; key.
< ; http://php.net/mysqlnd.sha256_server_public_key
< ;mysqlnd.sha256_server_public_key =
<
1451a1403,1415
> ; How many bytes to read from the file.
> ; http://php.net/session.entropy-length
> ;session.entropy_length = 32
>
> ; Specified here to create the session id.
> ; http://php.net/session.entropy-file
> ; Defaults to /dev/urandom
> ; On systems that don't have /dev/urandom but do have /dev/arandom, this will default to /dev/arandom
> ; If neither are found at compile time, the default is no entropy file.
> ; On windows, setting the entropy_length setting will activate the
> ; Windows random source (using the CryptoAPI)
> ;session.entropy_file = /dev/urandom
>
1473,1505c1437,1445
< ; Set session ID character length. This value could be between 22 to 256.
< ; Shorter length than default is supported only for compatibility reason.
< ; Users should use 32 or more chars.
< ; http://php.net/session.sid-length
< ; Default Value: 32
< ; Development Value: 26
< ; Production Value: 26
< session.sid_length = 26
<
< ; The URL rewriter will look for URLs in a defined set of HTML tags.
< ; <form> is special; if you include them here, the rewriter will
< ; add a hidden <input> field with the info which is otherwise appended
< ; to URLs. <form> tag's action attribute URL will not be modified
< ; unless it is specified.
< ; Note that all valid entries require a "=", even if no value follows.
< ; Default Value: "a=href,area=href,frame=src,form="
< ; Development Value: "a=href,area=href,frame=src,form="
< ; Production Value: "a=href,area=href,frame=src,form="
< ; http://php.net/url-rewriter.tags
< session.trans_sid_tags = "a=href,area=href,frame=src,form="
<
< ; URL rewriter does not rewrite absolute URLs by default.
< ; To enable rewrites for absolute pathes, target hosts must be specified
< ; at RUNTIME. i.e. use ini_set()
< ; <form> tags is special. PHP will check action attribute's URL regardless
< ; of session.trans_sid_tags setting.
< ; If no host is defined, HTTP_HOST will be used for allowed host.
< ; Example value: php.net,www.php.net,wiki.php.net
< ; Use "," for multiple hosts. No spaces are allowed.
< ; Default Value: ""
< ; Development Value: ""
< ; Production Value: ""
< ;session.trans_sid_hosts=""
---
> ; Select a hash function for use in generating session ids.
> ; Possible Values
> ; 0 (MD5 128 bits)
> ; 1 (SHA-1 160 bits)
> ; This option may also be set to the name of any hash function supported by
> ; the hash extension. A list of available hashes is returned by the hash_algos()
> ; function.
> ; http://php.net/session.hash-function
> session.hash_function = 0
1517c1457,1468
< session.sid_bits_per_character = 5
---
> session.hash_bits_per_character = 5
>
> ; The URL rewriter will look for URLs in a defined set of HTML tags.
> ; form/fieldset are special; if you include them here, the rewriter will
> ; add a hidden <input> field with the info which is otherwise appended
> ; to URLs. If you want XHTML conformity, remove the form entry.
> ; Note that all valid entries require a "=", even if no value follows.
> ; Default Value: "a=href,area=href,frame=src,form=,fieldset="
> ; Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> ; Production Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> ; http://php.net/url-rewriter.tags
> url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
1704c1655
< ;gd.jpeg_ignore_warning = 1
---
> ;gd.jpeg_ignore_warning = 0
1782c1733
< ;opcache.enable=1
---
> ;opcache.enable=0
1785c1736
< ;opcache.enable_cli=1
---
> ;opcache.enable_cli=0
1788c1739
< ;opcache.memory_consumption=128
---
> ;opcache.memory_consumption=64
1791c1742
< ;opcache.interned_strings_buffer=8
---
> ;opcache.interned_strings_buffer=4
1794,1795c1745,1746
< ; Only numbers between 200 and 1000000 are allowed.
< ;opcache.max_accelerated_files=10000
---
> ; Only numbers between 200 and 100000 are allowed.
> ;opcache.max_accelerated_files=2000
1823d1773
< ; Depending on the used Memory Manager this may cause some incompatibilities.
1893,1897d1842
< ; Implies opcache.file_cache_only=1 for a certain process that failed to
< ; reattach to the shared memory (for Windows only). Explicitly enabled file
< ; cache is required.
< ;opcache.file_cache_fallback=1
<
1902,1907d1846
< ; Validate cached file permissions.
< ;opcache.validate_permission=0
<
< ; Prevent name collisions in chroot'ed environment.
< ;opcache.validate_root=0
<
$ diff /usr/local/etc/php/7.1/php.ini /usr/local/etc/php/7.0/php.ini
146c146
< ; session.sid_bits_per_character
---
> ; session.hash_bits_per_character
160a161,165
> ; url_rewriter.tags
> ; Default Value: "a=href,area=href,frame=src,form=,fieldset="
> ; Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> ; Production Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
>
242,258d246
< ; URL rewriter function rewrites URL on the fly by using
< ; output buffer. You can set target tags by this configuration.
< ; "form" tag is special tag. It will add hidden input tag to pass values.
< ; Refer to session.trans_sid_tags for usage.
< ; Default Value: "form="
< ; Development Value: "form="
< ; Production Value: "form="
< ;url_rewriter.tags
<
< ; URL rewriter will not rewrites absolute URL nor form by default. To enable
< ; absolute URL rewrite, allowed hosts must be defined at RUNTIME.
< ; Refer to session.trans_sid_hosts for more details.
< ; Default Value: ""
< ; Development Value: ""
< ; Production Value: ""
< ;url_rewriter.hosts
<
300,303c288
< ; The value is also used for json_encode when encoding double values.
< ; If -1 is used, then dtoa mode 0 is used which automatically select the best
< ; precision.
< serialize_precision = -1
---
> serialize_precision = 17
341c326
< ;realpath_cache_size = 4096k
---
> ;realpath_cache_size = 16k
703a689
> ; mbstring or iconv output handler is used.
777,781d762
< ; if cgi.discard_path is enabled, the PHP CGI binary can safely be placed outside
< ; of the web tree and people will not be able to circumvent .htaccess security.
< ; http://php.net/cgi.dicard-path
< ;cgi.discard_path=1
<
802,808d782
< ; cgi.check_shebang_line controls whether CGI PHP checks for line starting with #!
< ; (shebang) at the top of the running script. This line might be needed if the
< ; script support running both as stand-alone script and via PHP CGI<. PHP in CGI
< ; mode skips this line and ignores its content if this directive is turned on.
< ; http://php.net/cgi.check-shebang-line
< ;cgi.check_shebang_line=1
<
895d868
< ;extension=php_ftp.dll
1202,1214d1174
< ; Records communication from all extensions using mysqlnd to the specified log
< ; file.
< ; http://php.net/mysqlnd.debug
< ;mysqlnd.debug =
<
< ; Defines which queries will be logged.
< ; http://php.net/mysqlnd.log_mask
< ;mysqlnd.log_mask = 0
<
< ; Default size of the mysqlnd memory pool, which is used by result sets.
< ; http://php.net/mysqlnd.mempool_default_size
< ;mysqlnd.mempool_default_size = 16000
<
1224,1232d1183
< ; Timeout for network requests in seconds.
< ; http://php.net/mysqlnd.net_read_timeout
< ;mysqlnd.net_read_timeout = 31536000
<
< ; SHA-256 Authentication Plugin related. File with the MySQL server public RSA
< ; key.
< ; http://php.net/mysqlnd.sha256_server_public_key
< ;mysqlnd.sha256_server_public_key =
<
1451a1403,1415
> ; How many bytes to read from the file.
> ; http://php.net/session.entropy-length
> ;session.entropy_length = 32
>
> ; Specified here to create the session id.
> ; http://php.net/session.entropy-file
> ; Defaults to /dev/urandom
> ; On systems that don't have /dev/urandom but do have /dev/arandom, this will default to /dev/arandom
> ; If neither are found at compile time, the default is no entropy file.
> ; On windows, setting the entropy_length setting will activate the
> ; Windows random source (using the CryptoAPI)
> ;session.entropy_file = /dev/urandom
>
1473,1505c1437,1445
< ; Set session ID character length. This value could be between 22 to 256.
< ; Shorter length than default is supported only for compatibility reason.
< ; Users should use 32 or more chars.
< ; http://php.net/session.sid-length
< ; Default Value: 32
< ; Development Value: 26
< ; Production Value: 26
< session.sid_length = 26
<
< ; The URL rewriter will look for URLs in a defined set of HTML tags.
< ; <form> is special; if you include them here, the rewriter will
< ; add a hidden <input> field with the info which is otherwise appended
< ; to URLs. <form> tag's action attribute URL will not be modified
< ; unless it is specified.
< ; Note that all valid entries require a "=", even if no value follows.
< ; Default Value: "a=href,area=href,frame=src,form="
< ; Development Value: "a=href,area=href,frame=src,form="
< ; Production Value: "a=href,area=href,frame=src,form="
< ; http://php.net/url-rewriter.tags
< session.trans_sid_tags = "a=href,area=href,frame=src,form="
<
< ; URL rewriter does not rewrite absolute URLs by default.
< ; To enable rewrites for absolute pathes, target hosts must be specified
< ; at RUNTIME. i.e. use ini_set()
< ; <form> tags is special. PHP will check action attribute's URL regardless
< ; of session.trans_sid_tags setting.
< ; If no host is defined, HTTP_HOST will be used for allowed host.
< ; Example value: php.net,www.php.net,wiki.php.net
< ; Use "," for multiple hosts. No spaces are allowed.
< ; Default Value: ""
< ; Development Value: ""
< ; Production Value: ""
< ;session.trans_sid_hosts=""
---
> ; Select a hash function for use in generating session ids.
> ; Possible Values
> ; 0 (MD5 128 bits)
> ; 1 (SHA-1 160 bits)
> ; This option may also be set to the name of any hash function supported by
> ; the hash extension. A list of available hashes is returned by the hash_algos()
> ; function.
> ; http://php.net/session.hash-function
> session.hash_function = 0
1517c1457,1468
< session.sid_bits_per_character = 5
---
> session.hash_bits_per_character = 5
>
> ; The URL rewriter will look for URLs in a defined set of HTML tags.
> ; form/fieldset are special; if you include them here, the rewriter will
> ; add a hidden <input> field with the info which is otherwise appended
> ; to URLs. If you want XHTML conformity, remove the form entry.
> ; Note that all valid entries require a "=", even if no value follows.
> ; Default Value: "a=href,area=href,frame=src,form=,fieldset="
> ; Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> ; Production Value: "a=href,area=href,frame=src,input=src,form=fakeentry"
> ; http://php.net/url-rewriter.tags
> url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
1704c1655
< ;gd.jpeg_ignore_warning = 1
---
> ;gd.jpeg_ignore_warning = 0
1782c1733
< ;opcache.enable=1
---
> ;opcache.enable=0
1785c1736
< ;opcache.enable_cli=1
---
> ;opcache.enable_cli=0
1788c1739
< ;opcache.memory_consumption=128
---
> ;opcache.memory_consumption=64
1791c1742
< ;opcache.interned_strings_buffer=8
---
> ;opcache.interned_strings_buffer=4
1794,1795c1745,1746
< ; Only numbers between 200 and 1000000 are allowed.
< ;opcache.max_accelerated_files=10000
---
> ; Only numbers between 200 and 100000 are allowed.
> ;opcache.max_accelerated_files=2000
1823d1773
< ; Depending on the used Memory Manager this may cause some incompatibilities.
1893,1897d1842
< ; Implies opcache.file_cache_only=1 for a certain process that failed to
< ; reattach to the shared memory (for Windows only). Explicitly enabled file
< ; cache is required.
< ;opcache.file_cache_fallback=1
<
1902,1907d1846
< ; Validate cached file permissions.
< ;opcache.validate_permission=0
<
< ; Prevent name collisions in chroot'ed environment.
< ;opcache.validate_root=0
<
有些项目似乎没有特别进行修改。
opcache的启用/禁用设置发生了变化,但是我不记得PHP7.0最初是禁用的还是我自己禁用的。(也没有查过)
暂时来说,我刚刚才意识到我没有正确设置时区…
;date.timezone =
扩展模块
我查看了 PHP 7.0 的扩展模块,但只安装了 Apache 模块。(虽然我记得还安装了其他模块…)
$ tree /usr/local/Cellar/php70/7.0.7/libexec/
/usr/local/Cellar/php70/7.0.7/libexec/
└── apache2
└── libphp7.so
在本地开发时,我使用内置服务器,因此 apache 模块只在需要时安装。