Set up a php development environment using apache in windows

Source: Internet
Author: User
Tags php session php development environment php file upload php website utc greenwich vc9 zip extension mysql login

Set up a php development environment using apache in windows

This article describes how to use Apache2.2.21/PHP5.3.5/mysql5.19/phpMyAdmin3.4.9 to build a php development environment in Windows2003.

Step 1: Download the installed file

1. Apache version httpd-2.2.21-win32-x86-no_ssl.msi.

2. MySQL version mysql-5.5.19-win32.msi.

3. PHP version of

4. phpMyadmin version


1. We recommend that you select an Apache version without SSL functionality to complete development, so we use Apache 2.2.21-win32-x86-no ssl. msi here.

2. Install MySQL under Windows select. msi installation package format, we select the mysql-5.5.19-win32.msi, double-click according to the Wizard to install, simple and convenient.

3. php we choose to use Windows. Zip, In terms of security and performance, both the zip version is good, and generally the server is installed with this version.

Do not download the default or VC9 version, because VC9 is customized for IIS, and VC6 is provided for Apache or other WEB service software.

4. phpMyAdmin is an online MySQL management tool based on PHP. The PHP environment required for phpMyAdmin3 installation must be at least PHP5.2 and MySQL 5 or later. We have met the requirements here.

Step 2: Install the file

1. Create a folder on the disk to be installed. To facilitate management, create a WAMP folder under the root directory of drive D. D: \ WAMP (WAMP is short for windows + apache + mysql + php ).

2. Create a WWW folder under the WAMP folder to store your PHP website programs. D: \ WAMP \ WWW.

3. Install the Apache server and install the Apache server in the D: \ WAMP \ Apache folder. For details about how to install Apache, refer to the Apache installation diagram.

4. decompress the downloaded php-5.3.5-Win32-VC6-x86 to the d: \ WAMP \ PHP folder.

5. Install the MySql database and install MySQL in the D: \ WAMP \ MySQL folder. For details about the MySQL installation process, refer to the MySQL installation diagram.

6. Decompress, rename it phpMyAdmin, and copy it to the PHP website program directory. The result is D: \ WAMP \ WWW \ phpMyAdmin.

Step 3: Configure Apache

Use the text editing tool (EditPlus recommended) to open D: \ WAMP \ Apache \ conf \ httpd. conf file, which is the Apache configuration file. The following steps are all about modifying the file content.

Note that you must restart the Apache service after modifying the httpd. conf file. The new settings will take effect.

1. Set the listening port

Open the httpd. conf file, find the Listen (probably in the 46th rows), and change the number following it to 8080, as shown below:

Listen 8080.

This parameter is used to set the listening port of the Apache server. The default value is 80. To avoid conflict with the IIS port number in Windows 8080, you can use the default port number 80 if you have not enabled IIS.

2. Let Apache load the PHP Module

Find # LoadModule vhost_alias_module modules/ (approximately 128th rows) and add the following content after this line:

LoadModule php5_module "D:/WAMP/PHP/php5apache2_2.dll" AddType application/x-httpd-php .php PHPIniDir "D:/WAMP/PHP"LoadModule php5_module "D:/WAMP/PHP/php5apache2_2.dll"

This statement loads the PHP5 module in module mode.

AddType application/x-httpd-php .php

The file with the. php extension is executed as a php script. You can use any other extensions you like, such as. html,. php5, or even. txt, to execute PHP.


This statement is used to specify the directory where the PHP configuration file php. ini is located.

If Apache 2 runs php5 in the module mode, you can use the PHPIniDir command.

3. Modify the website storage directory

We know that the default website directory of Apache is the htdocs folder under the Apache installation directory. When you change the website storage directory, you must modify the corresponding Apache configuration.

In the configuration file httpd. conf, find DocumentRoot (probably in line 182) and change it to the correct folder pointing to the website directory. Here we change

DocumentRoot "D:/WAMP/www"

At the same time, find This shoshould be changed to whatever you set DocumentRoot to (approximately 207 rows), and there is a line under it <Directoy default DocumentRoot>, modify the DocumentRoot path configured for you. Here we modify it:

 <Directory "D:/WAMP/www">

4. Modify the home page file of the Directory

In the configuration file httpd. conf, find DirectoryIndex index.html (approximately 244 rows) and change it:

DirectoryIndex index.html index.htm index.php

DirectoryIndex refers to the default file executed by Apache when the client browser accesses a directory.

