Yii学习总结之安装配置(3)

1. 开启apache的mod_rewrite模块,去掉LoadModule rewrite_module modules/mod_rewrite.so前的"#"符号,确保<Directory "..."></Directory>中有"AllowOverride All"。
2. 在项目中的/protected/config/main.php中添加代码:

复制代码 代码如下:


'components'=>array(
           ...
           'urlManager'=>array(
                 'urlFormat'=>'path',
                 'showScriptName'=>false,//注意false不要用引号括上
                 'rules'=>array(
                     'sites'=>'site/index',
                 ),
           ),
           ...
       ),

3.配置服务器,Yii可以在Apache和Nginx下配置

1)Apache

在Apache服务器下,Yii需要配置.htaccess文件。配置如下

复制代码 代码如下:


RewriteEngine on
# prevent httpd from serving dotfiles (.htaccess, .svn, .git, etc.)
RedirectMatch 403 /\..*$
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php

2)Nginx

Yii可以使用Nginx和PHP的FPM SAPI。配置如下

复制代码 代码如下:


server {
    set $host_path "/www/mysite";
    access_log  /www/mysite/log/access.log  main;
    server_name  mysite;
    root   $host_path/htdocs;
    set $yii_bootstrap "index.php";
    charset utf-8;
    location / {
        index  index.html $yii_bootstrap;
        try_files $uri $uri/ /$yii_bootstrap?$args;
    }
    location ~ ^/(protected|framework|themes/\w+/views) {
        deny  all;
    }
    #avoid processing of calls to unexisting static files by yii
    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;
    }
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;
        #let yii catch the calls to unexising PHP files
        set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }
        fastcgi_pass   127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;
        #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
    }
    # prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.)
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
}

使用如上配置,你可以在php.ini中设置cgi.fix_pathinfo=0,这样可以避免许多不必要的系统的stat()调用。

基本安装和配置就到这里~~

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/720e38a0fcd773ce2c29fef82f3ad564.html