Home >Backend Development >PHP Tutorial >How to configure the php-Apache-mysql environment under win7 system

How to configure the php-Apache-mysql environment under win7 system

WBOY
WBOYOriginal
2016-07-30 13:31:061054browse

How to configure the php environment under win7 system? php+Apache+mysql are all essential elements in the configuration process. php is responsible for parsing the php code, apache is responsible for the server side and mysql is the transfer station for data interaction.

So how to configure php+apache+mysql? Next, let’s take a look at the specific method. The software version will change, so you need to adapt to the times and adapt to changes.

Step one:

php-5.5.10-Win32-VC11-x64.zip Download address: http://windows.php.net/download/
httpd-2.4.7-win64-VC11.zip Download address : http://www.apachelounge.com/download/
mysql-5.6.16-winx64.zip Download address: http://dev.mysql.com/downloads/mysql/

Step 2:

Installation Configure Apache2.4.7 (httpd-2.4.7-win64-VC11.zip)

1. Unzip the downloaded installation package: httpd-2.4.7-win64-VC11.zip and put it in your own installation directory (my directory D:phpEnvApache24)

2.Then modify the http.conf (D:phpEnvApache24confhttp.conf) configuration file - just open it with Notepad

(1) Modify the root path of ServerRoot Apache:

(Line 37) Change ServerRoot "c:/Apache24" to =>ServerRoot "D:/phpEnv/Apache24"

(2) Modify ServerName to your host name:

If this line is not modified, start apache and prompt Starting httpd : AH00558

                                     (line 217) ServerName www.example.com:80 Remove the # in front. This attribute is needed when starting Apache from the command line.

(3) Modify the main folder directory accessed by DocumentRoot Apache, which is the location of php and html code files. The default path of Apache is under htdocs (D:phpEnvApache24htdocs), which has a simple entry file index.html. This path can be modified by yourself. I configure it here under my own newly created folder www (D: phpEnvwww).

(Line 247) DocumentRoot "c:/Apache24/htdocs"                                                                                                     using using using using                   use through out use out off out way out way out way outmbps outmbps outps out out out outmb right out right out right out right out right out out out out out out out out out out out out out of

''s-'s)                     -                                                

                                      

(4) Modify the entry file configuration: DirectoryIndex. Generally, we use index.php, index.html, and index.htm as the entry points for web projects. Apache's default entry is only index.html, and you need to add support for the other two. Of course, the settings of this entry file can be increased or decreased according to your own needs. If the requirements are stricter, you can only write one index.php, so that the entry in the project is It can only be index.php

(Line 274)

                                                              out way ’ ’ down ’ s ’ s         out through out out out out out out out out out clean out out out out to                           Have using. _module>

DirectoryIndex index.php index .htm index.html

                                                                                                                                                                                                                              ; ScriptAlias/cgi-bin/ "D:/phpEnv/Apache24/cgi-bin"

(6)(line 380)

"

" AllowOverride None

        Options None

          Require all granted

                            out

                                                                                                                                                                                                                      AllowOverride None’s

                                                                                                                                                                                        Require all granted

                       

3. Next you can start Apache

Start---Run, enter cmd, open the command prompt. Then go to the D:phpEnvApache24bin directory and press Enter httpd and press Enter, as shown in the figure.

If no error is reported, you can test it (keep the command window open).

Put the index.html in the Apache24htdocs directory into the D:phpEnvwww directory. If you access it with a browser, "It works" will appear, which means that apache has been correctly installed and started. You can also write a simple index.html file yourself and open it.

4. Add Apache to the window service startup item and set it to start at boot

Close the httpd service first (just close the command window)

Reopen a new command window and enter D:phpEnvApache24bin Catalog:

The command to add HTTP service is: httpd.exe -kinstall -n "servicename" servicename is the name of the service. What I added is: httpd.exe -k install -n "Apache24". After the command is successful, there will be a success prompt. This You can see the Apache24 service in the window service startup item and click Start. If you don’t want to set it to startup, you can also change the startup type to manual.

If you want to uninstall this service, you must first stop the service, and then enter httpd.exe -k uninstall -n "Apache24" to uninstall the service.

Of course, you can also start Apache through ApacheMonitor.exe under D:phpEnvApache24bin. I won’t go into details here.

In this way, the configuration of Apache is basically completed.

2. Install and configure php5.5.10 (php-5.5.10-Win32-VC11-x64.zip)

1. Unzip the downloaded php-5.5.10-Win32-VC11-x64.zip to Mine is (D:phpEnvphp) in the installation directory

2. Copy the php.ini-development file in the directory and rename it to php.ini. It is the configuration file of php

3. Add php support to the Apache service

Open Apache’s configuration file http.conf and add

# php5 support

LoadModule php5_module “D:/phpEnv/php/php5apache2_4.dll” at the end

AddHandler application/x-httpd-php .php

AddType application /x-httpd-php .html .htm


# configure thepath to php.ini

PHPIniDir "D:/phpEnv/php"

I added it under LoadModule

When adding, make sure your php5apache2_4.dll The file does exist. There is no such file in the early version of php5.5, but it is already there in the higher version. You can open the php installation directory to find this file

PHPIniDir "D:/phpEnv/php" This is your php Root directory

4. Restart the Apache server.
5. Test. Delete other files in www, create a new index.php with the content of Save it. When accessing the php information, it means that php has been successfully installed.

Remarks:
Some common configuration modifications of Php: (D:phpEnvphpphp.ini)
Time zone setting: date.timezone = Asia/Shanghai
Error reporting level: error_reporting = E_ALL This can be turned on in development mode.

