How to configure the php + Apache + mysql environment in win7 system _ php instance

Source: Internet
Author: User
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 under LoadModule

Make sure that the php5apache2_4.dll file exists in the php5.5 earlier version, but the file is already available in the later version. You can open the php installation directory to find the file.

PHPIniDir "D:/phpEnv/php". This is your php root directory.


4. Restart the Apache server.

5. Test.

Delete other files in www and create an index. php file. The content is <? Php phpinfo ();?> Save. Accessing the php information indicates that php has been successfully installed.

Note:

Some common Php configuration changes: (D: \ phpEnv \ php. ini)

Time zone settings: date. timezone = Asia/Shanghai

Error Report Level: error_reporting = E_ALL, which can be enabled in development mode.

Install mysql5.6.16(mysql-5.6.16-winx64.zip)

1. Install mysql

64-bit mysql does not find the msi installation package. Therefore, extract the package to the installation directory, configure the related environment variables, modify the configuration file, and add the window service, this is not detailed here. Here I will post my configuration file 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 will not explain anything else.

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

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

Delete 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. ini)

(1) (721 rows); extension_dir = "ext", remove the previous ";" and change it to extension_dir = "D: \ phpEnv \ php \ ext "enables php extension support. There are many php extension support in the ext folder. dll file. If you are interested, you can take a look.

(2) then the mysql extension of php is enabled.

(Rows 875 and 876) Remove the preceding ";"


   extension=php_mysql.dll
    extension=php_mysqli.dll


Of course, you can also enable php_pdo_mysql.dll in line 1 to enable php's pdo support.

Note: There are a lot of expansion options between lines 863rd and 888th. If you want to use them, just remove the previous. Of course, if you want to add other extension support such as redis support, php may not provide the corresponding dll file, you need to find the corresponding version of dll and add it to the ext folder, then add an extension =... in the configuration file...

Restart Apache

3) Start the MySQL Service

Net start mysql

MySQL service is starting.
The MySQL service cannot be started.

4) log on 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)


The MySQL server has three databases.

6) use the database


mysql> use test
Database changed


7) View tables in the database


mysql> show tables;
Empty set (0.00 sec)


8) create a table ttt


mysql> create table ttt(a int,b varchar(20)); 
Query OK, 0 rows affected (0.00 sec)


9) insert three data items


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 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 the update result:


mysql> select * from ttt; 
+------+------+
| a | b |
+------+------+
| 1 | aaa |
| 2 | xxx |
+------+------+
2 rows in set (0.00 sec)


13) delete a 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 root user of the MySQL database

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 user table data in 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 users in the user table


mysql> select User from user; 
+------+
| User |
+------+
| root |
+------+
1 row in set (0.00 sec)


6. Restart MySQL: After the MySQL user is changed, the MySQL server needs to be restarted to take effect.

Net stop mysql

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

Net start mysql
MySQL service is starting.
The MySQL service has been started successfully.

7. log on 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 the "net startmysql" 1067 error cannot be started after the password is changed, you can use the following solution:
Run the cmd command: D: \ Appserv \ mysql \ bin \ mysqladmin-uroot-p shutdown, enter the password, and then run the net start mysql command!

Iv. Create and delete Databases

1. Create a 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>


5. General steps for operating database data

1. Start the MySQL server

2. log on to the Database Server

3. Use a database to be operated

4. Operate the tables in the database and perform addition, deletion, modification, and query operations.

5. log out.

The above describes how to configure the php + Apache + mysql environment in win7.

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.

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.