项目链接并不WAMP的服务器上运行 [英] Project Links do not work on Wamp Server

查看:397
本文介绍了项目链接并不WAMP的服务器上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的另一台计算机上安装WAMP服务器运行一个中型数据库和用户界面。我已经成功地挡住了IIS和路由服务器为localhost:8080。但每当我尝试在我的项目的访问从本地主机的主页,在WWW文件;我重定向到一个网页未找到错误。

I am installing the Wamp Server on another computer to run a mid-sized database and UI. I have been successful in blocking the iis and routing the server to Localhost:8080. But whenever I try to access on of my projects from the localhost homepage, in the www file; I get redirected to a Page not found error.

当我将鼠标悬停上面的链接目录总是出现HTTP:// ProjectFolderNameHere /时,它应该是HTTP://本地主机:8080 / ProjectFolderNameHere /。我能做些什么来获得正常工作的联系?

When I hover above the links the directory always comes up "http:// ProjectFolderNameHere /" when it's supposed to be "http:// LocalHost:8080 / ProjectFolderNameHere /". What can I do to get the links working properly?

我的机器上的Windows 7家庭版64位运行,我已经有微软的IIS中禁用。

My Machine runs on Windows 7 Home Edition 64-bits, and I already have Microsoft's iis disabled.

推荐答案

WAMPServer 2.5安培; 3.0.x的主页上你的项目菜单和虚拟主机

有一直观的WampServer 2.5及以上的变化,有一个很好的理由,这种变化!

There has been a change of concept in WampServer 2.5 and above and there is a good reason for this change!

在WampServer它现在大力鼓励创建为每个项目的虚拟主机,即使你在 \\ WAMP \\ WWW \\文件夹中结构追究他们。

In WampServer it is now STRONGLY encouraged to create a Virtual Host for each of your projects, even if you hold them in a \wamp\www\subfolder structure.

虚拟主机文档

虚拟主机的例子

该WampServer主页( \\ WAMP \\ WWW \\的index.php )现在期望你已经创建了一个虚拟主机为所有的项目,将妥善只有工作,因此你这样做。

The WampServer home page ( \wamp\www\index.php ) now expects you to have created a Virtual Host for all your projects and will therefore work properly only if you do so.

记录

为了使生活更轻松使用WampServer学习PHP的Apache和MySQL它初学者建议你创建 \\ WAMP \\ WWW \\ 文件夹下的子文件夹。

In order to make life easier for beginners using WampServer to learn PHP Apache and MySQL it was suggested that you create subfolders under the \wamp\www\ folder.

wamp
  |-- www
       |-- Chapter1
       |-- Chapter2
       |-- etc

这些子文件夹将然后显示一个名为您的项目菜单下的WampServer首页链接和这些链接将包含一个链接,本地主机/ subfoldername

可接受仅用于简单的教程

这使生活容易让初学者,并且是例如那些下面的教程学习PHP的编码完全可以接受的。
但是开发一个真正的网站,你会以后要复制到现场托管的服务器时,它从来没有打算使用。
事实上,如果你没有使用这个机制,它常引起问题,因为Live站点配置不匹配您的开发配置。

This made life easy for the complete beginner, and was perfectly acceptable for example for those following tutorials to learn PHP coding. However it was never intended for use when developing a real web site that you would later want to copy to your live hosted server. In fact if you did use this mechanism it often caused problems as the live sites configuration would not match your development configuration.

问题作为真正的网站的发展。

The Problem for real website development.

这样做的原因是当然的默认的DocumentRoot设置瓦帕是

The reason for this is of course that the default DocumentRoot setting for wamp is

的DocumentRootC:/ WAMP /网络/

不管你的子文件夹叫什么。
这包换经常使用的PHP code,它查询的结构或你的开发WampServer运行它会得到一个活的托管服务器上运行时,当你的网站获得不同的信息,其中的DocumentRoot配置指向的文件夹顶部的网站文件的层次结构。
这种code的存在于许多框架和CMS的例如字preSS和Joomla等。

