Yii learning (1) -- Install configuration _ PHP Tutorial

Source: Internet
Author: User
Tags php framework contact form dotfiles
Yii learning (1) -- Install the configuration. I have previously written Yii articles on sina's blog. I haven't written any more articles about Yii since I came to the blog Park. it's just that I have nothing to do with the Dragon Boat Festival holiday. I just combined my previous blog and Yii official documents, in addition, I have previously written Yii articles in sina's blog. I haven't written any more articles about Yii since I came to the blog Park. it's just that I have nothing to do with the Dragon Boat Festival holiday. I just joined my previous blog, yii official documentation, coupled with the recent Yii gains summary, write a series ~~

Yii is a component-based high-performance PHP framework for developing large Web applications. Yii is written in strict OOP mode and has complete library references and Comprehensive tutorials. From MVC, DAO/ActiveRecord, widgets, caching, hierarchical RBAC, Web services, to topic, I18N and L10N, Yii provides almost all the functions required for today's Web 2.0 application development. In fact, Yii is one of the most efficient PHP frameworks. Yii is a high-performance PHP 5 web application development framework. Using a simple command line tool yiic, you can quickly create a web application code framework. developers can add business logic based on the generated code framework to quickly complete application development.

Install YiiBefore installing Yii, you must configure your development environment, such as a Web server that supports PHP5.1.0 or later. Yii has passed the Apache Web server test on Windows and Linux operating systems. It may also run on Web servers supporting PHP5 on other platforms. many free resources are published on the Internet, and you may get a Web server environment with PHP5 configured. Here we will leave the Web server and PHP5 installation aside. The installation of Yii is actually very simple. it takes only two steps:
  • Extract the downloaded file from the http://www.yiiframework.com/download Yii Framework to a directory accessible to the Web server.
  • After the installation is complete, we recommend that you check whether the current server meets all Yii requirements.
Fortunately, Yii comes with a simple check tool. To call it, enter http: // yourhostname/path/to/yii/requirements/index. php in your browser's address bar. the configuration of your server is shown below. Use the check tool to make sure that the server does not install and use extensions or components, but it only provides a suggestion to ensure that the installation is confirmed. As you can see, the following check results are not all in the Passed (pass) status, but some of them also display the Warning ). Of course, your configuration may be slightly different, so your display results may also be different. In fact, there is no need to pass all the details below. But it is also necessary. according to the Conclusion section, your server configuration meets the minimum requirements of Yii. (Your server configuration satisfies the minimum requirements by Yii .) Create a new application
  • Yii installation location is already known to you
  • WebRoot is the root directory configured on your Web server
  • Go to the framework directory from your command line and execute the following content:
  % 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/WebRoot/demo. This webapp command is used to create a brand new Yii application. It only needs to specify a parameter, whether it is an absolute or relative path, the application will be created. Its generated directories and files are only a skeleton of the application.

Testdrive/index. php Web app portal script file index-test.php function test use portal script file assets/contains public resource file css/contains CSS file images/contains image file themes/contains app topic protected/contains subject yiic command line script yiic. the yiic command line script yiic in bat Windows. php yiic command line PHP script commands/contains the custom 'yic' command shell/contains the custom 'yicic shell' command components/contains reusable user component Controller. identity of all php controller classes. the 'Identity 'class config/containing the configuration file console for php authentication. main. php Web application configuration test. the configuration controllers/class file containing the controller SiteController used for php function testing. php default controller class file data/contains sample database schema. mysql. SQL example MySQL database schema. sqlite. SQL example SQLite database testdrive. db example SQLite database file extensions/contains third-party extension messages/contains the translated message models/class file containing the model LoginForm. php 'login' action form model ContactForm. the form model runtime/contains the temporary file tests/contains the test script views/contains the controller view and layout file layouts/contains the Layout view file main. default layout of all views of php column1.php use single-column pages use layout column2.php use double-row pages use layout site/view file pages containing the 'site' controller/contain "static" page about. php "about" page view contact. php 'Contact 'Action view error. php 'error' action View (displaying external errors) index. php 'index' action View login. php 'login' action View system/system view file

In this case, you do not need to write a line of code. we can access the following URL in the browser to see our first Yii application:


We can see that this application contains three pages: Homepage, contact page, and logon page. The home page displays information about applications and user logon statuses. the contact page displays a contact form for users to enter and submit their inquiries, the logon page allows users to pass authentication and then access authorized content.


In this application, no matter which page url contains index. php, what should I do if I want to remove it.

1. enable the mod_rewrite module of apache and remove the "#" symbol before LoadModule rewrite_module modules/mod_rewrite.so to ensure There is "AllowOverride All ". 2. add the code to/protected/config/main. php in the project:
'Components' => array (... 'urlmanager' => array ('urlformat' => 'path', 'showscriptname' => false, // Do not enclose 'rules' => array ('sites '=> 'site/Index ',),),...),

3. configure the server. Yii can be configured in Apache and Nginx.

1) Apache

On the Apache server, configure the. htaccess file for Yii. The configuration 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 directlyRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d# otherwise forward it to index.phpRewriteRule . index.php

2) Nginx

Yii can use fpm sapi of Nginx and PHP. The configuration 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    #    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;        include fastcgi_params;        fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;        #PATH_INFO and PATH_TRANSLATED can be 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;    }}

With the above configuration, you can set cgi. fix_pathinfo = 0 in php. ini to avoid many unnecessary system stat () calls.

Here is the basic installation and configuration ~~


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.