The installation configuration _php skill of the summary of Yii learning

Source: Internet
Author: User
Tags php class php framework php script sqlite sqlite database svn yii dotfiles

Previously wrote Yii articles, just a holiday nothing, on the combination of previous articles, Yii official documents, coupled with the recent harvest of Yii Summary, write a series ~ ~

Yii is a component-based, high-performance PHP framework for developing large Web applications. Yii is written in strict OOP and has perfect library references and comprehensive tutorials. From mvc,dao/activerecord,widgets,caching, hierarchical rbac,web services, to thematic, i18n, and l10n,yii provide nearly 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 that allows developers to add business logic based on the generated code framework to quickly complete application development.

Installing Yii

Before you install YII, you must configure your development environment, such as a Web server that supports the PHP5.1.0 version. Yii has been tested via the Apache Web server on Windows and Linux operating systems. It may also run on other platforms to support PHP5 Web servers, the Internet has released a lot of free resources, you may get a well configured PHP5 Web server environment. Here we will throw away the Web server and PHP5 installation.
The installation of Yii is actually very simple and requires only two steps:
Extract the downloaded files from the http://www.yiiframework.com/download Yii framework to the directory that the Web server can access.
After the installation is complete, it is recommended that you check to see if the current server has met all the requirements of yii.
Luckily, it's easy to do, and Yii brings a simple check tool. To invoke it, enter in your browser's address bar: http://yourhostname/path/to/yii/requirements/index.php, below will display the configuration of your server. Use the Check tool to determine that the server is not installing and using extensions or components, but it simply gives a recommendation to ensure that the installation can be determined. As you can see, the results of the next check are not all passed (pass) status, and there is a partial display of warning (warning). Of course, your configuration may be slightly different, so your display results will vary. In fact, the following details are not necessary for all to pass. But part is also necessary, according to conclusion (conclusion) of this paragraph: Your server configuration meets the minimum requirements for 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 perform the following:

Copy Code code 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 application has been successfully created under the/webroot/demo. The role of this WebApp command is to create a new Yii application. It only needs to specify an argument, whether it is an absolute or a relative path, that will create the application. The directories and files it generates are only one skeleton of the application.

Copy Code code as follows:

testdrive/
index.php WEB Application Portal Script file
The portal script file used by the index-test.php function test
Assets/contains a publicly available resource file
css/contains CSS files
Images/contains picture files
Themes/contains application topics
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 a custom ' YIIC ' command
shell/contains a custom ' yiic Shell ' command
components/contains reusable user components
Controller.php the base class for all controller classes
Identity.php used to authenticate the ' Identity ' class
config/contains configuration files
console.php Console Application Configuration
main.php WEB application Configuration
Configuration used by the test.php functional test
controllers/class files that contain controllers
sitecontroller.php class file for default controller
data/contains sample Databases
Schema.mysql.sql Sample MySQL Database
Schema.sqlite.sql Sample SQLite Database
Testdrive.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's form model
A form model for contactform.php ' contact ' action
runtime/contains files that are temporarily generated
tests/contains test scripts
Views/contains the controller's view and layout files
layouts/contains layout view files
main.php the default layout for all views
column1.php layout used with a Single-column page
column2.php the layout used by a two-column page
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
View of error.php ' Error ' Action (show external error)
View of the index.php ' index ' action
View of the login.php ' login ' action
system/contains system view files

Instead of writing a 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 application contains three pages: the first page, the contact page, the login page. Home Show some information about the application and user login status, contact page displays a contact form for users to fill out and submit their inquiries, the login page allows users to pass the authentication and then access the authorized content.

Configuration

In this application, no matter to the URL of the page with index.php, if you want to remove it, how to do.

1. Open the Apache mod_rewrite module, remove LoadModule rewrite_module modules/mod_rewrite.so before the "#" symbol to ensure <directory "..." ></ There are "allowoverride all" in the directory>.
2. Add code to the/protected/config/main.php in the project:

Copy Code code as follows:

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

Copy Code code 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

Copy Code code 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 as above, you can set up cgi.fix_pathinfo=0 in PHP.ini, which avoids many unnecessary stat () calls to the system.

The basic installation and configuration is here ~ ~

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.