search
HomeBackend DevelopmentPHP TutorialYii learning summary installation configuration, yii summary installation configuration_PHP tutorial

Yii learning summary installation configuration, yii summary installation configuration

I have written articles about Yii before, and I just have nothing to do during the holidays, so I will combine the previous articles, the official documentation of Yii, and the recent harvest about Yii to summarize and write a series~~

Yii is a high-performance component-based PHP framework for developing large-scale web applications. Yii is written in strict OOP and has complete library references and comprehensive tutorials. From MVC, DAO/ActiveRecord, widgets, caching, hierarchical RBAC, web services, to theming, I18N and L10N, Yii provides almost everything needed 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. A simple command line tool yiic 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 Yii

Before installing Yii, you must configure your development environment, such as a web server that supports PHP5.1.0 or above. Yii has been tested on the Apache web server on Windows and Linux operating systems. It may also run on web servers that support PHP5 on other platforms. There are many free resources published on the Internet, and you may get a web server environment configured with PHP5. Here we will leave aside the web server and PHP5 installation.
The installation of Yii is actually very simple. It only requires two steps:
Download the Yii framework from http://www.yiiframework.com/ Unzip the downloaded file to a directory accessible to the web server.
After the installation is complete, it is recommended that you check whether the current server meets all Yii requirements.
Fortunately, doing this is easy, and Yii comes with a simple inspection tool. To call it, enter: http://yourhostname/path/to/yii/requirements/index.php in your browser address bar. Your server's configuration will be displayed below. Use the check tool to determine that the server does not have extensions or components installed and used, but it only gives a suggestion to ensure that the installation can be determined. As you can see, not all of the following check results are in Passed status, but some also show Warning. Of course, your configuration may be slightly different, and therefore, your display results will be different. In fact, it is not necessary to pass all the details below. But part of it is also necessary. According to the content of the Conclusion paragraph: your server configuration meets the minimum requirements of Yii. (Your server configuration satisfies the minimum requirements by Yii.)

Create a new application
The installation location of Yii is something you already know
WebRoot is the root directory of your web server configuration
From your command line, go to the framework directory and execute the following:

Copy code 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 application has been successfully created under /WebRoot/demo. The purpose of this webapp command is to create a brand new Yii application. It only requires specifying a parameter, whether it is an absolute or relative path and the application will be created. The directories and files it generates are just a skeleton of the application.

Copy code The code is as follows:

testdrive/
index.php Web application entry script file
index-test.php Entry script file used for functional testing
assets/ Contains public resource files
css/ Contains CSS files
images/ Contains image files
themes/ Contains application themes
protected/ Contains protected application files
yiic command line script
yiic.bat yiic command line script under Windows
yiic.php yiic command line PHP script
commands/ Contains custom 'yiic' commands
shell/ Contains custom 'yiic shell' commands components/ contains reusable user components
              Controller.php               The base class for all controller classes
Identity.php The 'Identity' class used for authentication
                                                                                                                                                                                                                            Console.php Console application configuration
                                                                                                                                                                                                               test.php Configuration used for functional testing
controllers/ class files containing controllers
SiteController.php Default controller class file
data/ Contains sample database
Schema.mysql.sql example 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 containing models
LoginForm.php Form model for 'login' action
ContactForm.php 'contact' action form model
runtime/ Contains temporarily generated files
tests/ tests/ Contains test scripts
views/ Contains the controller’s view and layout files
Layouts/Including layout view files
Main.php The default layout of all views of all views
Column1.php The layout used by a single -column page
                                                                                                                                                  ’ ’ s ’ s ’ s ’ s ’ s ’ s 1 t                     ’ ‐ down to column ’s ’ s ’ t it t ‐ to column2.php       Site/View file containing the 'Site' controller
pages/ Contains "static" pages
View of the "about" page about.php
               contact.php      View of the 'contact' action
             error.php        View of the 'error' action (shows external errors)
View of 'index' action
View of 'login' action
system/ Contains system view files

Without writing a line of code at this time, we can access the following URL in the browser to see our first Yii application:

http://hostname/testdrive/index.php


As we will see, this application contains three pages: home page, contact page, and login page. The homepage displays some information about the application and the user's login status, the contact page displays a contact form for users to fill out and submit their inquiries, and the login page allows users to first authenticate and then access authorized content.

Configuration

In this application, no matter which page URL you go to, index.php is included. What should I do if I want to remove it?

1. Enable apache's mod_rewrite module, remove the "#" symbol in front of LoadModule rewrite_module modules/mod_rewrite.so, and make sure there is "AllowOverride All" in .

2. Add code to /protected/config/main.php in the project:

Copy code The code is as follows:
'components'=>array(
...
            'urlManager'=>array(
                 'urlFormat'=>'path',
'Showscriptname' = & gt; false, // Note that False does not use 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. The configuration is as follows

Copy code 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. The configuration is as follows

Copy code 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 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;
    }
}

 使用如上配置,你可以在php.ini中设置cgi.fix_pathinfo=0,这样可以避免许多不必要的系统的stat()调用。

基本安装和配置就到这里~~

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/959101.htmlTechArticleYii学习总结之安装配置,yii总结安装配置 之前写过Yii的文章,正好假期没啥事,就结合以前的文章,Yii的官方文档,再加上最近的关于Yi...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP: An Introduction to the Server-Side Scripting LanguagePHP: An Introduction to the Server-Side Scripting LanguageApr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP and the Web: Exploring its Long-Term ImpactPHP and the Web: Exploring its Long-Term ImpactApr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

Why Use PHP? Advantages and Benefits ExplainedWhy Use PHP? Advantages and Benefits ExplainedApr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

Debunking the Myths: Is PHP Really a Dead Language?Debunking the Myths: Is PHP Really a Dead Language?Apr 16, 2025 am 12:15 AM

PHP is not dead. 1) The PHP community actively solves performance and security issues, and PHP7.x improves performance. 2) PHP is suitable for modern web development and is widely used in large websites. 3) PHP is easy to learn and the server performs well, but the type system is not as strict as static languages. 4) PHP is still important in the fields of content management and e-commerce, and the ecosystem continues to evolve. 5) Optimize performance through OPcache and APC, and use OOP and design patterns to improve code quality.

The PHP vs. Python Debate: Which is Better?The PHP vs. Python Debate: Which is Better?Apr 16, 2025 am 12:03 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on the project requirements. 1) PHP is suitable for web development, easy to learn, rich community resources, but the syntax is not modern enough, and performance and security need to be paid attention to. 2) Python is suitable for data science and machine learning, with concise syntax and easy to learn, but there are bottlenecks in execution speed and memory management.

PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools