Configure pseudo-static Apache server

Source: Internet
Author: User
Tags apache php php regular expression

Pseudo-static implementation:

(1) rewrite mechanism of Apache

(2) PHP Regular Expression

Exercise the construction of Apache + PHP + MySql

Interview:

Trial:

As a qualified PHP Engineer

Www.baidu.com

Start to build the environment:

Installed version:

Apache 2.2.22

MySQL 5.5.24

PHP 5.3.13

(1) uninstall the previous software

Make sure to stop the service

(2) uninstall

Delete the environment variable:

(3) Installation

Test whether the installation is successful:

(2) install PHP

Because PHP is a module of Apache.

Therefore, PHP is loaded through the Apache configuration file.

Load PHP Module

(2) Tell apache which files need to be parsed using the PHP language

(3) install MySQL

Encoding

Password

Problems during installation:

(1)

Import the previous database to our new environment

Copy the database folder in the data directory of MySQL (do not copy any database that needs to be copied)

(2) MySQL already exists

How to delete a previous service

SC Delete service name

(3) Apache server) (Web Server) ------ Apache server

MySQL (Application Server) ---- MySQL Server

After the software is uninstalled, some systems will automatically uninstall the service, but some systems will not automatically uninstall the service.

If you are prompted that the MySQL service already exists

(1) In Windows, the system administrator opens CMD and SC Delete service name.

(2) If the service cannot be detached, delete the service in the Registry by modifying the registry of the system.

Run ------ Regedit ---- HKEY_LOCAL_MACHINE ----- system ----- CurrentControlSet ----- services

Virtual directory Configuration:

Show our project when accessing www.baidu.com

(1) browser configuration

Modify the hosts file. The principle of domain name resolution is as follows:

Thoughts:

Why can I access www.yibei.com to display files in the project directory?

(1) first go to your local hosts to check whether there is any IP address pointed to by the current domain name. If so, directly access

(2) If you do not directly go to the Internet (DNS service provider), find it. If no error is prompted,

Bluehost Godaddy

China:

Hichina

Registered domain name: Taobao

1. Modify the hosts file first.

IP Address: Server IP address 127.0.0.1 and network IP address 192.168.2.1

127.0.0.1 localhost

127.0.0.1 www.php.com

127.0.0.1 www.sina.com

(2) Server Configuration

Every website can be used as a module to divide and conquer

Modify Apache configuration file

Httpd. conf

Go

# Virtual Hosts

# Include CONF/extra/httpd-vhosts.conf

Remove comments

Find the conf/extra/httpd-vhosts.conf File

Each website corresponds to a module.

<Virtualhost *: 80>

Serveradmin webmaster@dummy-host2.somenet.com

DocumentRoot "D:/myenv/Apache/docs/dummy-host2.somenet.com"

Servername dummy-host2.somenet.com

Errorlog "log/dummy-host2.somenet.com-error.log"

Customlog "logs/dummy-host2.somenet.com-access.log" common

</Virtualhost>

Configure one by yourself:

A module has at least two items:

1. Who is my domain name?

2. Where is the root directory of my website?

<Virtualhost *: 80>

DocumentRoot "D:/myenv/myweb/Sina"

Servername www.sina.com

</Virtualhost>

After the access, the forbbiden permission is displayed.

Modify permissions:

<Directory "D:/myenv/myweb/Sina">

Order deny, allow

Deny from all

Allow from all

</Directory>

Order access order, deny first, and then allow

Deny and allow can also be set.

Allow access from the IP address 127.0.0.1.

Allow from 127.0.0.1

5. Configure the php. ini file so that it can operate MySQL

Why do I need to restart Apache after modifying the PHP configuration file?

Because the php5apache2_2.dll module serves as a bridge between APACHE and PHP.

At the same time, PHP as an Apache module exists

Who are the functions of mysql_connect?

Why can I obtain database data after calling this function?

Because MySQL is an extension of PHP.

By default, the php. ini configuration file is not available,

PHP. ini-development Development Mode

PHP. ini-Production Environment

After modifying PHP. ini, because Apache will read the configuration file of PHP, you need to tell the location of the configuration file of Apache PHP.

Phpinidir D:/myenv/PHP

Next, modify PHP. ini to enable MySQL extension so that the MySQL database can be operated.

Extension = php_mysql.dll

Finally, I will tell PHP where is its extension directory?

So far, the three major companies have been successfully installed

6. How does one implement pseudo-static state through the Apache rewrite mechanism?

Review some virtual hosts

(1) Enable the VM in httpd. conf.

(2) The specific configuration of the VM, each website corresponds to a module

We divide and conquer websites and set different access permissions for each website.

After the VM is enabled, the server reads the directory corresponding to the VM.

Set the welcome page of the website (home page ):

<Ifmodule dir_module>

Directoryindex index.html index. php

</Ifmodule>

Display in sequence

Set Website access permissions:

Anti-leech:

Prevent others from stealing our resources

Configuration inheritance:

Check the configuration of your current VM.

If this item is not configured for the VM

<Directory/>

Options followsymlinks

AllowOverride none

Order deny, allow

Deny from all

</Directory>

(2) pseudo-static

Implemented by the rewrite. So module of Apache

Implementation:

Access: http://www.sina.com/news-id3.html

Actually, the access is:

Http://www.sina.com/news.php? Id = 3

Regular Expressions:

(1) modify the Virtual Host Configuration

1. Restart the httpd. conf module.

Loadmodule rewrite_module modules/mod_rewrite.so

<Directory "D:/myenv/myweb/Sina">

Order deny, allow

Deny from all

Allow from all

# Enable rewrite Engine

Rewriteengine on

# Tell the server to allow URL rewriting

AllowOverride all

# Tell the server to rewrite the rule

# If you want to use the matching result after matching the regular expression, $1 indicates the first child, $2 indicates the second child expression.

Rewriterule ([A-Z] +)-ID (\ d1_0000.html $ 1.php? Id = $2 & type = $1

</Directory>

(2) Add a. htaccess File

Topdvdreview.com

Www.topdvdreview.com

Search

Regular Expression:

How to use regular expressions in PHP

Test. PHP code:

<? PHP

$ STR = "ajfalkkjflakjf888-999-387 lkjaflsajf777-333-123 ";

// Retrieve four consecutive numbers.

$ Reg = "/(\ D) \ D (\ D )/";

// Retrieve 888-999-387

$ Reg = '/(\ D) \ 1 {2}-(\ D) \ 2 {2}-\ D {3 }/';

// $ Reg indicates the regular expression !, $ STR indicates the character to be searched, and $ put the result of result matching into this array

// Description: If this function finds one, it will stop matching.

// Add the matched result to the $ result array: $ result [0] is the string found. $ result [1] is the content of the first subexpression. $ result [2]... $ result [N]

// Preg_match ($ Reg, $ STR, $ result );

// $ Reg indicates the regular expression !, $ STR indicates the character to be searched, and $ put the result of result matching into this array

// Description: This function matches all results.

// Put the matching result into the $ result two-dimensional array: $ result [0] Put all the strings found

// $ Result [1] put each result, for example, $ result [1] [0], into the content of the first subexpression of the first matching result

// Other statements, and so on

// Preg_match_all ($ Reg, $ STR, $ result );

Echo "<PRE> ";

Print_r ($ result );

Echo "</PRE> ";

?>

Questions:

Http: // localhost/content. php/news-sport-id1.html

Retrieve from content. php

Retrieve news sport 1

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.