How to configure the php + Apache + mysql environment in win7

Source: Internet
Author: User
Tags php mysql extension
How to configure the php environment in win7? php + Apache + mysql is an essential element in the configuration process, the following article describes how to configure the php + Apache + mysql environment in win7. it is very popular to be interested in learning the B/S architecture, because the B/S architecture has many advantages, such as: Users only need to have a browser to use, convenient maintenance and upgrade, cross-platform, and so on. This article describes how to configure the development environment of Windows + Apache + PHP + Mysql.


How to configure the php environment in win7? php + Apache + mysql is an essential element in the configuration process. php is responsible for parsing php code, apache is responsible for the server while mysql is the transit station for data interaction.

So how can we configure php + apache + mysql? next, let's take a look at the specific method. the software version will change, so we need to renew it on a regular basis.

Step 1:

Php-5.5.10-Win32-VC11-x64.zip: http://windows.php.net/download/

Httpd-2.4.7-win64-VC11.zip: http://www.apachelounge.com/download/

Mysql-5.6.16-winx64.zip: http://dev.mysql.com/downloads/mysql/

Step 2:

Install apache2.4.7(httpd-2.4.7-win64-vc11.zip)

1. unzip the downloaded installation package: the httpd-2.4.7-win64-VC11.zip will put it in its own installation directory (my Directory D: \ phpEnv \ Apache24)


2. modify the configuration file http. conf (D: \ phpEnv \ Apache24 \ conf \ http. conf)-open it with notepad.

(1) modify the root path of ServerRoot Apache:

(37 rows) ServerRoot "c:/Apache24" changed to => ServerRoot "D:/phpEnv/Apache24"

(2) modify ServerName your host name:

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

(Row 217) ServerName www.example.com: 80 removes the previous #. This attribute is required when Apache is started 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: \ phpEnv \ Apache24 \ htdocs.pdf, which contains a simple access file index.html. You can modify the path by yourself. here, I will configure it in my new folder www (D: \ phpEnv \ www.

(Row 3) DocumentRoot "c:/Apache24/htdocs"


Change to =>

DocumentRoot "D: \ phpEnv \ www"

(4) modify the configuration of the entry File: In general, we use index.php?index.html#index.htm as the entry of the web project. Only index.html needs to be added to the access port of apachetings. of course, the settings of this entry file can be increased or decreased according to your own needs. if the requirements are strict, you can write only one index. php, so the entry in the project can only be index. php

(274 rows)

DirectoryIndex index.html

Change to =>


DirectoryIndex index. php index.htm index.html

(5) set the serverscript Directory:

(Row 3) ScriptAlias/cgi-bin/"c:/Apache24/cgi-bin/" changed to => ScriptAlias/cgi-bin/"D: /phpEnv/Apache24/cgi-bin"

(6) (380 rows)


AllowOverride None
Options None
Require all granted

Change to =>


AllowOverride None
Options None
Require all granted

3. start Apache.

Start --- run, enter cmd, and open the command prompt. Go to the D: \ phpEnv \ Apache24 \ bin directory and press enter ,.

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

Put index.html in the directory of Apache24 \ htdocs.html under the D: \ phpEnv \ www Directory. "It works" appears when accessed by a browser. This means that apache has been correctly installed and started. You can also open a simple index.html file.


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

Close the httpd service first (close the command window)

Open a new command window and go to the D: \ phpEnv \ Apache24 \ bin directory:

The command to add the HTTP service is: httpd.exe-kinstall-n "servicename" servicename is the service name. what I add is: when the httpd.exe-k install-n "Apache24" command is successful, a prompt is displayed. you can view the Apache24 service in the window service startup item.

Click Start. if you do not want to set it to boot, you can change the start type to manual.

If you want to uninstall the service, stop the service first. Then, enter httpd.exe-k uninstall-n "Apache24" to uninstall the service.

Of course, you can also start Apache using apachemonitor.exe under D: \ phpEnv \ Apache24 \ bin.

The Apache configuration is complete.


Install php5.5.10(php-5.5.10-win32-vc11-x64.zip)

1. decompress the downloaded php-5.5.10-win32-vc11-x64.zip file to the installation directory (D: \ phpEnv \ php)

