Install and configure the apache + php + mysql environment in win7

Source: Internet
Author: User
Tags install php on windows mysql connect php session php file upload php website web database

I installed Windows 7 in the past two days. Some time ago, a friend asked me how to install and build the PHP environment in Windows. So I plan to work hard to build the PHP environment step by step, currently, you do not need to use the PHP environment to build software. Here is a detailed tutorial on installing and configuring the PHP + Apache + Mysql environment in Windows 7, hoping to help PHP beginners.

To build a PHP environment in Windows 7, you must first download the PHP code package and the installation package for Apache and Mysql.

PHP version: php-5.3.2-Win32-VC6-x86, VC9 is specifically customized for IIS, VC6 is provided for other WEB service software, such as Apache. I downloaded a ZIP package,

Mysql version: mysql-essential-5.1.45-win32, MySQL Community Server 5.1.45,

Apache version: httpd-2.2.15-win32-x86-openssl-0.9.8m-r2, openssl indicates with openssl module, use openssl to configure SSL secure links for Apache.

Step 1: Install the Apache service in Windows 7.



Apache configuration information

Here, we mainly configure the Network Domain, Server Name, Email address, and port used by the Apache service. The default port is port 80. You can configure it on other ports as needed, you can use the default directory or select the installation directory as needed.

After installing the apache service, enter http: // localhost/in the browser to display It's work! Indicates that the Apache service is successfully installed.

Step 2: Install Mysql in Windows 7.



Install Mysql database and select the installation directory

Click Mysql installer to automatically install Mysql. During this period, you can select the installation directory of the Mysql database as needed.

  Note:: After installing the Mysql database, you need to configure the Mysql database before using PHP for connection. how to configure it will be discussed later.

  Step 3: install PHP on Windows 7.

In fact, it is very simple to install PHP in Windows 7, because my PHP code package, as long as you extract the php-5.3.2-Win32-VC6-x86 and rename the folder php, copy it to the C directory to complete the PHP installation.

  Step 4: configure the PHP environment in Windows 7.

The configuration of the PHP environment on Windows 7 is much simpler than that on Windows XP, and does not need to be copied. rename the ini-development configuration file to php. ini configuration file. Perform the following Configuration:

1. Open the php. ini configuration file and find

1
2
; On windows:
; Extension_dir = "ext"

Change

1
2
; On windows:
Extension_dir = "C:/php/ext"

Specifies the directory of the PHP extension package to call the corresponding DLL file.

2. Because the default PHP does not support automatic connection to Mysql, You need to enable the corresponding extended library functions, such as php_mysql.dll.

1
2
3
4
5
6
7
Extension = php_curl.dll
Extension = php_gd2.dll
Extension = php_mbstring.dll
Extension = php_mysql.dll
Extension = php_pdo_mysql.dll
Extension = php_pdo_odbc.dll
Extension = php_xmlrpc.dll

Remove the semicolon (;) before these extension.

3. Configure the PHP Session Function

When using the session function, we must configure the session file storage directory on the server. Otherwise, the session cannot be used. We need to create a new read/write directory folder on Windows 7, this directory is better independent from the main program directory of the WEB. Here I have created the phpsessiontmp directory on the root directory of the d disk, and then in php. in the ini configuration file, find

1 ; Session. save_path = "/tmp"

Change

1 Session. save_path = "D:/phpsessiontmp"

4. Configure the PHP file upload function
How to compile the PHP file upload function?

Like session, when using the PHP file upload function, we must specify a temporary folder to complete the file upload function. Otherwise, the file upload function will fail, we still need to create a read/write directory folder on Windows 7. Here I have created the phpfileuploadtmp directory on the root directory of drive D, and then in php. in the ini configuration file, find

1 ; Upload_tmp_dir =

Change

1 Upload_tmp_dir = "D:/phpfileuploadtmp"

5. Modify date. timezone. Otherwise, an error will be reported in date when phpinfo is executed:

Warning: phpinfo () [function. phpinfo]…

We need

1 ; Date. timezone =

Change

1 Date. timezone = Asia/Shanghai

