Php runtime environment configuration

Source: Internet
Author: User
Tags apache php php software
Server: web server. Our web requests are generally based on the http protocol. So sometimes we call web servers an http server. This is because the server we set up needs to provide a purpose for other users to obtain resources through web (http) requests. Starting from php: Programming language web (website construction) as a websiteNetwork programming language. C/s client server B/s browser server our website requests are all browser-based. What role does PHP play in the B/s architecture? It is neither a browser nor a server. Yes: the program language running on the server can help us manage resources on the server. How to build a B/S project: Browser: (usually set up by yourself) server: web server. Our web requests are generally based on the http protocol. So sometimes we call web servers an http server. This is because the server we set up needs to provide a purpose for other users to obtain resources through web (http) requests. What kind of computer can act as a server: What is the position of a computer? Is it browser or server? It is not determined by the hardware on the computer, but by the software on the computer. If a computer is installed with server software (software that provides certain services), it can be called a server. Lamp: Linux apache mysql php: Apache: is a web server software Mysql: is a database software, data is the core of the project. PHP: it is a programming language that can be used to manage data in the database and show the data managed and planned to the users (browser users ). B/S request: request. The browser sends data to the server, notifying the server that a certain resource is required. This process is the request process. Response: response. the server sends data to the browser. After the server receives a request from the browser, it processes the request and sends the result to the browser. In the B/S architecture, any interaction between the browser and the server requires the process of first request and then response. In the request response mode: The browser can send a request: who can receive and process the request? During apache request processing, apache calls php to operate resources on the server. Building a web server (apache) server software is not apache itself: the best combination of iis and PHP on Windows is apache software. Official website: http://www.apache.org/ Download the apache version:
During installation, you need to set the server information:
We use custom installation to see which configuration items can be used: set the following installation location:
Install to start installation. after installation is complete, enter: Localhost in the address bar of the browser. if the following interface can be found, it indicates that apache has been installed successfully: http server. The following describes how the http server can process php files. Install php software: official website: Introduction to the www. php. netPhp version? 5. x indicates that php software has a good development version. The larger the number, the newer it is. We recommend that you download the latest stable version. Windows is divided into vc6 and vc9 versions. It refers to different php source code compiler versions, where vc6 refers to php compiled by vc 6.0 and vc9 is compiled by vs2008. In general, if php and apache are used together on windows, the vc6 version of php is required. Php and iis usually use the vc9 version of php. Because apache is compiled using vc6. However, vc6 is no longer available in php 5.3.x. Therefore, when you use the new version of php, you need to install the basic compilation class library of vc2008 on your computer. We usually use php as a tool for apache. Use php as a module of apache. Generally, php installation refers to the installation of php into an apache module. Download the corresponding version: You do not need to install it. you need to decompress the configuration and copy it to the installation directory:
Configure the relationship between php and apache: by modifying the apache configuration file: Apache configuration file installation directory/conf/httpd. confE:/amp/apache/conf/httpd. use the apache command LoadModule in the conf configuration file.
LoadModule module name module address: Httpd. conf file: apache now has a tool called php. You also need to configure when to call this tool. You must call this tool to complete parsing only when the suffix of the requested file is. php. The execution segment is used. In Httpd. conf: restart apache to make apache configuration file take effect:
Thinking: what should we do if the current php file needs to be written to the htm file due to some special requirements? Match the corresponding file. An AddHander problem:
Our apache has configuration files, and our php also has configuration files. The name of our php configuration file is php. ini. What should we do if we need to load our configuration file? 1. php. ini to the specified directory; c:/windows 2 or php. ini is placed in the location you want to place. in this case, you need to change the php configuration file directory to achieve the effect. this is usually the second method. put the php configuration file in the php Directory: because php is already an apache module. ini is used by the php module, but apache is responsible for loading. You need to modify the apache configuration to change the configuration file directory of the php module. Use apache's PHPIniDir command for configuration.
Put the configuration file in the specified directory:
In this way, the file directory will be loaded to the current php. ini configuration file:
We use the php configuration file, but if we modify the php configuration file, we also need to restart the apache configuration to take effect. After php is installed, some basic PHP configurations need to be configured: Extension_dir: extension directory: Time zone: install MySQLMySQL is the database server software. This means that mysql can provide database services. Download MySQL www.mysql.com on the local machine: the corresponding version: Select a custom installation method to see what can be configured
Set Directory:
Click install to start the installation. when the following interface is displayed, it indicates that the MySQL program has been successfully installed. However, you need to set the MySQL server before the first use: generally, this configuration mainly configures mysql Users and permissions.
Start configuring MySQL: it is best to set the encoding to utf8.
We recommend that you write the mysql directory to a path with the environment changed:
Set the password of the root user of MySQL: 1234 abcd to start configuring the system: The following figure shows that the configuration is successful ,:
View mysql installation:
After successful installation, mysql installs the server and client. In the MySQL installation directory:
Therefore, when we use php to operate databases in the future, php will exist as a client to connect to the MysQL server.
Currently, MysQL has been installed on our computer. The next step is to use our PHP to operate MySQL: Step 1: enable MysQL extension: 1, you need to properly expand the file.
The above file is a basic mysql extension file. 2. use the extension command to load the extension file. You need to set the correct extension_dir extension file and use the extension command to load the corresponding extension:
Need to restart apache to make it take effect? We can use phpinfo () to check whether the shelf is successful. if you can see the following interface: where are the configuration files of Apache php and MySQL? Apache: Apache/conf/httpd. confPhp: php/php. iniMysql: mysql/my. ini is called my on windows. ini linux is called my. in the next php test, we have two test sites: one: test, which is used to save some test code: shop to simulate a simple shop project. Therefore, the test code of each project should be stored in the directory of each project.
Although the directory is different, the access method is: Test: localhost/testShop: localhost/shop. What does the same domain name mean in real projects? This means that there is only one domain name for the two projects, but only a different sub-directory. In general, different projects should have different domain names: Shop: kang. shop. comTest kang.test.com
Apache virtual host configuration: virtual host: we need to establish multiple external hosts on the same apache server. Assume the VM. Host: ip-based virtual host: a computer must have multiple IP addresses at the same time. Domain name-based VM: the access addresses of different projects are different, but the IP addresses are the same. If you need to configure a domain name-based virtual host, you need to modify the apache configuration file to achieve the effect! In the Apache configuration file, use the httpd-vhosts.conf file to centrally manage virtual hosts. We recommend that you do not write the configuration of our VM in httpd. conf, but in the centralized configuration file of the VM. All you need to do is remove the comments of the following line of code: Httpd. conf configuration file.
 