Take our modification as an example: when a user clicks a directory, apachewill Go To The index.html under the directory. If no index.htm is available, no index. php is available. If none of them are found, the file list in this directory is displayed by default. Reference: to prevent Apache from displaying the file list

Step 4: Configure PHP

Open the PHP installation directory, that is, D: \ WAMP \ PHP. We can see that the directory contains two such files: php. ini-development and php. ini-production: the first is the configuration file used for development, and the second is the configuration of the production environment. Because we develop on the local machine, select the former. Copy php. ini-development to the same directory and rename it php. ini. This php. ini is the configuration file currently in use. The following steps are to modify the content of this php. ini file. Note that after modifying the php. ini file, you need to restart the Apache service to make the new settings take effect.

1. Specify the directory for storing the PHP extension Library

In Windows, PHP extension libraries are usually stored in the ext directory of PHP in the form of DLL.
Use a text tool to open the php. ini file and find extension_dir = "ext" (approximately 809 rows), that is, the line under On windows. Replace the Semicolon ";" in front of it with the following:

 extension_dir = "D:/WAMP/PHP/ext"

Extension_dir indicates the directory of the PHP extension library to call the corresponding DLL file.

2. Enable the corresponding extension Library

By default, many PHP extension libraries are closed. For example, PHP does not support connection to the Mysql database by default, You need to enable the corresponding extension libraries.
Here we start some common extension libraries.

Search; Windows Extensions (approximately 941 rows), under which is the extension list.

Find the following extension:

;extension=php_curl.dll ;extension=php_gd2.dll ;extension=php_mbstring.dll ;extension=php_exif.dll ;extension=php_mysql.dll ;extension=php_mysqli.dll ;extension=php_pdo_mysql.dll ;extension=php_pdo_odbc.dll ;extension=php_sockets.dll ;extension=php_xmlrpc.dll ;extension=php_xsl.dll

Remove the Semicolon ";" before the extension. If you want to load other extension modules in the same way, just remove the semicolon.

Tip 1: When Apache is restarted, the system prompts "unable to load dynamic library... php_curl.dll". An error occurred while loading php_curl.dll. The solution is to copy libeay32.dll and ssleay32.dll under the PHP Directory to the windows directory or the windows/system32 directory, as long as it is the Path included in the system Path environment variable. If you do not want to copy the file, you can directly put the PHP Path in the system Path environment variable. Right-click my computer and choose Properties> advanced> environment variable => Path in the system variable. Double-click it and add a semicolon (;) to your PHP Path. "Before (; D: \ WAMP \ PHP), add it to OK. Restart Apache.

Tip 2: Exif extension is used to display the exif information of an image. Because the extension requires the support of mbstring. dll, the line extension = php_exif.dll must be written to the end of extension = php_mbstring.dll.

Tip 3: If the extension library that comes with PHP cannot meet your needs, you can go to to find and download the library you need. Windows users can go to or the to download the compiled DLL file, you can also go to the to load the PECL collection compressed package.

Tip 4: Many people are looking for php_zip.dll. In fact, the zip extension has been integrated since php5.3 and can be used directly. You can use <? Php phpinfo ()?> Find the zip extension description.

3. Allow PHP to support short labels

In the php. ini configuration file, search for short_open_tag = Off (approximately in line 266) and change it to: short_open_tag = On to support short labels.
Php code is generally included in <? Php...?> After short_open_tag = On is set, it can be written in a more concise form: <? ...?>.

4. Configure the PHP Session Function

When using the session function, we must configure the session file storage directory on the server. We need to create a read/write directory for the session, which is better independent from the website directory.

The directory is built on D: \ WAMP \ sessiontmp, and then in php. ini configuration file; session. save_path = "/tmp" (approximately 1467 rows), remove the Semicolon ";" and change it to the following:

 session.save_path = "D:/WAMP/sessiontmp"

5. Configure 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.
Create a readable directory folder D: \ WAMP \ fileuploadtmp, and find it in the php. ini configuration file; upload_tmp_dir = (approximately 875 rows), and change it:

 upload_tmp_dir = "D:/WAMP/fileuploadtmp"

PHP uploads files up to 2 MB by default. to upload files larger than 2 MB, see configure php. ini to upload files.

6. Set the time zone

Search for the php. ini configuration file; date. timezone = (approximately 993 rows), remove the Semicolon ";" and change it to the following:

 date.timezone = PRC

Date. timezone is a newly added Configuration Parameter in PHP5.1, which is used to set the time zone. The default date. timezone is commented out, that is, the default time zone is UTC Greenwich Mean Time.

