


Yii learning summary installation and configuration_PHP tutorial
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()调用。
基本安装和配置就到这里~~

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Installing Android applications on Linux has always been a concern for many users. Especially for Linux users who like to use Android applications, it is very important to master how to install Android applications on Linux systems. Although running Android applications directly on Linux is not as simple as on the Android platform, by using emulators or third-party tools, we can still happily enjoy Android applications on Linux. The following will introduce how to install Android applications on Linux systems.

Understanding Linux Bashrc: Function, Configuration and Usage In Linux systems, Bashrc (BourneAgainShellruncommands) is a very important configuration file, which contains various commands and settings that are automatically run when the system starts. The Bashrc file is usually located in the user's home directory and is a hidden file. Its function is to customize the Bashshell environment for the user. 1. Bashrc function setting environment

While studying in high school, some students take very clear and accurate notes, taking more notes than others in the same class. For some, note-taking is a hobby, while for others, it is a necessity when they easily forget small information about anything important. Microsoft's NTFS application is particularly useful for students who wish to save important notes beyond regular lectures. In this article, we will describe the installation of Ubuntu applications on Ubuntu24. Updating the Ubuntu System Before installing the Ubuntu installer, on Ubuntu24 we need to ensure that the newly configured system has been updated. We can use the most famous "a" in Ubuntu system

If you have used Docker, you must understand daemons, containers, and their functions. A daemon is a service that runs in the background when a container is already in use in any system. Podman is a free management tool for managing and creating containers without relying on any daemon such as Docker. Therefore, it has advantages in managing containers without the need for long-term backend services. Additionally, Podman does not require root-level permissions to be used. This guide discusses in detail how to install Podman on Ubuntu24. To update the system, we first need to update the system and open the Terminal shell of Ubuntu24. During both installation and upgrade processes, we need to use the command line. a simple

Detailed steps to install Go language on Win7 computer Go (also known as Golang) is an open source programming language developed by Google. It is simple, efficient and has excellent concurrency performance. It is suitable for the development of cloud services, network applications and back-end systems. . Installing the Go language on a Win7 computer allows you to quickly get started with the language and start writing Go programs. The following will introduce in detail the steps to install the Go language on a Win7 computer, and attach specific code examples. Step 1: Download the Go language installation package and visit the Go official website

The Xiaomi Mi 15 series is expected to be officially released in October, and its full series codenames have been exposed in the foreign media MiCode code base. Among them, the flagship Xiaomi Mi 15 Ultra is codenamed "Xuanyuan" (meaning "Xuanyuan"). This name comes from the Yellow Emperor in Chinese mythology, which symbolizes nobility. Xiaomi 15 is codenamed "Dada", while Xiaomi 15Pro is named "Haotian" (meaning "Haotian"). The internal code name of Xiaomi Mi 15S Pro is "dijun", which alludes to Emperor Jun, the creator god of "The Classic of Mountains and Seas". Xiaomi 15Ultra series covers

Title: A complete guide to installing FTPS service under Linux system In Linux system, setting up an FTP server is a common requirement. However, in order to enhance the security of data transmission, we can choose to install the FTPS service, which adds SSL/TLS encryption function based on the FTP protocol. Through the FTPS service, we can upload and download files while ensuring the security of data transmission. This article will provide a detailed guide for installing FTPS service under Linux system and provide specific instructions.

Installing Go language under Win7 system is a relatively simple operation. Just follow the following steps to successfully install it. The following will introduce in detail how to install Go language under Win7 system. Step 1: Download the Go language installation package. First, open the Go language official website (https://golang.org/) and enter the download page. On the download page, select the installation package version compatible with Win7 system to download. Click the Download button and wait for the installation package to download. Step 2: Install Go language
