PHP学习笔记8(WAMPServer)

来源:互联网 发布:java斐波那契数列第n项 编辑:程序博客网 时间:2024/06/14 09:15

(1)WAMPServer介绍

  • 什么是WAMPServer集成开发环境
    • W:windows
    • A:Apache
    • M:MySQL
    • P:PHP
  • 官网地址
    • http://www.wampserver.com/
  • 安装中可能出现的错误
    • 安装可能报错找不到MSVCR110.dll
      • 解决措施https://jingyan.baidu.com/article/4f7d57129fa86e1a201927de.html
      • VCredist下载网址http://www.microsoft.com/zh-CN/download/details.aspx?id=30679
    • 找不到VCRUNTIME140.dll
      • https://www.microsoft.com/en-US/download/details.aspx?id=48145
      • 下载安装
  • 成功标志
    • 浏览器中输入http://localhost/

这里写图片描述

(2)修改www目录

  • 打开Apache下的httpd.conf文件
  • 把这里的地址替换为我们自定义的目录
DocumentRoot "${INSTALL_DIR}/www"  C:\Users\wangc\Desktop\php<Directory "${INSTALL_DIR}/www">  C:\Users\wangc\Desktop\php    #    # Possible values for the Options directive are "None", "All",    # or any combination of:    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews    #    # Note that "MultiViews" must be named *explicitly* --- "Options All"    # doesn't give it to you.    #    # The Options directive is both complicated and important.  Please see    # http://httpd.apache.org/docs/2.4/mod/core.html#options    # for more information.    #    Options +Indexes +FollowSymLinks +Multiviews    #    # AllowOverride controls what directives may be placed in .htaccess files.    # It can be "All", "None", or any combination of the keywords:    #   AllowOverride FileInfo AuthConfig Limit    #    AllowOverride all    #    # Controls who can get stuff from this server.    ##   onlineoffline tag - don't remove    Require local</Directory>
  • 如果出现一下情况

