"PHP Learning" PHP Introductory Classic Chapter II notes

Source: Internet
Author: User
Tags builtin php introduction hosting sites web hosting web hosting sites

Document: HTTP://HTTPD.APACHE.ORG/DOCS/2.4/

directive: http://httpd.apache.org/docs/2.4/mod/core.html

One, configuration file

Grammar

* Master config file httpd.conf, change only restart service will take effect
* One line in the configuration command, if you want to more than one command, the last with a \ end, and the last character of the line no other characters or blank
* Each line of comments begins with #, is ignored, and cannot be followed by a line of commands
* Blank line whitespace characters are ignored in the configuration file
* Configuration file error detection can be done through test configuration (httpd.exe-w-t-f "D:\Software\GreenSoft\Apache\conf\httpd.conf"-D "D:\Software\ Greensoft\apache\. ")


Module

Related modulesrelated directives
--------------------------------------------
Mod_so<ifmodule>
LoadModule

* HTTPD is based on modularization, when compiling the configuration, the basic function module is loaded into the server kernel by default.
* For dynamically loaded modules can be completed by loadmodule instruction at any time.
* <IfModule> can be used for conditional loading
* DOS command httpd.exe-l can view modules that have already been loaded

* Httpd.exe supported parameter directives

-D Name:define a name for use in <ifdefine name> directives
-D directory:specify an alternate initial serverroot
-F file:specify an alternate serverconfigfile
-c "directive": process directive before reading config files
-c "directive": process directive after reading config files
-N name:set service name and use its serverconfigfile
-K Start:tell Apache to start
-K Restart:tell running Apache to do a graceful restart
-K Stop|shutdown:tell running Apache to shutdown
-K Install:install an Apache service
-K Config:change startup Options of an Apache service
-K Uninstall:uninstall an Apache service
-w:hold Open the console window on error
-e level:show startup errors of level (see LogLevel)
-e File:log Startup errors to File
-v:show Version number
-v:show Compile Settings
-h:list available command line options (this page)
-l:list compiled in Modules
-l:list Available Configuration directives
-t-d dump_vhosts:show parsed settings (currently only vhost settings)
-s:a synonym For-t-d dump_vhosts
-t-d dump_modules:show All Loaded MODULES
-m:a synonym For-t-d dump_modules
-t:run syntax check for config files
-t:start without DocumentRoot (s) check

Directive scope of action


Related modulesrelated directives
-----------------------------------------
<Directory>
<DirectoryMatch>
<Files>
<FilesMatch>
<Location>
<LocationMatch>
<VirtualHost>

* Instruction Range label can specify the scope of the directive to take effect, it can be nested
* Multiple web hosting sites can be supported by placing multiple instructions in the <VirtualHost> tab
* Node configuration see: Http://httpd.apache.org/docs/2.4/sections.html

. htaccess file

* HTTPd by placing the. htaccess file in the Site directory allows configuration to be distributed
*. htaccess's syntax is consistent with the master configuration file, and changes to that profile will take effect as soon as the request comes in.
* Commands that can be placed in the. htaccess See: Http://httpd.apache.org/docs/2.4/mod/directive-dict.html#Context
* If you have permission to configure the master configuration, you should avoid using the. htaccess file mode to configure, which affects server performance
1) after configuring the. htaccess file, httpd will find the. htaccess file for each directory, whether or not you actually use
2) When the document is requested, the. htaccess file will be loaded each time

3) httpd will look for the. htaccess file in a multi-tiered directory to apply the complete instructions.
4). The regular expression in the Address rewrite directive in htaccess is recompiled each time it is requested.
5) Security issues, the user is modifying. htaccess enables administrators to manage configuration management out of control. Only the allowoverride directive can be set to allow the user to use the specified instruction.


* Configuring directives in. htaccess can achieve the same effect as configuring Dirctory blocks in the master configuration, but the latter has better performance.

Contents of. htaccess file In/www/htdocs/example
AddType text/example. EXM

Equivalent to:

section from your httpd.conf file

<Directory/www/htdocs/example>
AddType text/example. EXM
</Directory>


* disabled. htaccess can be allowoverride with command None

Second, the Apache directory structure

root directory
|--Bin Program Command directory
|--Build
|--Cgi-bin
|--conf configuration file directory
|--Error
|--htdocs The Site directory when compiling the installation
|--icons
|--include
|--Lib
|--logs default log file storage includes error log (error_log) and access log (Access_log) tail-f Access_log can see access record at any time, inside Httpd.pid also record main process number
|--Mans
|--Manual
|--Modules module directory such as PHP memcache the compiled module is here

