1. Download the apache software http://www.apache.org
2. Installation
Install as administrator
3. Set the host name and domain name
4. Select the installation type
5. Customize the installation path
6. Start installation
7. Installation completed
8. Test:
Enter localhost in the browser’s address bar
httpd.conf is the main configuration file, located in the conf directory
SeverRoot
Server root directory (apache installation directory)
Example:
ServerRoot "D:/wamp1027"
Listen 80
Listening port
Example:
Listen 80
Set multiple listening ports
Listen 80
Listen 5000
Load function module
user The group name to which the user belongs
Example:
User daemon
group group name
Example:
Group daemon
ServerAdmin
Administrator email
Example:
ServerAdmin 20151027@itcast.net
ServerName
Set domain name (host name)
Example:
#ServerName localhost:80
DocumentRoot
The site root directory is mainly used to suggest the mapping relationship between domain names and directories internally.
Example:
DocumentRoot "D:/wamp1027/htdocs"
The role of domain name:
1. Provide external access (ISP’s DNS server completes the function)
2. Establish a mapping relationship between domain names and directories internally (just use the servername and documentroot options in the configuration file to configure)
Related settings for directories
#Directory related configuration
Directory related configuration:
Default homepage
DirectoryIndex is mainly used to return the home page file when the access request only specifies the domain name but not the specific file.
Example:
DirectoryIndex Home 1 Home 2
Whether directory structure listing is allowed
Options Indexes
Function: When the requested homepage file does not exist, whether to allow the directory structure to be listed. It is very unsafe. The website must be closed after it goes online (do not write this item)
AllowOverride
Mainly used to set whether to open external configuration files (.htaccess)
Set directory permissions
order
Form 1:
order deny,allow
Function: Allow all if there is no explicit rejection
Form 2:
order allow,deny
Function: Deny all if there is no explicit permission
Configure the deny and allow items using deny and allow
Example 1:
order deny,allow
deny from 192.168.10.11
allow from all
Except for the denial of 192.168.10.11, all others are allowed (regardless of the order of deny and allow specific items)
Example 2:
order allow,deny
allow from 192.168.10.11
deny from all
Only 192.168.10.11 is allowed to access, and all others are denied (regardless of the order of deny and allow specific items)
Extended configuration file httpd-vhosts.conf, located in the extra directory under the conf directory
NameVirtualHost turning on the virtual host based on the domain name
NameVirtualHost *:80
Virtual host usage:
#Host configuration items
Requirements:
There is a company with a server and three network cards
Network card 1: 192.168.10.11 www.fist.com d:/php_folder/20151027/20151201/first
Network card 2: 192.168.10.22 www.second.com
d:/php_folder/20151027/20151201/second
Network card 3: 192.168.10.33 www.third.com
d:/php_folder/20151027/20151201/second
Configuration steps:
1. Use host file to simulate DNS server
2. Enable loading of extended configuration files in the main configuration file
Create a virtual host in the extension configuration file
Requirements: Company A has a server with only a network card interface
Configure two hosts
192.168.20.11 www.one.com d:/php_folder/20151027/20151201/one
192.168.20.11 www.two.com d:/php_folder/20151027/20151201/two
Example:
Requirements:
Company A has a server
A fixed IP: 192.168.30.11
For all ordinary access, use the www.234.com domain name to operate through port 80
Require all administrators to use port 5000 for backend system management
Example:
Listening port
host file
Virtual host configuration
Used to open external configuration file .htaccess
.htaccess’s main functions are redirection, anti-leeching, and custom error message prompt pages.
Modification of .htaccess file does not require restarting apache
.htaccess file needs to be created using the editor save method
.htaccess file only takes effect in the current directory
Example 1:
Step 1: Open the external configuration file .htaccess file
Step 2: Set up a custom error message page in the .htaccess file
Example 2:
Step 1:
Step 2:
Create an image resource directory in the root directory, and create a .htaccess file in this directory with the following content:
Disable access to all files in this directory
Step 3:
When accessing a file in directory A in the root directory of the site, it will automatically redirect to directory B (or a directory under another host)
Apache only supports HTML files by default. It can support PHP through modules (plug-ins) and can also be connected to Tomcat to support JSP.
All functional extensions of Apache are implemented in the form of modules, and modules can be understood as plug-ins.
Illustration:
Example:
Step 1: Enable the following function modules
Step 2:
Use htpasswd.exe file to create a password file, the running environment is cmd
htpasswd syntax:
htpasswd -c password file username
It is used to recreate the password file.
Example:
Step three:
Set authentication method
Syntax:
AuthType Basic
Step 4:
Setting realm is to give a display name to the authenticated folder, which will be displayed to the user when they access it.
Syntax:
AuthName 'Prompt message'
Example:
Step 5:
Set up authentication user password file
Syntax:
AuthUserFile 'The directory where the password file is located'
Example:
Step 6: Set verification username
Authenticate multiple users
require user user1 user2 user3
Authenticate all users
require valid-user
Add authenticated user
Syntax:
htpasswd 'User password file' username
Example:
Delete user
Syntax:
htpasswd -D 'User password file' username
Full code example: