search
HomeBackend DevelopmentPHP TutorialYii learning summary installation and configuration_PHP tutorial

Yii learning summary installation and configuration_PHP tutorial

Jul 13, 2016 am 10:03 AM
yiihostbigstudyInstallSummarizearticleyesofseriesConfiguration

Yii Learning Summary Installation and Configuration

This article is the first article in the Yii Learning Summary series. It mainly introduces you to a brief introduction, installation and configuration of YII. If necessary Friends, please refer to it.

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 and 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. The following will display the configuration of your server. 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:

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.

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 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 'Identity' class used for authentication
config/ contains configuration files
console.php console application configuration
main.php Web application configuration
test.php Configuration used for functional testing
controllers/ contains controller class files
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/ contains model class files
LoginForm.php 'login' action form model
ContactForm.php 'contact' action form model
runtime/ contains temporarily generated files
tests/ contains test scripts
views/ contains the controller’s view and layout files
layouts/ contains layout view files
main.php Default layout for all views
column1.php uses the layout used by single column pages
column2.php The layout used by pages using double columns
site/ contains the view file for the 'site' controller
pages/ contains "static" pages
About.php "about" page view
View of contact.php 'contact' action
error.php 'error' action view (display external errors)
index.php 'index' action view
View of login.php '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:

The code is as follows:


'components'=>array(
...
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,//Note that false should not be enclosed 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. The configuration is 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. The configuration is 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 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/966924.htmlTechArticleYii学习总结之安装配置 本文是Yii学习总结系列文章的第一篇,主要给大家介绍下YII的简单介绍及安装和配置,有需要的小伙伴参考下吧。...
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
What are some common problems that can cause PHP sessions to fail?What are some common problems that can cause PHP sessions to fail?Apr 25, 2025 am 12:16 AM

Reasons for PHPSession failure include configuration errors, cookie issues, and session expiration. 1. Configuration error: Check and set the correct session.save_path. 2.Cookie problem: Make sure the cookie is set correctly. 3.Session expires: Adjust session.gc_maxlifetime value to extend session time.

How do you debug session-related issues in PHP?How do you debug session-related issues in PHP?Apr 25, 2025 am 12:12 AM

Methods to debug session problems in PHP include: 1. Check whether the session is started correctly; 2. Verify the delivery of the session ID; 3. Check the storage and reading of session data; 4. Check the server configuration. By outputting session ID and data, viewing session file content, etc., you can effectively diagnose and solve session-related problems.

What happens if session_start() is called multiple times?What happens if session_start() is called multiple times?Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

How do you configure the session lifetime in PHP?How do you configure the session lifetime in PHP?Apr 25, 2025 am 12:05 AM

Configuring the session lifecycle in PHP can be achieved by setting session.gc_maxlifetime and session.cookie_lifetime. 1) session.gc_maxlifetime controls the survival time of server-side session data, 2) session.cookie_lifetime controls the life cycle of client cookies. When set to 0, the cookie expires when the browser is closed.

What are the advantages of using a database to store sessions?What are the advantages of using a database to store sessions?Apr 24, 2025 am 12:16 AM

The main advantages of using database storage sessions include persistence, scalability, and security. 1. Persistence: Even if the server restarts, the session data can remain unchanged. 2. Scalability: Applicable to distributed systems, ensuring that session data is synchronized between multiple servers. 3. Security: The database provides encrypted storage to protect sensitive information.

How do you implement custom session handling in PHP?How do you implement custom session handling in PHP?Apr 24, 2025 am 12:16 AM

Implementing custom session processing in PHP can be done by implementing the SessionHandlerInterface interface. The specific steps include: 1) Creating a class that implements SessionHandlerInterface, such as CustomSessionHandler; 2) Rewriting methods in the interface (such as open, close, read, write, destroy, gc) to define the life cycle and storage method of session data; 3) Register a custom session processor in a PHP script and start the session. This allows data to be stored in media such as MySQL and Redis to improve performance, security and scalability.

What is a session ID?What is a session ID?Apr 24, 2025 am 12:13 AM

SessionID is a mechanism used in web applications to track user session status. 1. It is a randomly generated string used to maintain user's identity information during multiple interactions between the user and the server. 2. The server generates and sends it to the client through cookies or URL parameters to help identify and associate these requests in multiple requests of the user. 3. Generation usually uses random algorithms to ensure uniqueness and unpredictability. 4. In actual development, in-memory databases such as Redis can be used to store session data to improve performance and security.

How do you handle sessions in a stateless environment (e.g., API)?How do you handle sessions in a stateless environment (e.g., API)?Apr 24, 2025 am 12:12 AM

Managing sessions in stateless environments such as APIs can be achieved by using JWT or cookies. 1. JWT is suitable for statelessness and scalability, but it is large in size when it comes to big data. 2.Cookies are more traditional and easy to implement, but they need to be configured with caution to ensure security.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.