regardless of what your subfolder was called. This ment that often used PHP code that queried the structure or your site received different information when running on your development WampServer to what it would receive when running on a live hosted server, where the DocumentRoot configuration points to the folder at the top of the website file hierarchy. This kind of code exists in many frameworks and CMS's for example WordPress and Joomla etc.

例如:

可以说,我们在 WAMP \\ WWW举行的项目称为PROJECT1 \\ PROJECT1 并错误地作为运行本地主机/ PROJECT1 / index.php文件

Lets say we have a project called project1 held in wamp\www\project1 and run incorrectly as localhost/project1/index.php

这是什么会被一些有问题的PHP命令会报告:

This is what would be reported by some of the PHP command in question:

$_SERVER['HTTP_HOST'] = localhost
$_SERVER['SERVER_NAME'] = localhost
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www

现在如果我们使用的是虚拟主机的定义正确定义该网站并运行它作为的http:// PROJECT1 在WAMPServer开发刍议网站的搜寻结果将匹配接收时在现场托管环境。

Now if we had correctly defined that site using a Virtual Host definition and ran it as http://project1 the results on the WAMPServer devlopment site will match those received when on a live hosted environment.

$_SERVER['HTTP_HOST'] = project1
$_SERVER['SERVER_NAME'] = project1
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www/project1

现在这种差异似乎微不足道,在第一,但如果你要使用像Word preSS或的CMS的如Joomla例如,一个框架,这样可以当你移动你的站点中的服务器并导致问题

Now this difference may seem trivial at first but if you were to use a framework like WordPress or one of the CMS's like Joomla for example, this can and does cause problems when you move your site to a live server.

其实这应该仅在您可能会发现Apache的配置文件的工作基本上是相同的任何的Wndows Apache服务器,有差异。

Actually this should work basically the same for any wndows Apache server, with differences only in where you may find the Apache config files.

有3个步骤来创建Apache的第一个虚拟主机,只有2,如果你已经有一个定义。

There are 3 steps to create your first Virtual Host in Apache, and only 2 if you already have one defined.


  1. 创建虚拟主机定义(S)

  2. 添加新域名对HOSTS文件。

  3. 取消注释httpd.conf中的线,包括了虚拟主机定义文件。

第1步,创建虚拟主机定义(S)

Step 1, Create the Virtual Host definition(s)

编辑文件称为的httpd-hosts.conf 这对于WampServer住在

Edit the file called httpd-hosts.conf which for WampServer lives in

\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf

(Apache的版本号可能会有所不同,继续从事以前的大脑)

如果这是你第一次编辑这个文件,删除默认例如code,它是没有用的。

我假设我们要创建一个名为网站PROJECT1生活在一个定义

I am assuming we want to create a definition for a site called project1 that lives in

\wamp\www\project1

非常重要的,首先我们必须确保本地主机仍然工作所以这是第一个VHOST定义,我们将在此文件。

Very important, first we must make sure that localhost still works so that is the first VHOST definition we will put in this file.

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "c:/wamp/www">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

现在我们定义我们的项目:这当然是你每个项目做你开始一个新的

Now we define our project: and this of course you do for each of your projects as you start a new one.

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/project1"
    ServerName project1
    <Directory  "c:/wamp/www/project1">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

请注意:每个虚拟主机作为自己的的DocumentRoot 定义。还有,你可以添加到虚拟主机定义许多其它参数,检查Apache文档。

NOTE: That each Virtual Host as its own DocumentRoot defined. There are also many other parameters you can add to a Virtual Hosts definition, check the Apache documentation.

小一旁

Small aside

该方式的虚拟主机在Apache的工作:在此文件中的第一个定义也将成为默认的站点,所以应该在浏览器中使用该域名不匹配任何实际定义的虚拟托管域,文件中制作本地主机的第一个域因此,将使其如果一个黑客试图只使用你的IP地址加载的网站。
因此,如果我们确保Apache的安全性这一领域的总是设置为

