Windows+Apache builds php development environment

伊谢尔伦
Release: 2016-11-24 14:22:09
Original
1265 people have browsed it

Step 1: Download the installation 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 php-5.3 .5-Win32-VC6-x86.zip
4. phpMyadmin version phpMyAdmin-3.4.9-all-languages.zip

Tips:
1. It is recommended to choose the Apache version without SSL function to complete the development, so we use it here Apache 2.2.21-win32-x86-no-ssl.msi.
2. To install MySQL under Windows, choose the .msi installation package format. We chose mysql-5.5.19-win32.msi. Just double-click and follow the wizard to install. It is simple and convenient.
3. For PHP, we choose to use the Windows .zip version, php-5.3.5-Win32-VC6-x86.zip. In terms of security and performance, the zip version is better, and this version is generally installed on servers.
Do not download the NTS version or the VC9 version, because VC9 is specially customized for IIS, while VC6 is provided for Apache or other WEB service software.
4. phpMyAdmin is an online MySQL management tool based on PHP. When installing phpMyAdmin3, the PHP environment required is at least PHP5.2 and MySQL5 or above. We all meet the requirements here.

Step 2: Install the file

1. Create a folder on the disk to be installed. For the convenience of management, we create a WAMP folder in the root directory of the D drive. D:WAMP (WAMP is the abbreviation of windows+apache+mysql+php).
2. Create a WWW folder under the WAMP folder to store your PHP website program. D:WAMPWWW.
3. Install the Apache server and install the Apache server to the D:WAMPApache folder. For the specific Apache installation process, please refer to the document Apache Installation Diagram.
4. Unzip the downloaded php-5.3.5-Win32-VC6-x86 to the D:WAMPPHP folder.
5. Install the MySql database and install MySQL to the D:WAMPMySQL folder. For the specific MySQL installation process, please refer to the document MySQL Installation Diagram.
6. Unzip phpMyAdmin-3.4.9-all-languages.zip, then rename it to phpMyAdmin, and copy it to the PHP website program directory. The result is D:WAMPWWWphpMyAdmin.

Step 3: Configure Apache

First use a text editing tool (EditPlus is recommended) to open the D:WAMPApacheconfhttpd.conf file. This file is the configuration file of Apache. The following steps are to modify the content of this file.
It should be noted that after modifying the httpd.conf file, you need to restart the Apache service for the new settings to take effect.

1. Set the listening port

After opening the httpd.conf file, find Listen (about line 46) and change the number after it to 8080, as follows:

 Listen 8080
Copy after login

This parameter is used to set the listening port of the Apache server , generally defaults to 80. The reason for changing it to 8080 is to avoid conflict with the IIS port number of the Windows 2003 system. If you do not enable IIS, you can also use the default port number 80.

2. Let Apache load the PHP module

Find #LoadModule vhost_alias_module modules/mod_vhost_alias.so (about line 128), 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"
Copy after login

LoadModule php5_module "D:/WAMP/PHP/ php5apache2_2.dll"
This sentence means to load the PHP5 module in module mode.
AddType application/x-httpd-php .php
This sentence means to execute the file with .php extension as a php script. You can use any other extension you like, such as .html, .php5 or even .txt for PHP.
PHPIniDir "D:/WAMP/PHP"
This sentence is used to specify the directory where the PHP configuration file php.ini is located.
If Apache 2 runs php5 in module mode, you can use the PHPIniDir directive.

3. Modify the website storage directory

We know that Apache’s default website storage directory is the htdocs folder in the Apache installation directory. When you change the website storage directory, you must modify the corresponding Apache configuration.
Look for DocumentRoot (about line 182) in the configuration file httpd.conf and modify it to point to the correct folder in the website directory. We changed it here to

DocumentRoot "D:/WAMP/www"
Copy after login

At the same time, look for This should be changed to whatever you set DocumentRoot to (about line 207), below it there is the line , change it to your own configured DocumentRoot path. We modified it here to:

<Directory "D:/WAMP/www">
Copy after login

4. Modify the directory homepage file

Find DirectoryIndex index.html (about line 244) in the configuration file httpd.conf and modify it to:

DirectoryIndex index.html index.htm index.php
Copy after login

DirectoryIndex 指的是当客户浏览器访问的路径是一个目录时,Apache默认执行的文件。
以我们所修改的为例:当客户浏览器访问一个目录时,Apache会去找该目录下的index.html,如果没有再找index.htm,还没有再找 index.php。都找不到则默认显示该目录下的文件列表。参考文档:如果防止Apache显示文件列表

第四步:配置PHP

