Yii Learning Summary Installation Configuration _php Tutorial

Source: Internet
Author: User

Yii Learning Summary of the installation configuration


This article is the first article of Yii Learning Summary series, mainly to introduce the simple introduction of yii and installation and configuration, the need for a small partner to refer to it.

Previously written Yii article, just vacation nothing, combined with previous articles, YII official documents, plus 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:

The code is as follows:


% CD Webroot/testdrive/framework
% Yiic WebApp. /.. /testdrive
Create a WEB application under '/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.

The code is as follows:


testdrive/
index.php Web App Portal script file
Portal script files used by the index-test.php functional test
assets/contains a public resource file
css/contains CSS files
Images/contains picture files
Themes/contains app themes
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/contains the custom ' YIIC ' command
shell/contains custom ' YIIC shell ' commands
components/contains reusable user components
Controller.php base class for all controller classes
Identity.php ' Identity ' class for authentication
config/contains configuration files
console.php Console Application Configuration
main.php Web App Configuration
Configuration used by the test.php functional test
controllers/class file containing the controller
sitecontroller.php class file for default controller
data/contains sample Databases
Schema.mysql.sql Sample MySQL Database
Schema.sqlite.sql Example SQLite database
Testdrive.db Sample SQLite Database file
extensions/contains third-party extensions
messages/contains translated messages
models/class files that contain models
Form model for loginform.php ' login ' action
Form model for contactform.php ' contact ' action
runtime/contains files that are temporarily generated
tests/contains test scripts
views/contains the view and layout files for the controller
layouts/contains layout view files
main.php default layout for all views
column1.php using layouts for single-column pages
column2.php the layout used for a page with two columns
site/The view file containing the ' site ' controller
Pages/contains a "static" page
about.php view of the "about" page
View of contact.php ' contact ' action
error.php ' ERROR ' Action view (external error is displayed)
index.php The view of the ' Index ' action
View of login.php ' login ' action
system/contains system view files

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 from LoadModule rewrite_module modules/mod_rewrite.so to ensure "allowoverride All ".
2. Add the code in the/protected/config/main.php in the project:

The code is as follows:


' Components ' =>array (
...
' Urlmanager ' =>array (
' Urlformat ' = ' path ',
' Showscriptname ' =>false,//note false do not enclose in quotation marks
' 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

The code is as follows:


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 can use Nginx and PHP's FPM SAPI. Configured as follows

The code is 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 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 is 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;
}
}

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/966924.html www.bkjia.com true http://www.bkjia.com/PHPjc/966924.html techarticle Yii Learning Summary of the installation configuration This is the first article of Yii Learning Summary series, mainly to introduce the simple introduction of yii and installation and configuration, the need for a small partner to refer to it. ...

  • 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.