The way virtual hosts work in Apache: The first definition in this file will also be the default site, so should the domain name used in the browser not match any actually defined virtually hosted domain, making localhost the first domain in the file will therefore make it the site that is loaded if a hack attempt just uses your IP Address. So if we ensure that the Apache security for this domain is ALWAYS SET TO

Require local

从外部地址的休闲黑客将收到一个错误,而不是进入你的电脑,但你应该拼错了您将看到的WampServer主页域名,因为你是在同一台PC WampServer和therfore关于本地

第2步

添加新域名对HOSTS文件。
现在,我们需要补充的是,我们在虚拟主机的定义已经习惯了HOSTS文件,以便Windows知道哪里可以找到它的域名。这是类同创建DNS A记录,但在这种情况下,这个特定的PC上才可见。

Add your new domain name to the HOSTS file. Now we need to add the domain name that we have used in the Virtual Host definition to the HOSTS file so that windows knows where to find it. This is similiar to creating a DNS A record, but it is only visible in this case on this specific PC.

修改 C:\\ WINDOWS \\ SYSTEM32 \\ DRIVERS \\ ETC \\主机

该文件没有扩展名,应保持这种方式。当心记事本,因为它可能会尝试,如果你有没有更好的编辑器中添加一个 .TXT 扩展。
我建议你​​下载记事本+ +,它的自由和一个非常好的编辑。

The file has no extension and should remain that way. Watch out for notepad, as it may try and add a .txt extension if you have no better editor. I suggest you download Notepad++, its free and a very good editor.

此外,这是一个受保护的文件,所以你必须以管理员权限修改,因此使用启动你的编辑器以管理员身份运行的菜单选项。

Also this is a protected file so you must edit it with administrator privileges, so launch you editor using the Run as Administrator menu option.

hosts文件应该是这样的,当你完成这些修改

The hosts file should look like this when you have completed these edits

127.0.0.1 localhost
127.0.0.1 project1

::1 localhost
::1 project1

请注意,你应该在这里为IPV4环回地址定义 127.0.0.1 也是IPV6回环地址 :: 1 作为Apache是​​目前IPV6知道,浏览器将使用IPv4或IPv6或两者兼而有之。我不知道它是如何决定使用哪一个,但它可以使用,如果你有IPv6堆栈开启,大多数窗口操作系统的做的XP SP3的。

Note that you should have definitions in here for the IPV4 loopback address 127.0.0.1 and also the IPV6 loopback address ::1 as Apache is now IPV6 aware and the browser will use either IPV4 or IPV6 or both. I have no idea how it decides which to use, but it can use either if you have the IPV6 stack turned on, and most window OS's do as of XP SP3.

现在,我们必须告诉窗口刷新其域名缓存,因此再次使用运行启动命令窗口以管理员身份菜单选项一遍,然后执行以下操作。

Now we must tell windows to refresh its domain name cache, so launch a command window again using the Run as Administrator menu option again, and do the following.

net stop dnscache
net start dnscache

这会强制Windows以清除其域名缓存和重新加载它,在重装它会重新读取HOSTS所以现在知道的域 PROJECT1 文件。

This forces windows to clear its domain name cache and reload it, in reloading it will re-read the HOSTS file so now it knows about the domain project1.

第3步:取消注释httpd.conf中的线,包括了虚拟主机定义文件

Step 3: Uncomment the line in httpd.conf that includes the Virtual Hosts definition file.

编辑httpd.conf,使用wampmanager.exe菜单,以确保编辑正确的文件。

Edit your httpd.conf, use the wampmanager.exe menus to make sure you edit the correct file.

查找在httpd.conf

Find this line in httpd.conf

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

和刚删除来取消注释该行。

And just remove the # to uncomment that line.

要在你运行Apache,我们现在必须停止并重新启动Apache服务激活这种变化。

To activate this change in you running Apache we must now stop and restart the Apache service.

wampmanager.exe -> Apache -> Service -> Restart Service