这里写图片描述

  • 这是由于之前配置了wampserver的本地虚拟服务器,现在想把本地项目访问从虚拟幻境访问改为http://localhost/这种方式访问,所有导致服务器找不到用户请求的UR修改Apache下的httpd.conf文件
  • 修改Apache下的httpd.conf文件(加一个#把虚拟服务器注释掉)
# Virtual hosts# Include conf/extra/httpd-vhosts.conf
  • 测试成功,我们在php文件夹下放一个test.php,浏览器中访问http://localhost/test.php
<?php    echo 'success';?>
  • 但是我们点击www 目录还是跳转安装目录下www文件夹,不是我们自定义的php文件夹
  • 修改D:\ITSoft\wamp64\wampmanager.ini
[Menu.Left];WAMPMENULEFTSTARTType: separator; Caption: "Made in France by Otomatic"Type: item; Caption: "Localhost"; Action: run; FileName: "C:/Program Files (x86)/Internet Explorer/iexplore.exe"; Parameters: "http://localhost/"; Glyph: 27Type: item; Caption: "phpMyAdmin"; Action: run; FileName: "C:/Program Files (x86)/Internet Explorer/iexplore.exe"; Parameters: "http://localhost/phpmyadmin/"; Glyph: 28;WAMPVHOSTSUBMENUType: submenu; Caption: "Your VirtualHosts"; Submenu: myVhostsMenu; Glyph: 3;WAMPALIASSUBMENU;WAMPPROJECTSUBMENUType: item; Caption: "www 目录"; Action: shellexecute; FileName: "D:/ITSoft/wamp64/www"; Glyph: 2Type: submenu; Caption: "Apache"; SubMenu: apacheMenu; Glyph: 3Type: submenu; Caption: "PHP"; SubMenu: phpMenu; Glyph: 3Type: submenu; Caption: "MySQL"; SubMenu: mysqlMenu; Glyph: 3Type: separator; Caption: "64bit - Quick Admin"Type: item; Caption: "启动所有服务"; Action: multi; Actions: StartAllType: item; Caption: "停止所有服务"; Action: multi; Actions: StopAllType: item; Caption: "重新启动所有服务"; Action: multi; Actions: RestartAllType: separator;
  • 将上述黄色文本改为以下
Type: item; Caption: "phpDemo"; Action: shellexecute; FileName: "C:\Users\wangc\Desktop\php"; Glyph: 2
  • 修改D:\ITSoft\wamp64\ wampmanager.tpl
[Menu.Left];WAMPMENULEFTSTARTType: separator; Caption: "Made in France by Otomatic"Type: item; Caption: "${w_localhost}"; Action: run; FileName: "${c_navigator}"; Parameters: "${c_edge}http://localhost${UrlPort}/"; Glyph: 27Type: item; Caption: "${w_phpmyadmin}"; Action: run; FileName: "${c_navigator}"; Parameters: "${c_edge}http://localhost${UrlPort}/phpmyadmin/"; Glyph: 28;WAMPVHOSTSUBMENU;WAMPALIASSUBMENU;WAMPPROJECTSUBMENUType: item; Caption: "${w_wwwDirectory}"; Action: shellexecute; FileName: "${wwwDir}"; Glyph: 2Type: submenu; Caption: "Apache"; SubMenu: apacheMenu; Glyph: 3Type: submenu; Caption: "PHP"; SubMenu: phpMenu; Glyph: 3Type: submenu; Caption: "MySQL"; SubMenu: mysqlMenu; Glyph: 3Type: separator; Caption: "${c_wampMode} - Quick Admin"Type: item; Caption: "${w_startServices}"; Action: multi; Actions: StartAllType: item; Caption: "${w_stopServices}"; Action: multi; Actions: StopAllType: item; Caption: "${w_restartServices}"; Action: multi; Actions: RestartAllType: separator;${ItemPutOnline}Type: item; Caption: "${w_putOnline}"; Action: multi; Actions: onlineoffline;Type: item; Caption: "For local test only"; Action: run; FileName: "${c_phpExe}"; Parameters: "test.php";WorkingDir: "${c_installDir}/scripts"; Flags: waituntilterminated; Glyph: 9;WAMPMENULEFTEND
  • 将上述黄色文本改为以下
Type: item; Caption: "php 目录"; Action: shellexecute; FileName: "C:\Users\wangc\Desktop\php"; Glyph: 2

(3)多站点配置

  • 修改D:\ITSoft\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf添加新的站点名
    • ServerName 站点名
    • DocumentRoot 站点根目录
# Virtual Hosts#<VirtualHost *:80>    ServerName localhost    DocumentRoot D:/ITSoft/wamp64/www    <Directory  "D:/ITSoft/wamp64/www/">        Options +Indexes +Includes +FollowSymLinks +MultiViews        AllowOverride All        Require local    </Directory></VirtualHost><VirtualHost *:80>    ServerName test01.com    DocumentRoot C:\Users\wangc\Desktop\php\test01</VirtualHost><VirtualHost *:80>    ServerName test02.com    DocumentRoot C:\Users\wangc\Desktop\php\test02</VirtualHost>#
  • 修改Apache下的httpd.conf文件
    • 把虚拟主机的注释去掉
# Virtual hostsInclude conf/extra/httpd-vhosts.conf
  • 设置那些站点可以访问,此处设置为本地
<Directory "C:\Users\wangc\Desktop\php">    #    # Possible values for the Options directive are "None", "All",    # or any combination of:    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews    #    # Note that "MultiViews" must be named *explicitly* --- "Options All"    # doesn't give it to you.    #    # The Options directive is both complicated and important.  Please see    # http://httpd.apache.org/docs/2.4/mod/core.html#options    # for more information.    #    Options +Indexes +FollowSymLinks +Multiviews    #    # AllowOverride controls what directives may be placed in .htaccess files.    # It can be "All", "None", or any combination of the keywords:    #   AllowOverride FileInfo AuthConfig Limit    #    AllowOverride all    #    # Controls who can get stuff from this server.    ##   onlineoffline tag - don't remove    Require local</Directory>
  • 修改C:\Windows\System32\drivers\etc\host
    • 表示访问test01.com会从本地的站点先找
# Copyright (c) 1993-2009 Microsoft Corp.## This is a sample HOSTS file used by Microsoft TCP/IP for Windows.## This file contains the mappings of IP addresses to host names. Each# entry should be kept on an individual line. The IP address should# be placed in the first column followed by the corresponding host name.# The IP address and the host name should be separated by at least one# space.## Additionally, comments (such as these) may be inserted on individual# lines or following the machine name denoted by a '#' symbol.## For example:##      102.54.94.97     rhino.acme.com          # source server#       38.25.63.10     x.acme.com              # x client host# localhost name resolution is handled within DNS itself.#    127.0.0.1       localhost#    ::1             localhost127.0.0.1    test01.com127.0.0.1    test02.com
  • 测试是否成功
    • C:\Users\wangc\Desktop\php目录添加test01 test02目录
    • 目录下添加index.php
    • 浏览器直接访问test01.com test02.com,能成功访问其中的index.php文件则证明配置成功

(4)修改端口号

  • 修改Apache下的httpd.conf文件
    • 把默认80端口改为8080端口
## Mutex: Allows you to set the mutex mechanism and mutex file directory# for individual mutexes, or change the global defaults## Uncomment and change the directory if mutexes are file-based and the default# mutex file directory is not on a local disk or is not appropriate for some# other reason.## Mutex default:logs## Listen: Allows you to bind Apache to specific IP addresses and/or# ports, instead of the default. See also the <VirtualHost># directive.## Change this to Listen on specific IP addresses as shown below to# prevent Apache from glomming onto all bound IP addresses.##Listen 12.34.56.78:80Listen 0.0.0.0:8080Listen [::0]:8080# ServerName gives the name and port that the server uses to identify itself.# This can often be determined automatically, but we recommend you specify# it explicitly to prevent problems during startup.## If your host doesn't have a registered DNS name, enter its IP address here.#ServerName localhost:8080
  • 测试成功
    • 此时在浏览器访问localhost/test.php失败(等效于localhost:8080/test.php默认端口为80)
    • 必须默认localhost:8080/test.php
原创粉丝点击