打开PHP安装目录,即D:\WAMP\PHP,我们可以看到目录下有两个这样的文件 php.ini-development 和 php.ini-production,第一个是开发使用的配置文件,第二个是生产环境的配置,因为我们是在本机做开发,所以选择前者。将php.ini-development复制一份到同目录下,并改名为 php.ini。这个php.ini 就是当前使用的配置文件,以下几步都是在修改这个php.ini文件的内容。要注意的是,修改php.ini文件后需重新启动Apache服务,新设置才会生效。

1. 指定PHP扩展库的存放目录

在Windows下PHP的扩展库通常以 DLL 形式存放在PHP的ext目录中。
使用文本工具打开php.ini文件,查找extension_dir = "ext"(大概在809行),也就是在 On windows 下面那一行。把它前面的分号“;”去除掉,改为如下:

 extension_dir = "D:/WAMP/PHP/ext"
Copy after login

extension_dir 表示PHP扩展库的具体目录,以便调用相应的DLL文件。

2. 开启相应的扩展库

默认情况下许多PHP的扩展库都是关闭的,比如默认PHP不支持连接Mysql数据库,需开启相应的扩展库。
这里我们开启一些常用的扩展库。
查找 ; Windows Extensions(大概在941行),在它的下面是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
Copy after login

把以上extension 前面的分号 “;” 去掉。如果你希望加载其它扩展模块,方法相同,只要去掉前面的分号即可。
提示1:重启Apache提示 “unable to load dynamic library......php_curl.dll”,加载php_curl.dll错误。解决方法是拷贝 PHP 目录下的 libeay32.dll 和 ssleay32.dll 到 windows 目录或 windows/system32 目录下,只要是系统 Path 环境变量里包含的路径就可以。如果不想拷贝,你也可以直接把 PHP 路径放到系统 Path 环境变量里。 右击我的电脑=>属性=>高级=>环境变量=>系统变量里有个Path,双击打开,把你的PHP路径加个分号“;”再前面( ;D:\WAMP\PHP ),添加进去就OK了。重启Apache不再提示该错误。
提示2:Exif 扩展是用来显示图片的 exif 信息的,因为该扩展需要 mbstring.dll 支持,所以必须将 extension=php_exif.dll 这一行写到extension=php_mbstring.dll 的后面。
提示3:如果PHP自带的扩展库不能满足你的需要,你可以去 pecl.php.net 查找并下载你需要的库。windows用户可以去 pecl4win.php.net 或者 http://downloads.php.net/pierre/ 下载已经编译好的DLL文件,也可以去http://museum.php.net/php5/ 载PECL集合压缩包。
提示4:很多人在找php_zip.dll,其实从php5.3开始已经集成了zip扩展,直接使用就行了。你可以用 找到zip扩展的说明。

3. 让PHP支持短标签

在 php.ini 配置文件查找 short_open_tag = Off (大概在266行)把它修改成:short_open_tag = On 让其支持短标签。
php的代码一般包含在的标签内,设置 short_open_tag = On 之后,可以写成更简洁的形式:

4. 配置PHP的Session功能

在使用session功能时,我们必须配置session文件在服务器上的保存目录。我们需要为session建立一个可读写的目录,这个目录最好独立于网站目录之外。
这里把目录上建在了D:\WAMP\sessiontmp,然后在 php.ini 配置文件中找 ;session.save_path = "/tmp" (大概在1467行),去掉前面的分号“;” ,改为如下:

session.save_path = "D:/WAMP/sessiontmp"
Copy after login

5. 配置PHP的文件上传功能

同session一样,在使用PHP文件上传功能时,我们必须要指定一个临时文件夹以完成文件上传功能,否则文件上传功能会失败。
我们建立一个可读写的目录文件夹 D:\WAMP\fileuploadtmp,然后在 php.ini 配置文件中找到 ;upload_tmp_dir = (大概875行),修改为:

upload_tmp_dir = "D:/WAMP/fileuploadtmp"
Copy after login

PHP默认上传文件大小不超过2M,要想上传大于2M的文件,请参考文档 配置php.ini实现文件上传功能。

6. 设置时区

在 php.ini 配置文件查找 ;date.timezone = (大概在993行),去掉前面的分号“;” 改为如下:

date.timezone = PRC
Copy after login

date.timezone是PHP5.1开始新增加的配置参数,用来设置时区。默认date.timezone是被注释掉的,也就是默认时区是UTC格林威治标准时间。
我们这里改为 date.timezone = PRC(PRC,People’s Republic of China,中华人民共和国),也就是日期使用中国的时区。这样可以解决时间相差八小时的问题。

