Centos下Yum安装PHP5.5/5.6/7.0

经本人使用,通过这种方式安装的php会有一些扩展没有安装。

centos安装posix扩展(workerman需要使用此扩展):

yum install php-posix

安装intl扩展:

yum list | grep intl

找到适合自己版本的扩展进行安装即可,我安装的是56w这个版本的,这个你可能没有,需要安装webtatic源,请查看文章

https://blog.yeskn.com/archives/893.html

该文章的php部分讲到如何安装webtatic源。

默认的版本太低了,手动安装有一些麻烦,想采用Yum安装的可以使用下面的方案:

  1. 检查当前安装的PHP包

    yum list installed | grep php

如果有安装的PHP包,先删除他们:

yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64</pre>
  1. 如果想删除上面安装的包,重新安装:
    rpm -qa | grep webstatic
    rpm -e  上面搜索到的包
    
  2. 运行yum install

yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php55w-gd.x86_64 php55w-ldap.x86_64 php55w-mbstring.x86_64 php55w-mcrypt.x86_64 php55w-mysql.x86_64 php55w-pdo.x86_6

yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64

注:如果想升级到5.6把上面的55w换成56w就可以了。

yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64
  1. 安装PHP FPM
yum install php55w-fpm 
yum install php56w-fpm 
yum install php70w-fpm

注:如果想升级到5.6把上面的55w换成56w就可以了。

概念了解:CGI,FastCGI,PHP-CGI与PHP-FPM

本文转载自 简明现代魔法:http://www.nowamagic.net/librarys/veda/detail/1319/

CGI

CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上。

CGI可以用任何一种语言编写,只要这种语言具有标准输入、输出和环境变量。如php,perl,tcl等。

Continue reading "概念了解:CGI,FastCGI,PHP-CGI与PHP-FPM"

php文件操作

下面是一些常用函数和代码块,可以配合使用,比如一键删除某个目录下的文件,或者批量创建文件(对于需要创建缩略图的应用很有必要),或者读取文件内容,以及客户各种撩骚的要求:

basename(string  $filename)

返回filename此文件的文件名部分;


dirname(string  $filename)

返回filename此文件所在的绝对路径部分,不包括结尾’/’;


unlink(string $filename),rmdir()

删除文件,删除文件夹


file_get_contents(string $path)

返回由$path指定的文件内容,可以是网络地址,如file_get_contents('http://www.baidu/.com');


dir(string  $directory)

打开$directory指定的路径,并返回一个对象。这个对象包含三个方法:read() , rewind() 以及 close()
若成功,则该函数返回一个目录流,否则返回 false 以及一个 error。可以通过在函数名前加上 "@" 来隐藏 error 的输出。下面演示用这个函数遍历一个目录下面所有的文件和文件夹:


$dir = dir(“./images”);

while (($file = $dir->read()) !== false) {
    if ($file !== '.' and $file != '..') {
    echo 'file: ' . $file . "\n";
    }
}

$dir->close();

opendir() 

opendir() 函数打开一个目录句柄,可由 closedir()readdir()rewinddir() 使用。
若成功,则该函数返回一个目录流,否则返回 false 以及一个 error。可以通过在函数名前加上 "@" 来隐藏 error 的输出。实现的功能与dir()类似,不过dir()返回的是一个对象。

$dir = opendir(“images”);
while (($file = readdir($dir)) !== false)
{
    if ($file !== '.' and $file != '..') {
    echo “filename: ” . $file . "\n";
    }
}

closedir($dir);
?>