3. Install and configure mysql5.6.16 (mysql-5.6.16-winx64.zip)

1. Install mysql

The 64-bit mysql has not found the msi installation package for the time being, so unzip it directly to the installation directory. Then configure the relevant environment variables, modify the configuration file, and add the window service. I won’t go into details here. Post my configuration file here for your reference:

[mysqld]

loose-default-character-set = utf8

basedir = D:/program/mysql-5.6

datadir = D:/program/ mysql-5.6/data

 port = 3306

 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 character_set_server = utf8

 [client]

loose-default-character-set = utf8

Note: basedir is the root directory of mysql, datadir Is the data storage directory of mysql. I won’t explain the rest.

After installing mysql, there is no graphical user interface. You can install software such as Navicat for MySQL, which will seem more convenient.

Register mysql as a service: mysqld.exe --install mysql

Remove the mysql service: mysqld.exe --remove mysql

2. After installing mysql, add mysql support to php

Open the php configuration File php.ini (D:phpEnvphpphp.ini)

(1) (line 721); extension_dir = "ext", remove the previous ";" and change it to extension_dir = "D:phpEnvphpext" to open php extension support, There are many PHP extension support .dll files in the ext folder. Interested students can take a look.

(2) Then open the mysql extension of php

 (lines 875, 876) and remove the ";" in front

      extension=php_mysql.dll

       81 lines I usually use php_pdo_mysql.dll to enable php's pdo support.

Note: There are many expansion options on lines 863 to 888. Whatever you want to use, just remove the ";" in front of it. Of course, if you want to add other extension support such as redis support, PHP itself may not provide the corresponding dll file. You need to find the corresponding version of the dll and add it to the ext folder, and then add an extension=...

in the configuration file. After completion, restart Apache

3), start MySQL service
net start mysql
MySQL service is starting .
MySQL service cannot be started.
4), log in to the MySQL server
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.1.32-community MySQL Community Edition (GPL)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
Note: The MySQL administrator username is root, and the password is empty by default.
5), view the database
mysql> show databases;
+------------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.02 sec)
You can see that there are three databases in the MySQL server.
6), use database
mysql> use test
Database changed
7), view the tables in the database
mysql> show tables;
Empty set (0.00 sec)
8), create table ttt
mysql> create table ttt(a int,b varchar(20));
Query OK, 0 rows affected (0.00 sec)
9), insert three pieces of data
mysql> insert into ttt values(1,'aaa');
Query OK, 1 row affected (0.02 sec)
mysql> insert into ttt values(2,'bbb');
Query OK, 1 row affected (0.00 sec)
mysql> insert into ttt values(3,'ccc');
Query OK, 1 row affected (0.00 sec)
10), query data
mysql> select * from ttt;
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | bbb |
| 3 | ccc |
+------+------+
3 rows in set (0.00 sec)
11), delete data
mysql> delete from ttt where a=3;
Query OK, 1 row affected (0.01 sec)
Query operation result after deletion:
mysql> select * from ttt;
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | bbb |
+------+------+
2 rows in set (0.00 sec)
12), update data
mysql> update ttt set b = 'xxx' where a =2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
View updated results:
mysql> select * from ttt;
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | xxx |
+------+------+
2 rows in set (0.00 sec)
13), delete table
mysql> drop table ttt;
Query OK, 0 rows affected (0.00 sec)
View the remaining tables in the database:
mysql> show tables;
Empty set (0.00 sec)
3. Change the password of the MySQL database root user
1. Use the mysql database
mysql> use mysql
Database changed
2. View all tables in the mysql database
mysql>show tables;
+--------------------------+
| Tables_in_mysql |
+--------------------------+
| columns_priv |
| db |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| proc |
| procs_priv |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+--------------------------+
17 rows in set (0.00 sec)
3. Delete all data in the user table in the mysql database
mysql> delete from user;
Query OK, 3 rows affected (0.00 sec)
4. Create a root user with the password "xiaohui".
mysql>grant all on *.* to root@'%' identified by 'xiaohui' with grant option;
Query OK, 0 rows affected (0.02 sec)
5. View the users in the user table
mysql> select User from user;
+------+
| User |
+------+
| root |
+------+
1 row in set (0.00 sec)
6. Restart MySQL: After changing the MySQL user, you need to restart the MySQL server for it to take effect.
net stop mysql
MySQL service is stopping..
MySQL Service stopped successfully.
net start mysql
MySQL service is starting .
MySQL service has been started successfully.
7. Log in to the MySQL server again
mysql -uroot -pxiaohui
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.1.32-community MySQL Community Edition (GPL)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
If you change the password, net startmysql error 1067 cannot start mysql, you can use the following methods to solve it:
Use cmd command: D:Appservmysqlbinmysqladmin -uroot -p shutdown, then enter the password, and then net start mysql There is no such error message anymore!
4. Creation and deletion of database
1. Create database testdb
mysql> create database testdb;
Query OK, 1 row affected (0.02 sec)
2. Use database testdb
mysql> use testdb;
Database changed
3. Delete database testdb
mysql> drop database testdb;
Query OK, 0 rows affected (0.00 sec)
4. Log out
mysql>exit
Bye
C:Documents and SettingsAdministrator>
5. General steps for operating database data
1. Start the MySQL server
2. Log in to the database server
3. Use a database to be operated
4. Operate the tables in the database, and you can perform various additions, deletions, modifications and queries operate.
5. Log out.

The above introduces how to configure the php-Apache-mysql environment under win7 system, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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