全部文章
CentOS 和 macOS 下安装 PHP 7 的 tidy 扩展
Tidy是HTML清理和修复的实用程序,它支持操作HTML、XHTML和XML文档。比如说用户通过所见即所得html编辑器提交的html内容,人为地做成一些 html tag 的不匹配,很容易地破坏了整个页面的html结构。例如
测试内容
<div>测试
这里没有 </div> 结束tag,整个页面的结构就被破坏。这时 tidy 就可以很好地派上用场,它既可以检查输入内容的html结构,又可以修复这些不合法的内容。也可以输出 pretty 的 html。当然这些都是后话了,先安装了 php 的 tidy 扩展再说吧。
首先是在 CentOS PHP 7.1.0 安装 tidy
老办法:pecl
[root@lnmp lnmp.cn]# pecl install tidy
pear/tidy requires PHP (version >= 4.3.0, version <= 6.0.0), installed version is 7.1.0
No valid packages fou...
从 PHP 7.2 升级到 PHP 7.3
PHP 7.3.0 版本在经过数个 Alpha,beta 和 rc 版本之后在2018年12月6日终于正式发布。其实早在12月4日 PHP 就已经把 7.3 的安装文件打包好上传了,只是在12月6日发公告。我也是第一时间升级了服务器的PHP,只是现在才有时间记录下。
当前服务器环境 CentOS 7.4
[root@lnmp lnmp.cn]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
当前 PHP 版本 7.2.12
...[root@lnmp lnmp.cn]# php -v
PHP 7.2.12 (cli) (built: Nov 9 2018 02:47:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Laravel 结合数据库做PHP单元测试,并且 migrate 和 seed 只做一次
做测试的时候难免要结合数据库来测试,为了不影响现有数据及保持测试数据的完整性,一般是每次测试的时候创建一个新的测试数据库,并把写好的测试数据导入。这里就要用到 Laravel 的 Migrations 和 Seeding,请参考:
https://laravel.com/docs/master/migrations
https://laravel.com/docs/master/seeding
Laravel 已经整合 PHPunit,我们要做的就是建好测试数据库及表,导入测试数据,写测试函数。这里为了测试方便,用 sqlite 代替 MySQL 做测试数据库,避免每次都要启动 MySQL 来测试的麻烦。
首先在 database 目录下创建一个 testing.database.sqlite 文件作为 sqlite 数据库文件
touch database/testing.database.sqlite
然后在 config/database.php 的 connections 中加入测试数据库
...
guzzle 6.2 在 PHP 7.2 下及升级到 6.3 遇到的问题
程序在 PHP 7.1 运行没有任何问题,但升级到 PHP 7.2 后,出现这个错误
[ErrorException]
count(): Parameter must be an array or an object that implements Countab...
从 PHP 7 升级到 PHP 7.2
在 PHP 7.1 发布差不多1年后,PHP 7.2 终于发布。本文是从 PHP 7.1.0 升级到 PHP 7.2.1,从 PHP 7 的其他版本升级到 PHP 7.2.1 也是大同小异。如果是新安装,请参考: http://www.lnmp.cn/installing-php7-mysql57-nginx18-under-centos7.html
我之前是把 PHP 7.1.0 安装在
/usr/local/php-7.1.0
为了方便以后升级,加了这个软链,链接到 php-7.1.0
/usr/local/php
使用到 PHP 路径的时候一般都是使用这条软链路径。
先下载 PHP 7.2.1 源码,我下载的源码都是统一放到 /usr/local/src
[root@lnmp lnmp.cn]# cd /usr/local/src
[root@lnmp src]# wget -c http://cn2.php.net/get/php-7.2.1.tar.gz/from/this/mi...
http 扩展已经加载,但 http 函数全部不可以用
pecl_http 已经安装好,并且成功加载,在 phpinfo() 中可以看到,但 http 函数全部不可用,提示未定义:
Fatal error: Uncaught Error: Call to undefined function http_get()
Fatal error: Uncaught Error: Call to undefined function http_parse_headers()
Fatal error: Uncaught Error: Call to undefined function http_parse_cookie()
这里首先要确认安装的 pecl_http 是什么版本,因为版本1及以下和版本2及以上是完全不同的两个api。
https://pecl.php.net/package/pecl_http
如果安装的是版本1,最新 1.7.6 那么如下函数是可用的
http://php.net/manual/fa/ref.http.php
但如果安装的是2以上版本,最新 3.1.0 ,那么以上的 ht...
pecl_http configure: error: please install and enable pecl/raphf
本文是在 PHP 7.1 下用 pecl 安装 HTTP 3.1,关于 HTTP 都有哪些具体功能请参考:
https://mdref.m6w6.name/http
我这里主要是想用其中解析cookie的一些函数。
[root@lnmp lnmp.cn]# pecl install pecl_http
中途有几个提示输入库路径的,默认留空回车就是。
然而安装并不成功,具体错误如下:
checking whether ext/raphf is enabled... no
configure: error: please install and enable pecl/raphf
ERROR: `/tmp/pear/temp/pecl_http/configure --with-php-config=/usr/local/php7/bin/php-config --with-http-zlib-dir=/usr --with-http-libcurl-dir=/usr --with-http-libevent-dir=/usr --with-...
PHP 7.1 安装 ssh2 扩展
最近的项目要将文件从一台服务器上传到另外一台。本想着搭建ftp服务器,但为了节省时间,没有去做,而直接想着使用 sftp 或 scp 上传。这里就要用到 ssh2 扩展,下面说下如何在 PHP 7.1 下安装 ssh2,因为安装过程不算很顺利。
首先要安装 libssh2 开发库,否则安装扩展的时候会出现这个错误:
checking for gawk... gawk
checking for ssh2 support... yes, shared
checking for ssh2 files in default path... not found
configure: error: The required libssh2 library was not found. You can obtain that package from http://sourceforge.net/projects/libssh2/
ERROR: `/tmp/pear/temp/ssh2/configure --with-php-config=/usr/local/...