


Apache installation and configuration, Apache installation configuration_PHP tutorial
Jul 12, 2016 am 08:55 AMApache 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

Undress AI Tool
Undress images for free

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

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

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

ToversionaPHP-basedAPIeffectively,useURL-basedversioningforclarityandeaseofrouting,separateversionedcodetoavoidconflicts,deprecateoldversionswithclearcommunication,andconsidercustomheadersonlywhennecessary.StartbyplacingtheversionintheURL(e.g.,/api/v

TosecurelyhandleauthenticationandauthorizationinPHP,followthesesteps:1.Alwayshashpasswordswithpassword_hash()andverifyusingpassword_verify(),usepreparedstatementstopreventSQLinjection,andstoreuserdatain$_SESSIONafterlogin.2.Implementrole-basedaccessc

Proceduralandobject-orientedprogramming(OOP)inPHPdiffersignificantlyinstructure,reusability,anddatahandling.1.Proceduralprogrammingusesfunctionsorganizedsequentially,suitableforsmallscripts.2.OOPorganizescodeintoclassesandobjects,modelingreal-worlden

PHPdoesnothaveabuilt-inWeakMapbutoffersWeakReferenceforsimilarfunctionality.1.WeakReferenceallowsholdingreferenceswithoutpreventinggarbagecollection.2.Itisusefulforcaching,eventlisteners,andmetadatawithoutaffectingobjectlifecycles.3.YoucansimulateaWe

To safely handle file uploads in PHP, the core is to verify file types, rename files, and restrict permissions. 1. Use finfo_file() to check the real MIME type, and only specific types such as image/jpeg are allowed; 2. Use uniqid() to generate random file names and store them in non-Web root directory; 3. Limit file size through php.ini and HTML forms, and set directory permissions to 0755; 4. Use ClamAV to scan malware to enhance security. These steps effectively prevent security vulnerabilities and ensure that the file upload process is safe and reliable.

Yes, PHP can interact with NoSQL databases like MongoDB and Redis through specific extensions or libraries. First, use the MongoDBPHP driver (installed through PECL or Composer) to create client instances and operate databases and collections, supporting insertion, query, aggregation and other operations; second, use the Predis library or phpredis extension to connect to Redis, perform key-value settings and acquisitions, and recommend phpredis for high-performance scenarios, while Predis is convenient for rapid deployment; both are suitable for production environments and are well-documented.

In PHP, the main difference between == and == is the strictness of type checking. ==Type conversion will be performed before comparison, for example, 5=="5" returns true, and ===Request that the value and type are the same before true will be returned, for example, 5==="5" returns false. In usage scenarios, === is more secure and should be used first, and == is only used when type conversion is required.

The methods of using basic mathematical operations in PHP are as follows: 1. Addition signs support integers and floating-point numbers, and can also be used for variables. String numbers will be automatically converted but not recommended to dependencies; 2. Subtraction signs use - signs, variables are the same, and type conversion is also applicable; 3. Multiplication signs use * signs, which are suitable for numbers and similar strings; 4. Division uses / signs, which need to avoid dividing by zero, and note that the result may be floating-point numbers; 5. Taking the modulus signs can be used to judge odd and even numbers, and when processing negative numbers, the remainder signs are consistent with the dividend. The key to using these operators correctly is to ensure that the data types are clear and the boundary situation is handled well.
