Yii Learning (1)--Installation Configuration _php Tutorial

Source: Internet
Author: User
Tags php framework contact form
Before the Sina Blog wrote Yii article, came to blog after the garden, did not write about Yii article, just the Dragon Boat Festival holiday No matter, combined with the previous blog, Yii official documents, coupled with the recent summary of the harvest of Yii, write a series ~ ~

Yii is a high-performance, component-based PHP framework for developing large Web applications. Yii is written in strict OOP, with well-established library references and comprehensive tutorials. From mvc,dao/activerecord,widgets,caching, hierarchical Rbac,web services, to theming, i18n and l10n,yii provide almost everything you need for today's Web 2.0 application development. In fact, Yii is one of the most efficient PHP frameworks. Yii is a high-performance PHP5 Web application Development framework. With a simple command-line tool, YIIC can quickly create a code framework for a Web application, and developers can add business logic based on the generated code framework to quickly complete application development.

Installing Yii

Before installing YII, you must configure your development environment, such as a Web server that supports more than PHP5.1.0 versions. Yii has passed the Apache Web server test on Windows and Linux operating systems. It may also run on other platforms that support the PHP5 Web server, which publishes a lot of free resources on the Internet, and you may get a well-configured PHP5 Web server environment. Here we will throw away the installation of the Web server and PHP5. The installation of Yii is actually very simple and requires only two steps:
    • Download the Yii framework from http://www.yiiframework.com/download file to the directory accessible by the Web server.
    • After the installation is complete, it is recommended that you check that the current server has met all of Yii's requirements.
Fortunately, it's easy to do this, and Yii comes with a simple check tool. To invoke it, type: http://yourhostname/path/to/yii/requirements/index.php in the address bar of your browser and the configuration of your server will be shown below. Use the Check tool to determine that the server is not installing and using extensions or components, but it only gives a recommendation to ensure that the installation can be determined. As you can see, the results of the tests below are not all Passed (passed), and some show warning (warning). Of course, your configuration may be slightly different, so your display results will vary. In fact, the following details are not necessary to pass all. But part is also necessary, according to conclusion (conclusion) of the content of this paragraph: your server configuration satisfies the minimum requirements of yii. (Your server configuration satisfies the minimum requirements by YII.)

To create a new application

    • The installation location of Yii is what you already know.
    • Webroot is the root directory of your Web server configuration
    • From your command line, go to the framework directory and do the following:
  % CD webroot/testdrive/framework  Yiic webapp. /.. /testdrive  '/webroot/testdrive'? [yes| No]  Yes         mkdir /webroot/testdrive         mkdir /webroot/testdrive/  Assets         mkdir /webroot/testdrive/css         generate CSS/bg.gif         Generate CSS/form.css         generate CSS/main.css

Your app has been successfully created under/webroot/demo. The purpose of this WebApp command is to create a new Yii application. It only needs to specify a parameter, either absolute or relative, to create the application. The directories and files it generates are just a skeleton of the application.

testdrive/index.php Web App Portal script file index-test.php The entry script file used by the functional test assets/contains the exposed resource file CSS/contains CSS files images/contains picture files themes/includes app theme protected/contains protected application files YIIC YIIC command-line script yiic.bat YIIC command-line script under Windows yiic.php YIIC Command-line PHP script commands/Includes a custom'YIIC'Command Shell/Includes a custom'YIIC Shell'Order Components/contains reusable user components controller.php the base class of all controller classes identity.php used for authentication'Identity'class Config/contains configuration files console.php Console app configuration main.php Web app configuration test.php Configuration controllers used by functional testing/class file that contains the controller sitecontroller.php the default controller's classes file data/contains sample database schema.mysql.sql example MySQL database schema.sqlite.sql example SQLite database t Estdrive.db Sample SQLite Database file extensions/contains third-party extensions messages/contains translated messages models/class file that contains the model loginform.php'Login'Action Form Model contactform.php' Contact'form model Runtime for actions/contains files that are temporarily generated tests/include test script views/view and layout files that contain controllers layouts/contains layout view files main.php The default layout for all views column1.php use the layout column2 used by single-column pages. PHP uses a two-column page for layout site/include'site'view files for controller pages/include"Static"page about.php" About"view of the page contact.php' Contact'view of the action error.php'Error'view of the action (show external error) index.php'Index'view of the actionLogin. php'Login'View system for actions/Include system View file

Instead of writing a single line of code, we can access the following URL in our browser to see our first YII application:

http://hostname/testdrive/index.php

We will see that this app contains three pages: Home page, contact page, landing page. Home Show some information about the application and user login status, the contact page displays a contact form for users to fill out and submit their inquiries, and the login page allows the user to authenticate and then access the authorized content.

Configuration

In this app, there's index.php in the URL of that page, and if you want to get rid of it, what to do.

1. Open the Apache mod_rewrite module and remove the "#" symbol before the LoadModule rewrite_module modules/mod_rewrite.so to ensure There is "allowoverride all" in the. 2. Add the code in the/protected/config/main.php in the project:
' components ' = =array(           ...           ') Urlmanager ' = =array(                 ' urlformat ' = ' path ',                 ' showscriptname ' =false ,// Note False do not enclose the                 ' rules ' = =array(                     ' sites ' = ') ' Site/index ',                 ),           ),           ...        ),

3. Configure the server, Yii can be configured under Apache and Nginx

1) Apache

Under the Apache server, Yii needs to configure the. htaccess file. Configured as follows

403 /\. *iffile%{request_filename}-%{request_filename}-d# otherwise Forward it to Index.phprewriterule. index.php

2) Nginx

Yii can use Nginx and PHP's FPM SAPI. Configured as follows

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 on127.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_pass127.0.0.1:9000;        Include Fastcgi_params;        Fastcgi_param script_filename $document _ROOT$FSN; #PATH_INFO and path_translated can is omitted, but RFC3875Specifies them forCGI 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; }}

Using the configuration above, you can set the cgi.fix_pathinfo=0 in PHP.ini , which avoids the many unnecessary stat () calls to the system.

Basic installation and configuration is here ~ ~

http://www.bkjia.com/PHPjc/778932.html www.bkjia.com true http://www.bkjia.com/PHPjc/778932.html techarticle before Sina Blog wrote Yii article, came to blog after the garden, did not write about Yii article, just the Dragon Boat Festival holiday No matter, combined with the previous blog, yii official documents, plus ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.