php5.5 yaml 安装,php linux yaml 的安装和使用、环境区分(测试、预发布、生产)

安装:

1 下载yaml包

wget http://pyyaml.org/download/libyaml/yaml-0.2.2.tar.gz

tar -zxvf yaml-0.2.2.tar.gz

cd yaml-0.2.2/

./configure

make

make install

2,下载php的yaml扩展包

点击官网下载:https://pecl.php.net/package/yaml

tar -zvxf yaml-2.0.4.tgz

cd yaml-2.0.4/

/usr/local/php7/bin/phpize //这里要改成你PHP的安装目录

./configure --with-php-config=/usr/local/php7/bin/php-config //这里也是一样

make

make install

php.ini 添加扩展yaml.so

vi /usr/local/php7/lib/php.ini //一样注意目录

extension=yaml.so

4 重启PHP-FPM

//数组转yaml

$yaml = yaml_emit($invoice);

// yaml转数组

$parsed = yaml_parse($yaml);

//读取yaml文件地址

$configFile = dev.yaml

$defaultConfig = yaml_parse_file($configFile);

5 设置环境变量,测试、预发布、灰度、生产

nginx配置

server {

charset utf-8;

client_max_body_size 128M;

listen 80; ## listen for ipv4

#listen [::]:80 default_server ipv6only=on; ## listen for ipv6

server_name domian.com;

root /opt/web;

index index.php;

#access_log /opt/log/access.log;

#error_log /opt/log/error.log;

location / {

# Redirect everything that isn't a real file to index.php

try_files $uri $uri/ /index.php$is_args$args;

}

# uncomment to avoid processing of calls to non-existing static files by Yii

#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {

# try_files $uri =404;

#}

#error_page 404 /404.html;

location ~ \.php$ {

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_pass 127.0.0.1:9000;

#fastcgi_pass unix:/var/run/php5-fpm.sock;

try_files $uri =404;

# Project params

fastcgi_param ENV_MOD DEVELOPMENT; # 开发环境

#fastcgi_param ENV_MOD TEST; # 测试环境

#fastcgi_param ENV_MOD PRODUCTION; # 生产环境

}

location ~ /\.(ht|svn|git) {

deny all;

}

}

Apache配置

ServerName domain.com

DocumentRoot "/opt/web/"

# use mod_rewrite for pretty URL support

RewriteEngine on

# If a directory or a file exists, use the request directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward the request to index.php

RewriteRule . index.php

# use index.php as index file

DirectoryIndex index.php

# ...other settings...

# 环境变量

SetEnv ENV_MOD DEVELOPMENT #开发环境

#SetEnv ENV_MOD TEST #测试环境

#SetEnv ENV_MOD PRODUCTION #生产环境

通过不同  环境变量,读取配置文件

public function getMode()

{

// 从 webserver 配置获取环境模式信息

$mode = getenv(self::ENV_NAME);

// 尝试从config/mode.php读取环境配置

if (empty($mode)) {

$modeFile = $this->_configDir . '/mode.php';

if (file_exists($modeFile)) {

$mode = file_get_contents($modeFile);

}

} else {

// 从配置文件获取环境模式信息

//todo

}

$mode = trim(strtoupper($mode));

return $mode;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值