centos7下lnmp开发环境composer 安装yii2个人总结

第一步安装composer(如果您已安装可以忽略直接第二部)

用curl 下载下来composer.phar

curl -sS https://getcomposer.org/installer | php

mv composer.phar /usr/local/bin/composer (‘/usr/local/bin’此目录系统全局加载)

切换到/usr/local/bin 执行 composer self-update 更新composer

第二步

首先执行

[root@localhost code]# composer global require “fxp/composer-asset-plugin:1.0.0″
Changed current directory to /root/.composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
– Installing fxp/composer-asset-plugin (v1.0.0)
Downloading: 100%
Writing lock file    Generating autoload files

再执行
[root@localhost code]# composer create-project yiisoft/yii2-app-advanced yii 2.0.6
Installing yiisoft/yii2-app-advanced (2.0.6)
– Installing yiisoft/yii2-app-advanced (2.0.6)
Downloading: 100%

Created project in yii
Loading composer repositories with package information
Installing dependencies (including require-dev)

Reading bower.json of bower-asset/jquery (1.11.3)
Could not fetch
https://api.github.com/repos/jquery/jquery/contents/bower.json?ref=0d5ec2d8ac94a419ee47a39319c43ff9a7326b50, please create a GitHub OAuth token to go over the API rate limit
Head to https://github.com/settings/tokens/new?scopes
You can also add it manually later by using “composer config github-oauth.github.com <token>” Reading bower.json of bower-asset/jquery.inputmask (3.1.50)
Could not fetch https://api.github.com/repos/RobinHerbots/jquery.inputmask/contents/bower.json?ref=f44d5deec804c72fe85da31819b18bdcdad26f65, please create a GitHub OAuth token to go over the API rate limit
Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+dev.poc.ren+2015-08-09+2246
to retrieve a token. It will be stored in “/root/.composer/auth.json” for future use by Composer.
Token (hidden):
Token stored successfully. Reading bower.json of bower-asset/jquery.inputmask (3.1.35)(此处很慢,耐心等待)
– Installing yiisoft/yii2-composer (2.0.3)
Downloading: 100%

– Installing ezyang/htmlpurifier (v4.6.0)
Downloading: 100%

– Installing cebe/markdown (1.1.0)
Downloading: 100%

– Installing bower-asset/jquery (2.1.4)
Downloading: 100%

– Installing bower-asset/jquery.inputmask (3.1.50)
Downloading: 100%

– Installing bower-asset/punycode (v1.3.2)
Downloading: 100%

– Installing bower-asset/yii2-pjax (v2.0.4)
Downloading: 100%

– Installing yiisoft/yii2 (2.0.6)
Downloading: 100%

– Installing swiftmailer/swiftmailer (v5.4.1)
Loading from cache

– Installing yiisoft/yii2-swiftmailer (2.0.4)
Downloading: 100%

– Installing yiisoft/yii2-codeception (2.0.4)
Downloading: 100%

– Installing bower-asset/bootstrap (v3.3.5)
Downloading: 100%

– Installing yiisoft/yii2-bootstrap (2.0.4)
Downloading: 100%

– Installing yiisoft/yii2-debug (2.0.5)
Downloading: 100%

– Installing bower-asset/typeahead.js (v0.10.5)
Downloading: 100%

– Installing phpspec/php-diff (v1.0.2)
Loading from cache

– Installing yiisoft/yii2-gii (2.0.4)
Downloading: 100%

– Installing fzaninotto/faker (v1.5.0)
Loading from cache

– Installing yiisoft/yii2-faker (2.0.3)
Downloading: 100%

fzaninotto/faker suggests installing ext-intl (*)
Writing lock file
Generating autoload files

注意:在安装过程中 Composer 可能会询问你 GitHub 账户的登录信息,因为可能在使用中超过了 GitHub API (对匿名用户的)使用限制。因为 Composer 需要为所有扩展包从 GitHub 中获取大量信息,所以超限非常正常。(译注:也意味着作为程序猿没有 GitHub 账号,就真不能愉快地玩耍了)登陆 GitHub 之后可以得到更高的 API 限额,这样 Composer 才能正常运行。更多细节请参考 Composer 文档(该段 Composer 中文文档期待您的参与)。

第三步 初始化 配置nginx站点

推荐使用的 Nginx 配置

为了使用 Nginx,你应该已经将 PHP 安装为 FPM SAPI 了。使用如下 Nginx 配置,将 path/to/basic/web 替换为实际的 basic/web 目录,mysite.local 替换为实际的主机名以提供服务。

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## 监听 ipv4 上的 80 端口
    #listen [::]:80 default_server ipv6only=on; ## 监听 ipv6 上的 80 端口

    server_name mysite.local;
    root        /path/to/basic/web;
    index       index.php;

    access_log  /path/to/basic/log/access.log main;
    error_log   /path/to/basic/log/error.log;

    location / {
        # 如果找不到真实存在的文件,把请求分发至 index.php
        try_files $uri $uri/ /index.php?$args;
    }

    # 若取消下面这段的注释,可避免 Yii 接管不存在文件的处理过程(404)
    #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.conf;
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        try_files $uri =404;
    }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}

使用该配置时,你还应该在 php.ini 文件中设置 cgi.fix_pathinfo=0 ,能避免掉很多不必要的 stat() 系统调用。

还要注意当运行一个 HTTPS 服务器时,需要添加 fastcgi_param HTTPS on; 一行,这样 Yii 才能正确地判断连接是否安全。

第四步 初始化框架(由于网速不稳定,web里面没有自动生成index.php所以我们得自己手动初始化)

切换到 项目目录 ,执行以下php init

[root@localhost yii]# php init
Yii Application Initialization Tool v1.0

Which environment do you want the application to be initialized in?

[0] Development
[1] Production

Your choice [0-1, or “q” to quit] 0

Initialize the application under ‘Development’ environment? [yes|no] yes

Start initialization …

generate backend/config/main-local.php
generate backend/config/params-local.php
generate backend/web/index-test.php
generate backend/web/index.php
generate common/config/main-local.php
generate common/config/params-local.php
generate console/config/main-local.php
generate console/config/params-local.php
generate frontend/config/main-local.php
generate frontend/config/params-local.php
generate frontend/web/index-test.php
generate frontend/web/index.php
generate yii
generate cookie validation key in backend/config/main-local.php
generate cookie validation key in frontend/config/main-local.php
chmod 0777 backend/runtime
chmod 0777 backend/web/assets
chmod 0777 frontend/runtime
chmod 0777 frontend/web/assets
chmod 0755 yii
chmod 0755 tests/codeception/bin/yii

… initialization completed.

[root@localhost yii]#

第五步 修改hosts文件(此处省略)

0 Comments
Leave a Reply