Bin directory
|--AB Apache HTTP Server Performance Stress test tool, similar to JMeter loadrunner webbench
|--apachectl Apache boot command
|-- Apr-1-config
|--apu-1-config
|--apxs Apache Server compile and install extension tools that will be used to compile the DSO mode module for example when compiling PHP:--with-apxs2=/usr/ Local/apache/bin/apxs
|--checkgid
|--dbmmanage
|--envvars
|--envvars-std
|--Htcacheclean The command to clean up the disk buffers is generally less used
|--htdbm
|--htdigest
|--htpasswd to establish updated Basic authentication files such as configuring Nagio monitoring will use
|--httpd for Apache control command program, Apachectl call to httpd
|--httxt2dbm
|--logresolve

when executing


Conf Directory
|--Extra Auxiliary Apache configuration file
| |--httpd-autoindex.conf
| |--httpd-dav.conf DAV Support configuration
| |--httpd-default.conf Apache related service configuration such as time-out time to stay connected
| |--httpd-info.conf
| |--httpd-languages.conf Language Support
| |--httpd-manual.conf
| |--httpd-mpm.conf Server pool management, such as Apache mode Configuration connection
| |--httpd-multilang-errordoc.conf
| |--httpd-ssl.conf supports SSL encryption configuration
| |--httpd-userdir.conf
| |--httpd-vhosts.conf Virtual machine configuration file
|--httpd.conf Master configuration file
|--Magic
|--Mime.types
|--Original

Three, httpd.conf main configuration file Common configuration


ServerRoot "/usr/local/apache2.2.22" Apache installation directory
Listen Apache Port
<ifmodule!mpm_netware_module>
<ifmodule!mpm_winnt_module>
User Daemon Apache running users
Group Daemon Apache Run groups
</IfModule>
</IfModule>
ServerAdmin [email protected] Admin mailbox
DocumentRoot "/usr/local/apache2.2.22/htdocs" Site Directory, note that the last do not add/Line

<directory/> root directory permissions
Options FollowSymLinks can use symbolic links
AllowOverride None
Order Deny,allow
Deny from all
</Directory>
<directory "/usr/local/apache2.2.22/htdocs" > Directory permissions Note Indexes's role is to allow directory browsing
Options Indexes FollowSymLinks
allowoverride None disables user-to-directory configuration files. htaccess modified, generally none
Order Allow,deny
Allow from all
</Directory>

<ifmodule dir_module>
DirectoryIndex index.html Site Directory Home file Multiple files separated by spaces
</IfModule>

<filesmatch "^\.ht" > Prevent Web users from viewing hidden files beginning with. HT
Order Allow,deny
Deny from all
Satisfy All
</FilesMatch>

Errorlog "Logs/error_log" error log
LogLevel Warn warning Level
<ifmodule log_config_module>
Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" Combined compound log format
Logformat "%h%l%u%t \"%r\ "%>s%b" common general log format
<ifmodule logio_module>
Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "%I%O" combinedio compound log format
</IfModule>
Customlog "Logs/access_log" Common default Access log format
</IfModule>

<ifmodule alias_module>
scriptalias/cgi-bin/"/usr/local/apache2.2.22/cgi-bin/" CGI alias configuration
</IfModule>
<ifmodule cgid_module>
</IfModule>

<directory "/usr/local/apache2.2.22/cgi-bin" > CGI access Path
AllowOverride None
Options None
Order Allow,deny
Allow from all
</Directory>
DefaultType Text/plain definition cannot determine MIME type when using default MIME type, if the service mainly contains text or HTML, Text/plain is a good choice

<ifmodule mime_module>
Typesconfig Conf/mime.types
AddType application/x-compress. Z allows information to be extracted in transit using mosaic/x 2.1+, but not all browsers support
AddType application/x-gzip. gz. tgz
</IfModule>

<ifmodule ssl_module>
Sslrandomseed Startup Builtin
Sslrandomseed Connect Builtin
</IfModule>

Four, virtual host http_vhost.conf configuration file

Namevirtuahost *:80 represents a name-based virtual host *:80 provides HTTP services on 80 ports that listen to all IP on this computer, * can be set to a specific IP
<virtualhost *:80>
ServerAdmin Admin Mailbox
ServerName Domain name
Serveralias aliases can set multiple domains to point to the same site
Errorlog error Log
Customlog Access Log
</VirtualHost>


The configuration of the virtual host is a local priority principle, that is, the http_vhost.conf configuration, then it will not be read from the main configuration file http.conf


V. Modify the Apache default Site Directory

1. Document PATH changes
DocumentRoot "D:/software/greensoft/apache/htdocs"
Change into
DocumentRoot "E:/wwwroot/apache"

2. Directory Changes
<directory "D:/software/greensoft/apache/htdocs" >
Change into
<directory "E:/wwwroot/apache" >


Six, configure multi-site mode

Mode one copy configuration file, install new service
1. Copy the httpd.conf to a new file httpdnew.conf
2. Change the listening port in httpdnew.conf to a custom port that is not used. listen:8111
3, the httpdnew.conf in the Site Directory DocumentRoot "original absolute path" to DocumentRoot "new absolute path"
4, the httpdnew.conf in the permissions set <directory "original absolute path" > Changed to <directory "New absolute path" >
5. Installation of new services. Dos down into the bin directory under Apache installation directory, enter command httpd.exe-k install-n "service name"-F "X:\Apache installation directory root \conf\httpdnew.conf"
6, start the new service. Enter Command httpd-k start