You can also click here to learn more about the configuration of PHP. INI.

So far, the php environment configuration on Windows 7 is complete, but it is not enough to complete these configurations. We need Apache to support PHP, therefore, you also need to complete the corresponding PHP configuration in the Apache configuration file.

Step 5: Configure Apache to support PHP

1. Under # LoadModule vhost_alias_module modules/mod_vhost_alias.so, add

1
2
3
LoadModule php5_module "c:/php/php5apache2_2.dll"
PHPIniDir "c:/php"
AddType application/x-httpd-php. php. html. htm

We can see multiple php5apache DLL files under the PHP Directory. Because we are using Apache2.2.15, we certainly need to use php5apache2_2.dll, and then specify the PHP installation directory and program extension.

2. We should know that the directory for executing the WEB main program on the Apache server by default is Apache2.2/htdocs. Therefore, when your WEB main program directory is changed, we need to modify the corresponding Apache configuration.

1 DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"

Change

1 DocumentRoot "D:/PHPWeb"
1 <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">

Change

1 <Directory "D:/PHPWeb">

3. Finally, modify the order of the specific index file. Because the PHP function is configured, index. php is required for priority execution.

1 DirectoryIndex index.html

Change

1 DirectoryIndex index. php index.html

4. Restart the Apache server

Now, the PHP environment configuration on the Apache server is complete. You only need to create a new PHP file in the D:/PHP web directory and write

1
2
3
<?
Phpinfo ();
?>

Enter http: // localhost in the browser to view the specific PHP configuration page, which means that the PHP environment configuration is complete on Window 7.

After configuring the PHP environment on Windows 7, we need to complete the last step of setting up the PHP environment, that is, supporting the Mysql database.

First, configure the Mysql server.

Click Mysql Server Instance Config Wizard in the Mysql Server5.1 menu under the Start menu to complete the Mysql Configuration Wizard.



Select the Mysql server type

I personally think that the first and second items can be selected. If it is only used as a WEB database, the second item is recommended.



Mysql database usage



Select the number of concurrent connections of the Mysql database

Select the number of concurrent connections of Mysql. The first option is the maximum number of 20 concurrent connections, the second option is the maximum number of 500 concurrent connections, and the last option is custom. You can choose one based on your needs.



Select the Mysql service port number, which is generally the default value.



Select the character set of the Mysql database

UTF8 is recommended for general purposes. Otherwise, garbled characters may occur.



Set Mysql as a Windows Service

I will automatically log on to the Mysql service and cancel it. You can select this option. If not, you can use net start mysql to start the Mysql service.



Set the password of the root user of the Mysql database



Execute Mysql service configuration options

The configuration file of the Mysql database is saved in C: \ Program Files \ MySQL Server 5.1 \ my. ini. If there are any changes in the future, you can modify this file.

Now the Mysql database configuration is complete. to verify whether PHP can connect to Mysql, you can create the following code in index. php:


<? Php
$ Connect = mysql_connect ("127.0.0.1", "root", "your mysql Database Password ");
If (! $ Connect)
Echo "Mysql Connect Error !";
Else echo "Welcome to PHP website development tutorial network-www.leapsoul.cn ";
Mysql_close ();
?>

Enter http: // localhost/in the browser and you will see:Welcome to PHP website development tutorial network-www.leapsoul.cnIt indicates that PHP is successfully connected to Mysql.

How to Use localhost to connect to MYSQL5.3 in Windows 7

In Windows 7, when PHP is connected to Mysql, the IP address can only be used by default to connect to Mysql, but localhost cannot be used to connect to Mysql. The solution is to open C: \ Windows \ System32 \ drivers \ etc hosts file

1 #127.0.0.1 localhost

To remove the annotations.

OK. On Windows 7, you can use PHP + Apache + Mysql to build the PHP environment, we can see that setting up the PHP environment on other Windows platforms saves a lot of work, but we should also note the problem of connecting to the Mysql5.3 database on Windows 7. Of course, if you are as lazy as me, you can use Appserv or Xampp to configure the PHP environment.

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.