FuelPHP 安装

fuelphp 安装

 

本章介绍如何在您的机器上安装 fuelphp 框架。 fuelphp 的安装非常简单和容易。您有两种方法可以创建 fuelphp 应用程序:

  • 第一种方法是使用名为 oil 的 fuelphp 工具进行命令行安装。
  • 第二种方法是基于 composer 的安装。 fuelphp 使用 composer 进行安装和包依赖,因此在继续该过程之前,请确保 composer 已安装在本地。

让我们在后续部分中逐一详细介绍每种方法。

 

系统要求

在开始安装之前,必须满足以下系统要求。

 

web 服务器(以下任一项)

  • wamp (windows)
  • 微软 iis (windows)
  • 灯 (linux)
  • mamp (macintosh)
  • xamp(多平台)
  • nginx(多平台)
  • php 内置开发网络服务器(多平台)

 

浏览器支持(以下任何一项)

  • ie(internet explorer 8+)
  • 火狐
  • 谷歌浏览器
  • safari

php 兼容性-php 5.3 或更高版本。要获得最大收益,请使用最新版本。

让我们在本教程中使用 php 的内置开发 web 服务器。内置的开发 web 服务器易于启动,并且足以了解 fuelphp web 应用程序的基础知识,而无需深入了解 web 服务器和配置领域的复杂性。

 

命令行安装

fuelphp 的命令行安装非常简单,最多需要五分钟。

 

安装油包

oil 是 fuelphp 框架提供的一个特殊包/命令,用于完成 fuelphp 应用程序开发所需的许多任务,包括安装、开发和测试应用程序。

要安装 oil 包,打开一个 shell 并运行以下命令:

sudo curl https://get.fuelphp.com/oil | sh

该命令使用curl来下载安装oil包。该命令将显示类似以下信息的结果,最后安装油包。

 % total    % received % xferd  average speed   time    time     time  current 
                                 dload  upload   total   spent    left  speed 
100   479  100   479    0     0    353      0  0:00:01  0:00:01--:--:--  353

 

创建新项目

要使用 oil 创建新项目,请使用以下命令:

oil create <project_name> </project_name>

让我们使用以下命令创建一个名为"helloworld"的新项目。

oil create helloworld

现在,您可以看到类似于以下内容的响应,并最终创建一个简单的 fuelphp 应用程序框架。

composer create-project fuel/fuel helloworld 
installing fuel/fuel (1.8.0.1) 
  -installing fuel/fuel (1.8.0.1) 
      loading from cache  
created project in helloworld  
loading composer repositories with package information 
updating dependencies (including require-dev) 
  -installing composer/installers (v1.3.0) 
      loading from cache
  -installing fuelphp/upload (2.0.6) 
      loading from cache  
  -installing michelf/php-markdown (1.4.0) 
      loading from cache  
  -installing psr/log (1.0.2) 
      loading from cache  
  -installing monolog/monolog (1.18.2) 
      loading from cache  
  -installing phpseclib/phpseclib (2.0.0) 
      loading from cache  
  -installing fuel/core (1.8.0.4) 
      loading from cache  
  -installing fuel/auth (1.8.0.4) 
      loading from cache  
  -installing fuel/email (1.8.0.4) 
      loading from cache  
  -installing fuel/oil (1.8.0.4) 
      loading from cache  
  -installing fuel/orm (1.8.0.1) 
      loading from cache  
  -installing fuel/parser (1.8.0.4) 
      loading from cache  
  -installing fuel/docs (1.8.0.4) 
      loading from cache
   ……………. 
   …………….  
   writing lock file
   generating autoload files 

 

油版

要测试 oil 是否可用并检查版本,请使用以下命令:

$ cd helloworld
$ php oil-v

上述命令产生以下结果:

fuel: 1.8 running in "development" mode

 

石油帮助命令

要获取 oil 的基本帮助文档,请使用以下命令:

$ php oil help

上面的命令将显示类似于以下结果的帮助文档:

usage: 
   php oil [cell|console|generate|package|refine|help|server|test]  
runtime options: 
  -f, [--force]    # overwrite files that already exist 
  -s, [--skip]     # skip files that already exist 
  -q, [--quiet]    # supress status output 
  -t, [--speak]    # speak errors in a robot voice  
description:   
   the 'oil' command can be used in several ways to facilitate quick development, help 
   with testing your application and for running tasks.  
environment: 
   if you want to specify a specific environment oil has to run in, overload the 
   environment variable on the commandline: fuel_env=staging php oil <commands> more information: 
   you can pass the parameter "help" to each of the defined command to get 
   information about that specific command: php oil package help  
documentation:   
   http://docs.fuelphp.com/packages/oil/intro.html    </commands>

到目前为止,您已经知道如何使用油安装 fuel。让我们在下一节中介绍基于 composer 的安装。

 

基于 composer 的安装

以下命令用于使用 composer 安装 fuelphp。

$ composer create-project fuel/fuel--prefer-dist.

 

git 存储库克隆

要将最新的开发版本安装为本地 git 存储库克隆,请使用以下命令。

$ composer create-project fuel/fuel:dev-1.9/develop--prefer-source.

 

运行应用程序

移动到项目目录 public 文件夹,使用以下命令使用生产服务器运行应用程序。

$ cd path/to/helloworld/public
$ php-s localhost:8080 index.php

它产生以下响应。

php 5.5.31 development server started at sun may 21 12:26:10 2017
listening on http://localhost:8080
document root is /users/workspace/php-fuel/helloworld/public
press ctrl-c to quit.

现在,请求 url, http://localhost:8080,它将产生以下结果。

 

结果

这是在开发环境中运行 fuelphp 应用程序的最简单方法。如果您在生产环境中以这种方式创建应用程序,您将面临安全问题。推荐的方法是设置虚拟主机配置。下一节将介绍 apache 网络服务器。

 

设置虚拟主机

这是访问 fuelphp 应用程序的更安全的方式。要设置虚拟主机,您需要将 apache 虚拟主机文件链接到您的应用程序。如果是内网应用,将系统主机文件 url 重定向到虚拟主机。

 

虚拟主机文件

打开虚拟主机并添加以下更改。

<virtualhost *:80=""> 
   servername hello.app 
   documentroot /path/to/public 
   setenv fuel_env “development”
   
   <directory path="" to="" public=""> 
      directoryindex index.php 
      allowoverride all 
      order allow,deny 
      allow from all 
   </directory> </virtualhost> 

 

系统主机文件

现在,使用以下命令向您的计算机添加主机条目。

sudo vi /etc/hosts

然后,将以下行添加到文件末尾。

127.0.0.1 hello.app

要使所有更改可用,请重新启动 apache 服务器并请求 url, http://hello.app。它生成 fuelphp 主页。

下一节:fuelphp 架构概述

fuelphp 教程

相关文章