


Apache installation and configuration, Apache installation configuration_PHP tutorial
Apache installation and configuration, Apache installation configuration
Install Apache
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
Apache directory structure:
bin directory:
Apache’s main configuration file
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)
Configuration of virtual host:
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
IP based hosting
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
Configuration based on domain name
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:
Port based configuration
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
AllowOverride
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
1. Customized error page
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:
2. Redirect
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 working mode
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:
Apache implements user authentication
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:

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

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

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



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
