安装

下载最新稳定版本SF代码

下载最新版SF,把它解压到你服务器的目录上。

通过Git下载框架代码

git clone https://github.com/liemao/PHP-StarFramework

框架目录结构

+ public
  | - .htaccess // Rewrite rules
  | - index.php // Application entry
  | + static
      | + css
      | + js
      | + img
- application/
  - Bootstrap.php   // Bootstrap
  + configs
      | - application.ini // Configure 
  + controllers
     - IndexController.php // Default controller
  + layouts
     | + default
         - layout.phtml // layout
  + logs //Log
  + models //Model
  + services //Service
  + views    
      | + scripts
          |+ index   
            - index.phtml // View template for default controller
+ library
    | + Star //Star Framework

服务器环境要求

PHP最低版本: 5.2+

配置

SF初始添加环境变量,无需任何配置即可使用, SF支持Star_Config_Ini和Star_Config_Php两种适配器。环境变量初始值必须包含入口文件定义APPLICATION_ENV值,环境变量用来区分测试环境和线上环境配置。配置文件配好各个环境配置,可以直接修改入口文件APPLICATION_ENV值切换配置。

PHP配置

<?php
return array(
    "production" => array( //环境变量
        "bootstrap" => array( //bootstrap设置
            "path" => APPLICATION_PATH . "/Bootstrap.php", //bootstrap路径
        ),
        "resources" => array(
            "frontController" => array(
                "debug" => true, //是否打开debug模式
            ),
        ),
    ),
);
?>

INI配置

[production]
;bootstrap路径
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
;bootstrap类名
bootstrap.class = "Bootstrap" 

权限设置

SF日志目录是需要权限设置,application/logs目录需要设置为可写入权限。

WEB服务器

指定WEB根目录到sf_path/public目录,开启WEB服务器Rewrite模块。

apache配置

# 设置文档根目录为 “sf_path/public”
DocumentRoot "sf_path/public"
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule !\.(js|css|png|jpg|jpeg|gif|swf|ico|html|htm)$ index.php [NC,L]

nginx rewrite规则

server {
    listen 80;
    server_name  www.yoursf.com;

    location / {
        root   sf_path/public;
        index  index.php;
        if (!-e $request_filename) {
            rewrite ^/(.*)  /index.php/$1 last;
        }
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|swf|ico|html|htm)$ {
        break;
    }

    location ~ \.php$ {
        root           sf_path/public;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }
}

运行

安装完成后,你可以使用浏览器输入如下URL访问刚安装完毕的SF应用:

http://www.yoursf.com/

你将会看到SF影响缺省页面,恭喜您!开始基于SF构建应用程序之路。

No comments yet.

Leave a Reply