PHP study notes: server deployment and configuration
1. Introduction
Before developing PHP, you need to deploy and configure the server to ensure that PHP The code runs normally. This article will introduce how to deploy and configure the server, and provide specific code examples.
2. Server deployment
Step 2: Configure the Apache server. The configuration file is located in the httpd.conf file in the conf folder under the Apache installation directory. This file can be opened with a text editor for modification.
(1) Configure the listening port. Find the "Listen" configuration item and modify it to the required port number. The default is 80.
(2) Configure the default website directory. Find the "DocumentRoot" configuration item and set it to the root directory path of your website. For example, set it to "D:/www".
(3) Configure virtual host. Add the following code at the end of the configuration file:
DocumentRoot "D:/www" ServerName localhost
Note: If you need to deploy multiple websites, you can add multiple virtual Host configuration.
3. PHP configuration
Step 2: Configure PHP parser. Open the configuration file httpd.conf of the Apache server, find the following code and uncomment it:
Step 3: Add the PHP parser installation path to the system environment variable Path so that php commands can be used directly on the command line.
Step 2: Modify the configuration. Use a text editor to open the php.ini file and modify the following configuration items as needed:
(1) Modify the time zone: Find the "date.timezone" configuration item and modify it according to your own time zone.
(2) Turn on error prompts: Find the "display_errors" configuration item and set it to On so that you can see error prompts during development and debugging.
(3) Enable the extension module: Find the configuration item of ";extension=xxxx" (xxxx represents the module name), and remove the preceding semicolon to enable the corresponding extension module. For example, enable the MySQL extension module and change ";extension=mysqli" to "extension=mysqli".
4. Code Example
In order to verify whether the PHP code can run correctly, a simple PHP code example is provided below.
5. Summary
This article introduces how to deploy and configure the PHP server, and provides specific code examples. Through these steps, you can easily run PHP code on your server, providing a good environment for development. At the same time, it is also recommended to further study and configure the server according to actual needs to meet more needs.
The above is the detailed content of PHP study notes: server deployment and configuration. For more information, please follow other related articles on the PHP Chinese website!