全部文章
安装 PHP 出现 cannot find -lltdl 错误
在编译 PHP 的过程中遇到这个错误:
/usr/bin/ld: cannot find -lltdl
collect2: error: ld returned 1 exit status
make: *** [sapi/fpm/php-fpm] Error 1
解决办法是:
yum install libtool-ltdl-devel
LNMP 环境下安装多个 PHP 版本(PHP7, PHP5)
因为还有不少的开源程序未兼容 PHP 7,所以在已有的 CentOS 7, PHP 7,MySQL 5.7 和 Nginx 1.8 环境下再安装 PHP 5. 关于 PHP 7 的安装,请参考:http://www.lnmp.cn/installing-php7-mysql57-nginx18-under-centos7.html
安装 PHP 5.6
PHP 5 和 PHP 7 的安装其实是大同小异。目前最新版本是 php-5.6.21。先下载源码:
[root@lnmp ~]# cd /usr/local/src
[root@lnmp src]# wget -c http://cn2.php.net/distributions/php-5.6.21.tar.gz
解压:
[root@lnmp src]# tar -zxvf php-5.6.21.tar.gz
configure. 其中安装路径为 /usr/local/php5:
[root@lnmp src]# cd php-5.6.21/
[root@lnmp p...
PHP 5.3 中用 mb_detect_encoding 检测字符串是否为 UTF-8 的问题
PHP 提供了 mb_detect_encoding 来检测字符串的编码。例如:
mb_detect_encoding('LNMP笔记', 'UTF-8', true);
将返回 UTF-8,如果不是UTF-8将返回false。不过这种判断并不是百分百的,例如 gbk 编码的 希腊 :
mb_detect_encoding(mb_convert_encoding('希腊', 'gbk', 'UTF-8'), 'UTF-8', true);
PHP 7 中返回 false
PHP 5.3 返回 UTF-8
貌似是PHP的bug,但在PHP7总已经修复。
在PHP 5.3可以用正则替代 mb_detect_encoding 检查字符串是否是 UTF-8:
preg_match('//u', mb_convert_encoding('希腊', 'gbk', 'UTF-...
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
打开网址出 404 File not found. 错误,但文件的确是存在的,找查nginx error log,发现这个
2016/05/12 00:01:01 [error] 24257#0: *166460 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 223.73.106.97, server: www.lnmp.cn, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.lnmp.cn"
这个是因为nginx配置文件中fastcgi_param没有设置对路径引起的,在nginx的 default.conf 配置文件中有这么一段:
#location ~ \.php$ {
&n...
Nginx 实现 HTTP 用户认证
当某些内容只想给某些特定的用户看到的话,HTTP 用户认证是一个很好的解决方法。下面是在 Nginx 实现 HTTP 用户认证方法。
用户密码信息要保存到一个文件中供 Nginx 调用,先创建一个文件夹保存这些文件
[root@lnmp lnmp.cn]# mkdir /etc/nginx/htpasswd
而这个文件通常可以用 Apache htpasswd 生成,但这里既然已经装了 Nginx,就不想再装 Apache 了,在没安装 Apache 的情况,可以通过如下命令通过 openssl 生成 htpasswd 文件:
[root@lnmp lnmp.cn]# printf "lnmp:$(openssl passwd -crypt lnmp.cn)\n" >> /etc/nginx/htpasswd/lnmp.cn
其中 lnmp 是用户名,lnmp.cn 是密码。其中密码有长度限制,最长8位,超过会被截断,并出现这个警告:
Warning: truncating password to 8 ch...
CentOS 7 下 PHP 7,MySQL 5.7 和 Nginx 1.8 的安装与配置
下面将一步步在 CentOS 7 下 PHP 7,MySQL 5.7 和 Nginx 1.8 的安装与配置。首先我的 CentOS 版本是7.0.1406
[root@lnmp ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.0.1406 (Core)
Release: 7.0.1406
Codename: Core
如果服务器是其他版本 CentOS,应该也是大同小异。下面首先安装 Nginx
Nginx 1.8 安装
这里将用 yum 来安装 Nginx。首先更新一下 yum repo, 以便可以安装到对应...