Here we change to date. timezone = PRC (PRC, People's Republic of China, People's Republic of China), that is, the date uses the China time zone. In this way, the time difference is solved by eight hours.

Step 5: Configure phpMyAdmin

Open the phpMyAdmin directory, that is, D: \ WAMP \ WWW \ phpMyAdmin. We can see a config under the directory. sample. inc. php file, copy this file to the same directory, and rename it config. inc. php. This config. inc. php is the configuration file of phpMyAdmin. The following steps are to modify the content of this config. inc. php file.

1. Set phpMyAdmin logon Mode

Open the config. inc. php file and find $ cfg ['servers'] [$ I] ['auth _ type']. The settings are as follows:

 $cfg['Servers'][$i]['auth_type'] = 'cookie';

The value of this parameter is set to cookie. You need to enter the user name and password each time you log on to phpMyAdmin. This is also the default setting of phpMyAdmin.

Find $ cfg ['blowfish _ secret'] and set it as follows:

 $cfg['blowfish_secret'] = '';

This parameter is used to encrypt Cookies. this parameter is set to admin).com. You can change it to your own password.

Here we will introduce phpMyAdmin's four logon methods:

Cookie:This is the default logon method configured for phpMyAdmin. Enter the MySQL management account and password on the logon page.
When you select the cookie logon mode, you also need to set the phrase password $ cfg ['blowfish _ secret'], which is used for Cookies encryption.
Example: $ cfg ['blowfish _ secret'] = 'admin10000. com ';
If no password is set, the system prompts "a phrase password is required for the configuration file" when you log on to phpMyAdmin.

Config:Enter the phpMyAdmin logon address in the address bar of the local browser to log on. Anyone can access the address. Set the user name and password in the configuration file in advance.
The following two lines of parameters must be added to the configuration file for Logon:
$ Cfg ['servers'] [$ I] ['user'] = 'your MySQL logon account ';
$ Cfg ['servers'] [$ I] ['Password'] = 'your MySQL login password;
If you are only developing on this machine, you can set the config logon mode to save the trouble of entering the password each time.

Http:In the displayed dialog box, enter the user name and password.
Signon: similar to the logon mode of page Jump, you must set $ cfg ['servers'] [$ I] ['signonurl'], after you enter the phpMyAdmin logon address, the URL set by signonURL is automatically displayed.

2. enable advanced phpMyAdmin Functions

After logging on to phpMyAdmin, you will be prompted at the bottom of the homepage: "Not all advanced phpMyAdmin functions are set, and some functions are unavailable ".
Now let's solve this problem. Use the phpMyAdmin import function to import the phpMyAdmin/scripts/create_tables. SQL file to create necessary data tables.

Next, you need to create a new MySQL user and grant it the permission to access the data table created in the previous operation. This MYSQL user is called a control user and supports advanced phpMyAdmin functions.

Here we use pma as the control user and pmapass as the control user password. You can change it on your own.

Enter the following SQL code in the SQL query function box of phpMyAdmin:

 GRANT USAGE ON mysql.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass'; GRANT SELECT ( Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv ) ON mysql.user TO 'pma'@'localhost'; GRANT SELECT ON mysql.db TO 'pma'@'localhost'; GRANT SELECT ON TO 'pma'@'localhost'; GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON mysql.tables_priv TO 'pma'@'localhost'; 

Next we will find the line "User used to manipulate with storage" in config. inc. php. Remove the two line parameter comments (double slash "//") below it.


 $cfg['Servers'][$i]['controluser'] = 'pma'; $cfg['Servers'][$i]['controlpass'] = 'pmapass';

These two lines control the user and the user password respectively. That is, the user we created above.

Find the row "Storage database and tables" and remove the comments of the following parameters. Result:

 $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark'; $cfg['Servers'][$i]['relation'] = 'pma_relation'; $cfg['Servers'][$i]['table_info'] = 'pma_table_info'; $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords'; $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages'; $cfg['Servers'][$i]['column_info'] = 'pma_column_info'; $cfg['Servers'][$i]['history'] = 'pma_history'; $cfg['Servers'][$i]['tracking'] = 'pma_tracking'; $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords'; $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig';

Step 6: Test

Save the following code as the index. php file and put it under the D: \ WAMP \ WWW directory.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" ""> 

Enter "http: // localhost: 8080/index. php" in the address bar of the browser ". The result is shown in:

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