typora-copy-images-to: images
1.1 Today's goals
- Master how the internet works
- Master the relationship between domain names, DNS and IP addresses
- Understand the role of the hosts file in Internet access
- Understand the difference between static and dynamic websites
- Understand the server composition of a dynamic website
- Understand how PHP works
- Learn how to use PHP variables
- Understand the concept of variable variables
- Master the access form of mutable variables
- Understand the difference between pass-by-value and pass-by-reference variables
1.2 Introduction to PHP
1.2.1 Overview
PHP is the abbreviation of Hypertext Preprocessor, (Hypertext Preprocessor) is an open source scripting language that runs on the server side.
LAMP combination (Linux, Apache, MySQL, PHP), these four products are all open source products
php是一门语言,用来做业务逻辑
apache为PHP提供了运行环境
linux为Apache的运行提供了平台
mysql数据库用来存储数据
Learn more: what is a wamp combination
windows+apche+mysql+php
1.2.2 Five basic concepts
1. Static and dynamic pages
静态页面:服务器不执行的页面
动态页面:服务器执行的页面
Question: Is it possible to store static pages in a dynamic website?
Answer: Yes
2. Client and Server
浏览者这段是客户端
服务器端:给浏览者提供服务
3. Port and port number Port number range: 0-65535
4. BS architecture and CS architecture
BS: Access the server through a browser
b:browser(浏览器)
s:sever(服务器)
优点:
1、只要有浏览器就可以访问
2、开发低
缺点:
2、开发的代码都放在服务器上 胖服务器-瘦客户端
All web is BS architecture
CS: Access the server through client software
c:client(客户端)
s:server(服务器)
优点:
1、可以开发客户端和服务器端,这时候就可以实现负载的均衡
缺点:
1、必须要安装一个软件才能去访问
2、开发成本高
For example: QQ, stock trading software
5. Front and back
前台:浏览器看到的界面
后台:管理员看到的界面
1.2.3 Advantages of PHP
- Cross-platform, can run on both windows and linux
- Open source code: no copyright issues are involved
- Simple syntax: Getting started with PHP is easy
- Running on the server side, as long as the server deployment environment is fine.
1.3 Introduction to Web
1.3.1 Changes in the web era
From the rise of the Internet to the present, it has gone through the process from web1.0, 2.0 to web3.0
Web1.0(信息共享)的主要特点在于用户单纯的获取信息
Web2.0(信息共建)更注重用户的交互作用,用户既是网站内容的浏览者,也是网站内容的制造者。
Web3.0(信息传承)通过第三方信息平台对多家网站的信息进行整合,用户在互联网上拥有自己的数据,并能在不同网站上使用
Example:
Web1.0:来到一个餐馆,老板给你上了一盘番茄炒蛋;
Web2.0:来到一个餐馆,你跟老板主动点了一份番茄炒蛋;
Web3.0:来到一个餐馆,老板见到你就问,老规矩,还要番茄炒蛋?
1.3.2 Principles of Web Services
Static website principle (browser-server)
Dynamic website principle (browser-server-database)
The principle of intelligent website (browser-server [analysis and recommendation]-database)
1.4 Building a Web Server
1.4.1 Install phpstudy
Just unzip it directly
1.4.2 Directory Structure
start the service
1.4.3 Access the server
Create a demo.php page in the www directory
<?php
phpinfo();
access server
访问规则:http://服务器ip地址/php页面
比如:
http://localhost/demo.php
http://127.0.0.1/demo.php
1.4.4 Common Commands
Supplementary DOS commands
切换盘符 盘符+冒号
进入目录 cd 目录地址
Apache commands
httpd -v 查看apache版本号 version
httpd -t 检测运行环境 test
PHP commands
php -v PHP版本号
1.4.5 Principles of Internet Communication
Essentially, one computer accesses another computer's resources, addressing process (IP address, port, domain name, DNS)
On the Internet, the IP address is used to distinguish each computer's identity, but IP memory is not friendly. We take the IP address as a name, and an IP corresponds to a name, and this name is called a domain name.
Access process:
step:
1. The client enters the domain name (URL), and performs DNS resolution (Domain Name Server) in the nearest computer room. DNS resolution is to convert the domain name into an IP address
2. Access the server by IP address
1.4.6 DNS resolution
Goal: It is inconvenient to access the server by ip address, and it is accessed through the domain name.
hosts file
test
summary:
The hosts file is used for DNS resolution
1.5 Server Configuration
1.5.1 Virtual Directory Configuration
1. Change the virtual directory
To change the location of the virtual directory, you need to change it in the apache configuration file (conf/httpd.conf)
In phpstudy, both httpd.conf and vhost.conf have instructions to configure virtual directories, and both configuration files have instructions to configure virtual directories. For testing, we comment out the introduction of vhost.conf
change virtual directory
Reminder: After the project is online, the directory structure cannot be displayed
Permission exercise
Example one:
Order allow,deny
Allow from all
# 允许所有请求访问
Example two:
Order allow,deny
Allow from all
Deny from all
# 拒绝所有请求访问
Exercise three:
Order allow,deny
Deny from all
Allow from all
# 拒绝所有请求访问
Exercise four:
<Directory "C:/PHP/Apache/htdocs">
Order deny, allow
Allow from 192.168.101.50
Deny from 192.168
</Directory>
# 拒绝192.168开头,但除去(192.168.101.50)的IP的访问
Exercise five:
<Directory "C:/PHP/Apache/htdocs">
Order deny, allow
Allow from 192.168.101.50
Deny from all
</Directory>
# 只允许192.168.101.50访问
Exercise six:
<Directory "C:/PHP/Apache/htdocs">
Order allow,deny
Allow from 192.168
Deny from 192.168.101.50
</Directory>
# 只允许192.168开头的,但要去除192.168.101.50 的IP访问
2. Change the default home page
in the httpd.conf configuration file
The search order of the default home page, from front to back.
3. Change the listening port
Set in the httpd.conf configuration file
Set the listening port through the Listen command
Multiple listening ports can be set
access:
http://domain name:port number/demo.php
Supplement: View port occupancy
Use netstat -ano on the command line to view
Find a string in the results
1.5.3 Virtual host configuration
need:
输入www.baidu.com 打开web1的网站
输入www.sina.com打开web2的网站
Configuration process:
To configure virtual hosts, the training file for virtual hosts (vhosts.conf) needs to be introduced in httpd.conf
vhosts.conf is configured as follows
<VirtualHost _default_:80>
DocumentRoot "C:\web1" #指定虚拟目录路径
ServerName www.baidu.com # 虚拟目录绑定的域名
DirectoryIndex aa.php # 默认首页
<Directory "C:\web1">
Options -Indexes -FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost _default_:80>
DocumentRoot "C:\web2"
ServerName www.sina.com
DirectoryIndex bb.php
<Directory "C:\web2">
Options -Indexes -FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Do dns resolution in the host file
visit result
Supplement: The difference between sites, virtual directories, and virtual hosts
Site: A site is a folder that holds all the material related to the site
Virtual Directory: Site + Permissions
Virtual host: virtual directory + domain name
1.6 Introduction to PHP Syntax
1.6.1 PHP is a compiled language
The difference between a compiled language and an interpreted language is whether or not the final executable program is saved.
PHP execution process
1.6.2 PHP Delimiters
Because PHP is a scripting language, delimiters are required
1. Standard style (recommended)
<?php
?>
example
<?php
echo 'i am a boy!';
?>
Reminder, if the entire page is PHP code, the PHP terminator can be omitted (recommended)
<?php
echo 'i am a boy!';
2. Short tag style (not supported by default, you need to enable support for segment tags in the php configuration file)
<?
?>
example:
<?
echo '锄禾日当午';
?>
summary:
httpd.conf is the configuration file of apache
php.ini is the configuration file of php
1.6.3 Notes
Single line comments: // and #
Multi-line comments: / /
1.6.4 PHP output statement
echo:输出
print:输出,输出成功返回1
print_r():输出数组
var_dump():输出数据的详细信息,带有数据类型和数据长度
<?php
var_dump('abc'); //string(3) "abc"
?>
1.7 Variables
The essence of a variable is a space in memory
1.7.1 Naming rules for variables
- Variables must start with $, the $ character is not part of the variable, it only means that the identifier that follows is the variable name.
- Except $, start with letter, underscore, followed by number, letter, underscore
- Variable names are case-sensitive, $aa and $Aa are two spaces
Are the following variables legal?
$a 合法
$a1 合法
$1a 不合法
$_1a 合法
Note: PHP statements must end with a semicolon
<?php
$a=10;
$name='Tom';
?>
1.7.2 Variable variables
Variable name can be changed, store the variable name in another variable
example
<?php
$a=10;
$b='a';
echo $$b; //10
example
<?php
$name1='tom';
$name2='berry';
if(rand(1,10)%2){
$name='name1'; //将变量名存储在$name中
}else{
$name='name2';
}
echo $$name;
summary:
1. rand(1,10): Get a random integer from 1 to 10
1.7.3 Variable passing
Variables are passed by value and by address (pass by reference)
<?php
//值传递
$num1=10; //将10付给$num1
$num2=$num1; //将$num1的值付给$num2
$num2=20; //更改$num2
echo $num1; //10
//地址传递
$num1=10; //将10付给$num1
$num2=&$num1; //将$num1的地址付给$num2
$num2=20; //更改$num2
echo $num1; //20
summary:
1. There are two types of parameter transfer, value transfer and address transfer
2. & means to get the address of the variable
3. In the value transfer, one variable has changed, and the other variable has no effect, because there are two spaces
4. In the address transfer, one variable has changed, and the other has also changed, because the two variables point to the same space
1.7.4 Destroying variables
Use unset() to destroy the variable, the variable name is destroyed, and the variable value is destroyed by the PHP garbage collection mechanism
<?php
$num1=10;
$num2=&$num1;
unset($num1); //销毁的是变量名
echo $num2; //10
A value without a variable reference is garbage.
1.8 Homework
After phpstudy is installed, there is a phpmyadmin management database software. By default, it is placed in a virtual directory, which is unreasonable. Please reconfigure the virtual host to access phpmyadmin
Input phpmyadmin.com
open phpmyadmin management software
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。