现在,如果在系统托盘中的图标WAMP不会再次走向绿色,这意味着你可能已经做错了事在 \\ WAMP \\ BIN \\ apache的\\ apache2.4.9 \\的conf \\额外\\的httpd -hosts.conf 文件。

Now if the WAMP icon in the system tray does not go GREEN again, it means you have probably done something wrong in the \wamp\bin\apache\apache2.4.9\conf\extra\httpd-hosts.conf file.

如果所以这里是要找出什么是错的一个有用的机制。它使用了Apache的exe(httpd.exe)的功能,可查看其配置文件,并通过文件名和行号报告错误。

If so here is a useful mechanism to find out what is wrong. It uses a feature of the Apache exe (httpd.exe) to check its config files and report errors by filename and line numbers.

启动命令窗口。

cd \wamp\bin\apache\apache2.4.9\bin
httpd -t

所以,修正错误,直到你得到的输出再次复试

So fix the errors and retest again until you get the output

Syntax OK

现在有一件事。

Now there is one more thing.

有实际上wampmanager菜单系统上的2个新的菜单项。一位名为我的项目是默认打开的。
而第二个,名为我的虚拟主机,这是不是默认激活。

There are actually 2 new menu items on the wampmanager menu system. One called 'My Projects' which is turned on by default. And a second one, called 'My Virtual Hosts', which is not activated by default.

我的项目将列出\\ WAMP的\\ www目录的子目录,并提供一个链接,启动该网站在该子目录。
正如我刚才所说,推出project1`而不是本地主机/ PROJECT1这样做,我们必须创建一个虚拟主机定义,以使该链接实际上启动该网站在浏览器中的链接工作,没有虚拟主机的定义,它很可能推出针对网站名称网络搜索作为关键字或只返回一个没有找到场地条件。

'My Projects' will list any sub directory of the \wamp\www directory and provide a link to launch the site in that sub directory. As I said earlier, it launches 'project1` and not 'localhost/project1' so to make the link work we must create a Virtual Host definition to make this link actually launch that site in your browser, without the Virtual Host definition it's likely to launch a web search for the site name as a keyword or just return a site not found condition.

在我的虚拟主机菜单项稍有不同。它搜索其用于定义虚拟主机(我们将获得在一分钟),并为它找到,并为每一个菜单项的每个ServerName参数菜单链接的文件。
这似乎有点令人困惑,因为一旦我们为的子目录创建一个虚拟主机定义\\ WAMP \\ www文件夹一些物品就会出现在我的项目菜单和我的虚拟主机菜单的。

The 'My Virtual Hosts' menu item is a little different. It searches the file that is used to define Virtual Hosts ( we will get to that in a minute ) and creates menu links for each ServerName parameter it finds and creates a menu item for each one. This may seem a little confusing as once we create a Virtual Host definition for the sub directories of the \wamp\www folder some items will appear on both of the 'My Projects' menu and the 'My Virtual Hosts' menu's.

我如何把这个其他的我的虚拟主机菜单上?


  • 请在\\ WAMP \\ wampmanager.tpl文件的备份,以防万一你犯了一个错误,它的一个非常重要的文件。

  • 编辑的\\ WAMP \\ wampmanager.tpl

  • 找到该参数; WAMPPROJECTSUBMENU ,其在[Menu.Left]部分

  • 添加这个新参数; WAMPVHOSTSUBMENU 之前或之后。WAMPPROJECTSUBMENU 参数

  • 保存文件。

  • 现在,右键单击wampmanager图标,然后选择刷新。如果不添加菜单,退出并重新启动wampmanager。

  • Make a backup of the \wamp\wampmanager.tpl file, just in case you make a mistake, its a very important file.
  • Edit the \wamp\wampmanager.tpl
  • Find this parameter ;WAMPPROJECTSUBMENU, its in the '[Menu.Left]' section.
  • Add this new parameter ;WAMPVHOSTSUBMENU either before or after the ;WAMPPROJECTSUBMENU parameter.
  • Save the file.
  • Now right click the wampmanager icon, and select 'Refresh'. If this does not add the menu, 'exit' and restart wampmanager.