第五步:配置phpMyAdmin

打开phpMyAdmin目录,即D:\WAMP\WWW\phpMyAdmin,我们可以看到目录下有一个config.sample.inc.php 文件,将这个文件复制一份到同目录下,并改名为 config.inc.php。这个config.inc.php 就是phpMyAdmin的配置文件,以下几步都是在修改这个config.inc.php 文件的内容。

1. 设置phpMyAdmin登录方式

打开config.inc.php文件,查找 $cfg['Servers'][$i]['auth_type'] ,设置如下:

   $cfg[&#39;Servers&#39;][$i][&#39;auth_type&#39;] = &#39;cookie&#39;;
Copy after login

这个参数的值设置为cookie,每次登录phpMyAdmin需要输入用户名密码。这也是phpMyAdmin的默认设置。

然后找到 $cfg['blowfish_secret'],设置如下:

$cfg[&#39;blowfish_secret&#39;] = &#39;admin10000.com&#39;;
Copy after login

此参数用于Cookies的加密,这是设置为admin10000.com,你可以改成自己的密码。

这里介绍一下phpMyAdmin 的四种登录方式:
cookie:这是phpMyAdmin配置默认的登录方式。需在登录界面输入MySQL的管理账号和密码。
当选择cookie登录方式,还需要设置短语密码 $cfg['blowfish_secret'] ,这个密码用于Cookies的加密。
例如:$cfg[&#39;blowfish_secret&#39;] = &#39;admin10000.com&#39;;
如果没有设置,登录phpMyAdmin会提示 “配置文件现在需要一个短语密码” 的错误。
config:直接在地浏览器地址栏输入phpMyAdmin登录地址即可登录,任何人都可以访问。用户名和密码提前在配置文件中设定好。
此登录方式必须在配置文件中增加下面2行参数:
$cfg['Servers'][$i]['user'] = '你的MySQL登录账号';
$cfg['Servers'][$i]['password'] = '你的MySQL登陆密码;
如果只是在本机器做开发,可以设置为config登录方式,省去每次输入密码的麻烦。
http:弹出一个对话框,输入用户名和密码后进入。
signon:类似于页面跳转的登录方式,同时需要设定$cfg['Servers'][$i]['SignonURL'],当你输入phpMyAdmin登录地址后会自动跳转到signonURL设定的网址。

2. 开启phpMyAdmin 高级功能

登录phpMyAdmin 后,在首页面的最下方会提示:“phpMyAdmin 高级功能未全部设置,部分功能不可用”。
现在我们来解决这个问题。使用phpMyAdmin的导入功能,导入phpMyAdmin/scripts/create_tables.sql 这个文件,从而建立必要的数据表。
接下来还需要新建一个MySQL用户,并授予其访问上一步操作建立的数据表的权限,这个MYSQL用户称为控制用户,为 phpMyAdmin 高级功能提供支持。
我们这里使用 pma 作为控制用户以及 pmapass 作为控制用户的密码。你可以自行更改。
在phpMyAdmin的SQL查询功能框中输入以下SQL代码:

  GRANT USAGE ON mysql.* TO &#39;pma&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;pmapass&#39;;
    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 &#39;pma&#39;@&#39;localhost&#39;;
    GRANT SELECT ON mysql.db TO &#39;pma&#39;@&#39;localhost&#39;;
    GRANT SELECT ON mysql.host TO &#39;pma&#39;@&#39;localhost&#39;;
    GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv)
        ON mysql.tables_priv TO &#39;pma&#39;@&#39;localhost&#39;;
Copy after login

接着我们在 config.inc.php 中找到 User used to manipulate with storage 这一行。把它下面的2行参数注释(双斜杠“//”)去掉。结果为:

 $cfg[&#39;Servers&#39;][$i][&#39;controluser&#39;] = &#39;pma&#39;;
        $cfg[&#39;Servers&#39;][$i][&#39;controlpass&#39;] = &#39;pmapass&#39;;
Copy after login

这两行分别是控制用户和控制用户密码。也就是上边我们创建的那个用户。

接着找到 Storage database and tables 这一行,把下面的几个参数的注释去掉。结果为:

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

第六步:测试

将如下代码保存为index.php文件,放到D:\WAMP\WWW目录下面。


< html xmlns="http://www.w3.org/1999/xhtml">
                                                                    " />
                                                        if (! $ Link) Echo "MySQL database connection failed!"; Connection successful!";                                                                                              
                            lt;?php phpinfo(); ?>



Then enter "http://localhost:8080/index.php" in the browser address bar.



Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template