Mode two add new port, new virtual directory Way
1, httpd.conf on the basis of the previous listening port, plus the new listening port Listen 8333. So Apache has multiple listening ports
2, httpd.conf to join the virtual host support. Join instruction: Namevirtualhost *
3. Find the location of <VirtualHost> definition notes. Join instruction:
<virtualhost localhost:8333>
ServerName localhost
DocumentRoot "virtual site new absolute path"
</VirtualHost>

Mode three establish the virtual host way
1. Modify the virtual host Profile X:\Apache installation directory root directory \conf\extra\httpd-vhosts.conf file. Add Configuration:
<virtualhost 127.0.1.1:8222>
DocumentRoot "virtual site new absolute path"
ServerName url.com
Errorlog "virtual site new absolute path/error.log"
</VirtualHost>

2. Modify the Master Profile X:\Apache installation directory root directory \conf\httpd.conf. Remove # # # # # # # # # conf/extra/httpd-vhosts.conf
3. Modify the Master Profile X:\Apache installation directory root directory \conf\httpd.conf. Add Directory Permissions:
<directory "virtual site new absolute path" >
Options Indexes followsymlinks multiviews execcgi
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
4. Restart the corresponding Apache service

Vii. configuring Apache to support URL rewriting

1, add the load-carrying module. Httpd.conf found #loadmodule rewrite_module modules/mod_rewrite.so, remove the # number
2, httpd.conf found allowoverride None, changed to allowoverride all (all indicates that URL rule rewriting is supported on the entire server)
3, httpd.conf Join
<directory "Site absolute path" >
Options FollowSymLinks
AllowOverride All
</Directory>
4. Restart the Apache server and start the service
5. In the URL rewrite site directory, a. htaccess file with the file name is. htaccess. The override does not take effect if there is no such file or any rules for URL rewriting are not defined in this file.
6. In. htaccess, a pseudo-static page is mapped by a regular expression. The URL regular expression is as follows:
Rewriteengine on
Rewriterule index.html index.php
Rewriterule (\d+). htmlinfo\. Php\? Infoid= info\.php\?infoid=1
The effect is: www.abc.cn/info/info.php?infoid=100 map to Www.abc.cn/info/100.html


Can be used for the following purposes:
1. Custom page for HTTP error. Format errordocument error code/directory name/name. extension
ErrorDocument 404/errors/notfound.html
ErrorDocument 401 "You have permission to access this page!"

2. Deny access to an IP
Order Allow,deny
Deny from 210.10.56.32
Deny from 219.5.45.
Deny from www.baidu.com
Allow from all

3. Protect. Htaccess documentation
4, URL to turn (document migration, directory changes, display friendly and easy to remember URL). Format:
Redirect/old directory/old document name new document name
Redirect Old Directory New directory

5. Change the default home page
DirectoryIndex the new default name
DirectoryIndex filename.html index.cgi index.pl default.htm

6. Anti-hotlinking
Rewriteengine on
Rewritecond%{Http_referer}!^R ew ri te co nd Rewritecond [NC]
Rewriterule. (gif&line;jpg) -[F] rewriterule. (gif&line;jpg) -[F] rewriterule. (gif&line;jpg) http://www.mydomain.com/alternative name [r,l]

Eight, configure anti-hotlinking
1, see Configure Apache Support URL rewrite section, configure Apache support URL rewrite
2, in the site of the. htaccess file to add
Rewriteengine on
#允许空 access to "Http_referer"
Rewritecond%{http_referer}!^[nC]rEwrIteCoNd [Nc]rewritecond http://nobing.cn/no.png [r,nc,l]

Description
R is the meaning of the turn
NC refers to case insensitive
The function of L is to indicate the end of this steering, and the subsequent steering is not affected by the previous judgment statement.

Multiple extensions separated by |


Nine, configure the cache

LoadModule Cache_module modules/mod_cache.so
LoadModule Mem_cache_module modules/mod_mem_cache.so
<ifmodule mod_cache.c>
#默认缓存有效期 (seconds)
Cachedefaultexpire 3600
Cachemaxexpire 86400
Cachelastmodifiedfactor 0.1

#禁止缓存某些特定的URL
Cachedisable/local_files
#使用特定的存储类型缓存某些特定的URL
Cacheenable mem/manual
Cacheenable fd/images
Cacheenable Disk/
<ifmodule mod_mem_cache.c>
Cacheenable Mem/
Mcachesize 8192
Mcachemaxobjectcount 10000
Mcacheminobjectsize 1
Mcachemaxobjectsize 51200
#MCacheRemovalAlgorithm LRU
</IfModule>
</IfModule>

PHP Learning PHP Introduction Classic Chapter Two notes

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.