大注意
如果你已经有定义了一些虚拟主机的新的菜单才会出现!否则,你会看到没有区别,直到你定义一个VHOST。

Big Note The new menu will only appear if you already have some Virtual Hosts defined! Otherwise you will see no difference until you define a VHOST.

现在,如果你把这个给其合乎逻辑的延伸

您现在可以完全将你的网站code中的 \\ WAMP \\ 文件夹结构之外只需在VHOST定义改变DocumentRoot的参数。因此,例如,你可以这样做:

You can now move your web site code completely outside the \wamp\ folder structure simply by changing the DocumentRoot parameter in the VHOST definition. So for example you could do this:

创建WAMP磁盘或任何其他磁盘上的文件夹(注意网络驱动器,它们是一个比较复杂)

Create a folder on the wamp disk or any other disk ( beware of network drive, they are a bit more complicated)

D:
MD websites
CD websites
MD example.com
CD example.com
MD www

现在您的网站code复制,或开始在 \\网站\\ example.com \\ WWW 文件夹内创建并这样定义你的VHOST:

You now copy your site code to, or start creating it in the \websites\example.com\www folder and define your VHOST like this:

<VirtualHost *:80>
    DocumentRoot "d:/websites/example.com/www"
    ServerName example.dev
    ServerAlias www.example.dev
    <Directory  "d:/websites/example.com/www">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    php_flag display_errors Off
    php_flag log_errors On

    php_value max_upload_size 40M
    php_value max_execution_time 60
    php_value error_log "d:/wamp/logs/example_com_phperror.log"
</VirtualHost>

那么这个新的发展领域添加到HOSTS文件:

Then add this new development domain to the HOSTS file:

127.0.0.1 localhost
::1 localhost

127.0.0.1 project1
::1 project1

127.0.0.1 example.dev
::1 example.dev

注:这是不使用服务器名称或ServerAlias​​是与您的生活的域名是一个好主意,因为如果我们使用example.com作为服务器名称那就意味着我们再也不能去从这个PC的现实生活的网站,因为它会直接example.com到127.0.0.1这个就是PC,而不是出在互联网上。

另外:
看到我让这个网站可以从互联网访问从VHOST定义中,这一变化将只适用于这个网站,并没有其他的。允许客户端查看了一个小时左右的更改,而无需将其复制到现场服务器非常有用的。
这并不意味着我们必须手工编辑这个文件来打开此访问和关闭,而不是使用put在线/离线菜单上wampmanager。

ALSO: See that I have allowed this site to be accessed from the internet from within the VHOST definitions, this change will apply to only this site and no other. Very useful for allowing a client to view your changes for an hour or so without having to copy them to the live server. This does mean that we have to edit this file manually to turn this access on and off rather than use the Put Online/Offline menu item on wampmanager.

另外,我增加了一些修改PHP配置,再次将仅适用于这一个网站。
保持与不像你保持其他站点具体要求网站时非常有用。
我想我们可以从参数假设使用它在它有一个长期运行的页面的某个地方,这是非常不好写,不会显示在浏览器上的错误未做页面乌七八糟运行。相信我,这样的网站存在,人们还是希望他们保持的非常的。但是,这意味着我们只有在全球范围内改变这些参数对于这个特定的网站,而不是在WampServer运行的所有虚拟网站。

Also I have added some modifications to the PHP config, again that will only apply to this one site. Very useful when maintaining a site with specific requirement unlike all the other sites you maintain. I guess we can assume from the parameters used that it has a long running page in it somewhere and it is very badly written and will not run with errors being displayed on the browser without making a horrible mess of the page. Believe me sites like this exist and people still want them maintained badly. But this mean we only have to change these parameters for this specific site and not globally to all Virtual sites running on WampServer.

这篇关于项目链接并不WAMP的服务器上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