Before modifying the configuration file: adding a virtual host requires two aspects: 1. for server configuration, you need to use apache to add a virtual host and let httpd first. the conf configuration file loads the centralized configuration file of the VM :,
Find the centralized configuration file of the VM: 1 and add a NameVirtualHost *: 80. Generally, this configuration is written to make it effective for all VM instances. 2. each VM is configured by a command segment. 3. the command "ServerName" in the VM indicates that the domain name of the VM, DocumentRoot, indicates that the root directory of the VM is used to restart the server. 2. the configuration of the browser requires the browser to find the machine where the VM is located. If we cannot access our virtual domain name through a browser, it means we can. Can the current browser locate the server? It is actually the process of configuring ip resolution through domain names. Use the domain name resolution file in windows to complete:
Next we will map kang.shop.com and kang.test.com to the cost machine respectively: the above operations have completed the most basic configuration of the VM: permission configuration: Create a vm again
Kang.frame.com e:/amp/sites/frame server: add a virtual host: restart apache: Browser: add a domain name resolution::
The reason for this result is: The project is saved in different locations:, Test shop e:/apache/htdocsFrame e: /amp/sites/do all projects have to be placed in the htdocs directory? No. However, you need to manually configure directory permissions. By default, two configurations work: the preceding command indicates that if we do not set special permissions for a directory, use the permission configuration in this configuration segment. Is a default configuration. Section 2:
 
The meaning of the above code: configure the directory option e:/amp/apache/htdocs. Therefore, both the test and shop projects follow the configuration of allow from all in the second section, while the frame project follows the configuration of deny from all in the first section. If we need to solve this problem, we can modify: in the first section: This will allow all directories

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.