How to set up php mysql server

PHPz
Release: 2023-03-29 10:32:07
Original
1050 people have browsed it

In today's Internet era, PHP and MySQL technologies have become the technical basis for many website services. Especially for those who want to engage in website development and operation and maintenance, it is essential to be familiar with PHP and MySQL and have server deployment capabilities. It's important. Therefore, in this article, we will introduce how to set up PHP and MySQL servers.

1. Preparation

Before setting up PHP and MySQL servers, we need to install some software. First is the Apache HTTP server software, followed by the PHP parser and the MySQL software package. These softwares are free and can be downloaded from the official website. In order to ensure that the software can be used normally, we need to select the software package corresponding to the version and bit number of our own operating system to download.

After the download is completed, we need to install the Apache HTTP server first, and then install the PHP parser and MySQL software package. During the installation process, you need to pay attention to some related configuration options, such as the root directory of the Apache HTTP server, configuration options of the PHP parser, etc.

2. Configure the Apache server

1. Modify the Apache service port number

Apache uses port 80 for Internet communication by default, but when we build the server locally, the port may be It is occupied by other programs and causes the Apache server to not work properly. Therefore, we need to change the port number of the Apache server. The specific steps are as follows:

Find the apache configuration file httpd.conf, located in {apache installation path}\conf\httpd.conf
Find Listen 80, and change 80 to another unoccupied port. For example 8888
Save the changes and restart the Apache server

2. Configure the Apache directory index

We need to enable the directory index in the Apache configuration file httpd.conf to facilitate our View the directory where the project is located in the browser. The specific steps are as follows:

Find the httpd.conf file, located in {apache installation path}\conf\httpd.conf
Find LoadModule autoindex_module modules/mod_autoindex.so, and remove the # symbol in front
Find Options Indexes FollowSymLinks, remove the # symbol in front of Indexes
Restart the Apache server

3. Configure PHP

Configuring the PHP program in the Apache server includes two aspects, one is Apache Interact with PHP directly through PHP modules, and one is to interact with PHP through CGI (Common Gateway Interface) mode.

1. Module mode

Module mode is the best way to interact between Apache and PHP. The specific steps are as follows:

Find the httpd.conf file, located in {apache installation path}\conf\httpd.conf
Find LoadModule php7_module {php installation path}\php7apache2_4.dll, remove the # comment, and enable it Module
Find AddHandler application/x-httpd-php .php, remove the # comment, enable apache module mode
Find PHPiniDir "{php installation path}", remove the # comment, and specify the location of the php.ini file
Restart the Apache server

2.CGI mode

CGI mode is an alternative way of interaction between Apache and PHP. The specific steps are as follows:

Find the httpd.conf file, located in {apache installation path}\conf\httpd.conf
Find ScriptAlias ​​/cgi-bin/ "{php installation path}\cgi-bin\ ", set the path where the CGI script is stored
Find AddType application/x-httpd-php .php, remove the # comment, and allow the PHP script to be parsed
Restart the Apache server

4. Configure MySQL

MySQL is a relational database management system through which we can store and manage data in projects. MySQL configuration includes configuring the connection database, modifying the default port, setting the character set, and creating the database.

1. Configure the connection to the MySQL server

The relevant configuration parameters for connecting to the MySQL server can be found in the my.ini file in the MySQL installation directory.

[client]
port=3306
default-character-set=utf8

2. Modify the MySQL default port

If the MySQL default port number (3306 ) is occupied, we need to modify it to another port that is not occupied. There are two ways to modify the default port: directly edit the MySQL configuration file or use the system tools officially provided by MySQL to modify it.

Method 1: Directly edit the MySQL configuration file my.ini. Find the following code:

The MySQL server

[mysqld]
port=3306
modify port=Other port number

Method 2: Use MySQL official provider Modify using the modification tool (MySQL Notifier). The specific operations are as follows:

Download the MySQL Notifier tool
Start the MySQL Notifier tool and select the corresponding MySQL server
In the server configuration page, find the network tab
In this page, you can modify it The port number of MySQL, and then click the "Save" button

3. Set the MySQL character set

If there are Chinese or other non-English characters in the database, you need to set the MySQL character set. The specific steps are as follows:

Find the my.ini file, located in {MySQL installation path}\my.ini
Find the [mysqld] line and add character-set-server=utf8 in the next line
Restart MySQL server

4. Create database

If you need to create a database in MySQL server, we can run the following command to complete the task:

Connect to MySQL server

mysql -u root -p

Create a new database

create database db_name;

Display database list

show databases;

5. Summary

The above are the specific steps to build PHP and MySQL servers. By following the above steps, you can quickly build and build this service yourself. In actual operation, you need to pay attention to some security and stability issues to ensure that there are no problems with your self-built server.

The above is the detailed content of How to set up php mysql server. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template