2. copy the php. ini-development file in the directory and change it to php. ini, which is the configuration file of php.

3. add php support for the Apache service

Open the Apache configuration file http. conf and add

# php5 support
LoadModule php5_module “D: /phpEnv/php/php5apache2_4.dll”
AddHandler application / x-httpd-php.php
AddType application / x-httpd-php .html .htm
# configure thepath to php.ini
PHPIniDir "D: / phpEnv / php"
Here I add it below LoadModule

When adding, make sure that your php5apache2_4.dll file does exist in the earlier version of php5.5. There is no such file, but it already exists 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, save it as <? Php phpinfo ();?>, Access to the php information, it means that php has been successfully installed.
Remarks:
Some common configuration changes for Php: (D: \ phpEnv \ php \ php.ini)
Time zone setting: date.timezone = Asia / Shanghai
Error reporting level: error_reporting = E_ALL This can be turned on all in development mode.

Third, install and configure mysql5.6.16 (mysql-5.6.16-winx64.zip)

1.Install mysql

The 64-bit mysql does not find the msi installation package for the time being, so decompress it directly to the installation directory, then configure the relevant environment variables, modify the configuration file, and add the window service. It will not be written here in detail. Paste 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, and datadir is the data storage directory of mysql. I won't explain anything else

There is no graphical user interface after installing mysql. You can install software such as Navicat for MySQL, which will look 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 for php

Open the php configuration file php.ini (D: \ phpEnv \ php \ php.ini)

(1) (line 721); extension_dir = "ext", remove the ";" in front, and change it to extension_dir = "D: \ phpEnv \ php \ ext". Extended support for .dll files, interested students can take a look.

(2) Then open the php mysql extension

(Lines 875, 876) remove the ";"

    extension = php_mysql.dll
    extension = php_mysqli.dll
Of course, you can also open 881 line php_pdo_mysql.dll to enable PHP's pdo support. I generally use this.

Note: There are many expansion options in lines 863 to 888. What you want to use, just remove the ";" in front. 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, then add an extension = ... in the configuration file

Once done, restart Apache

3), start the MySQL service

net start mysql

The MySQL service is starting.
The MySQL service failed to start.

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 blank 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), using the database
mysql> use test
Database changed
7) View the tables in the database
mysql> show tables;
Empty set (0.00 sec)
8), create the 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 results after deletion:

mysql> select * from ttt;
+ ------ + ------ +
| a | b |
+ ------ + ------ +
| 1 | aaa |
| 2 | bbb |
+ ------ + ------ +
2 rows in set (0.00 sec)
12), update the 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 update results:

mysql> select * from ttt;
+ ------ + ------ +
| a | b |
+ ------ + ------ +
| 1 | aaa |
| 2 | xxx |
+ ------ + ------ +
2 rows in set (0.00 sec)
13), delete the 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)
Third, change the password of the MySQL database root user

1.Use mysql database
mysql> use mysql
Database changed
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 to take effect.

net stop mysql

MySQL service is stopping ...
The MySQL service has stopped successfully.

net start mysql
The MySQL service is starting.
The MySQL service has started successfully.

7.Re-login to the MySQL server

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 get a 1067 error that cannot start mysql after changing the password, you can use the following solutions:
Use cmd command: D: \ Appserv \ mysql \ bin \ mysqladmin -uroot -p shutdown, then enter the password, and then net start mysql will not show this error!

Fourth, the creation and deletion of the database

1.Create the database testdb

mysql> create database testdb;
Query OK, 1 row affected (0.02 sec)
2.Use the database testdb

mysql> use testdb;
Database changed
3.Delete the database testdb

mysql> drop database testdb;
Query OK, 0 rows affected (0.00 sec)
4.Log out

mysql> exit
Bye

C: \ Documents and Settings \ Administrator>
Five, the general steps to manipulate database data

1.Start the MySQL server
2. Login to the database server
3. Use a database to operate
4. Operate the tables in the database to perform operations such as adding, deleting, modifying, and checking.
5. Log out.

The above describes the way to configure php + Apache + mysql environment in win7 system, I hope everyone likes it.

Related Article

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.