简体   繁体   English

在本地运行多个网站Apache PHP Ubuntu

[英]Running multiple websites locally Apache PHP Ubuntu

I am attempting to run more than one virtualhost(?), for example: http:/localhost will point to one project, http:/newsite to another and http:/myfavourite again to a different project a different document root. 我试图运行多个虚拟主机(?),例如:http:/ localhost将指向一个项目,http:/ newsite指向另一个项目,http:/ myfavourite指向另一个项目的另一个文档根目录。

(each http:// is http:/ here because of hyperlink posting restrictions) (由于超链接发布限制,每个http://都是http:/ here)

I have had no success looking where to edit the apache files in /etc/apache2. 我没有成功查看在/ etc / apache2中编辑apache文件的位置。 Am I looking for a vhosts file? 我在寻找一个vhosts文件吗?

Any advice would be awesome, thanks. 任何建议都很棒,谢谢。

Here is a chapter of an e-book that explains how to create Virtual Hosts to do precisely what you want -- and the examples are using Ubuntu : Creating A Local Domain Using Apache Virtual Hosts 以下是电子书的一章,解释了如何创建虚拟主机以完全按照您的需要进行操作 - 示例使用的是Ubuntu: 使用Apache虚拟主机创建本地域

In a few words : 简而言之 :

  • You first need to create the VirtualHost 您首先需要创建VirtualHost
  • Then, you have to edit your hosts file (under Linux, it's /etc/hosts ) so the new "pseudo domain name" points to your machine. 然后,您必须编辑您的hosts文件(在Linux下,它是/etc/hosts ),以便新的“伪域名”指向您的计算机。

For the VirtualHost, with Ubuntu, you'd create a new file in /etc/apache2/sites-available/ ; 对于VirtualHost,使用Ubuntu,您将在/etc/apache2/sites-available/创建一个新文件; for instance named your-site.com ; 例如,名为your-site.com ; it would contain something like this : 它将包含这样的东西:

<VirtualHost *:80>
    ServerName your-site.com
    DocumentRoot /.../www/...

    <Directory /.../www/...>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

And you register this file so it's loaded by Apache, with this command : 你注册这个文件,所以它由Apache加载,使用这个命令:

sudo a2ensite your-site.com

And, then, reload Apache : 然后,重新加载Apache:

sudo /etc/init.d/apache2 reload


You then have to edit /etc/hosts to add a line like this : 然后,您必须编辑/ etc / hosts以添加如下所示的行:

127.0.0.1       your-site.com

So "your-site.com" actually points to your own computer. 因此,“your-site.com”实际上指向您自己的计算机。


What is important is that the name used to access your website in a browser is the one that is declared in the hosts file ; 重要的是,用于在浏览器中访问您的网站的名称是在hosts文件中声明的名称; it also must be the same than the one used by the ServerName directivr in Apache's configuration. 它也必须与Apache配置中ServerName directivr使用的相同。


When you have done that for one VirtualHost... It's just the same for every other one : only the name of the site, and it's DocumentRoot, change. 当你为一个VirtualHost做了这个......对于其他每个人来说都是一样的:只有站点的名称和它的DocumentRoot才会改变。


Hope this helps! 希望这可以帮助!

You could edit your /etc/hosts and add multiple names pointing to 127.0.0.1, then add VirtualHost entries for each of those names. 您可以编辑/ etc / hosts并添加指向127.0.0.1的多个名称,然后为每个名称添加VirtualHost条目。 Depending on your server, the config could be in /etc/apache2/conf/httpd.conf or in /etc/apache2/sites-available. 根据您的服务器,配置可以在/etc/apache2/conf/httpd.conf或/ etc / apache2 / sites-available中。 If it's the latter, then here is the first google hit that I got for the config. 如果是后者,那么是我获得配置的第一个谷歌点击。

localhost has nothing to do with apache, but is an alias to your machine (ip 127.xxx). localhost与apache无关,但是是你机器的别名(ip 127.xxx)。

you'll have to edit /etc/hosts to accomplish what you want. 你必须编辑/etc/hosts来完成你想要的。

why do you want to do that? 你为什么要那样做? isn't http://localhost/newsite enough? 不是http:// localhost / newsite吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM