2014-02-26 106 views
0

我使用的是ubuntu 13.10 OS和LAMP,Apache 2.4。如何在ubuntu中創建一個虛擬主機13.10

我想在apache上創建一個虛擬主機。我嘗試了一些代碼,但沒有奏效。

進行了以下修改。但它不起作用。

首先我將HostnameLookups off更改爲HostnameLookups onetc\apache2\apache2.conf文件。然後,我添加了下面的代碼,

<VirtualHost *:80> 
ServerName local.scholarships.theiet.in 
DocumentRoot /home/www/my_project/public_html 
<Directory path_to_code_base/public> 
    Options -Indexes 
    Require all granted 
    DirectoryIndex index.php 
    AllowOverride All 
</Directory> 
</VirtualHost> 

重啓Apache後,我跑了http://localhost/。該網站未加載。

我怎樣才能運行http://localhost/

回答

0

這是另一種在ubuntu 13中創建虛擬主機的方法。10

下面的例子演示如何創建一個虛擬主機,

步驟1:上/home/user/www/

步驟創建一個名爲site1.com PHP項目2:在/etc/apache2/apache2.conf

更改 HostnameLookups offHostnameLookups on

第3步:創建一個名爲的配置文件上/etc/apache2/sites-available/

添加此代碼site1.com.conf

<VirtualHost *:80> 
ServerName site1.com 
ServerAlias www.site1.com 
ServerAdmin [email protected] 
DocumentRoot /var/www/site1.com 
ErrorLog ${APACHE_LOG_DIR}/error.log 
CustomLog ${APACHE_LOG_DIR}/access.log combined 
<Directory "/var/www/site1.com"> 
    Options All 
    AllowOverride All 
    Require all granted 
</Directory> 
</VirtualHost> 

步驟4:然後添加127.0.0.1 site1.com/etc/hosts.txt

步驟5:打開終端並運行命令,

sudo a2ensite site1.com 

sudo /etc/init.d/apache2 restart 

步驟6:打開瀏覽器,並運行http://site1.com/

試試這個

1

在這裏載入我的網站是如何創建在Apache/Ubuntu的virtural主持人:

我的000-default.conf文件:

<VirtualHost *:80> 
    DocumentRoot /var/www/php/frbit/l4blog/public/ 
    <Directory /var/www/php/frbit/l4blog/public/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride All 
    </Directory> 
    ServerName l4blog 
</VirtualHost> 

請注意,我創建了服務器名稱,這是我的新主機的名稱。

而且你可以在/ etc添加新的主機名/ hosts文件是這樣的:

127.0.0.1 your_host_name 

爲了不鍵入例如長的URL而不是

http://localhost/path/directory/file/... 

您只需輸入your_host_name在地址欄:在網站可用目錄現在必須「的.conf」結束

your_host_name 
1

您的配置文件的文件名,所以在/ etc/apache2/sites-available /添加你的.conf文件,以example.com.conf的風格命名;它的模型在以下方面:

<VirtualHost *:80> 
ServerAdmin [email protected] 
    ServerName www.example.com 
    DocumentRoot /var/www/example.com 
    <Directory /> 
      Options FollowSymLinks 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride All 
    require all granted 
    </Directory> 

    ErrorLog /var/log/apache2/example.com.error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel warn 

    CustomLog /var/log/apache2/example.com.access.log combined  
</VirtualHost> 

在Apache中與啓用:

$ sudo a2ensite example.com 

(如果你需要禁用它以後使用$ sudo的a2dissite example.com)

您可能還需要添加一行到/ etc/hosts文件:

127.0.0.1 example.com 

不要忘了,雖然你已經添加的網站到apache的apache,你也需要重新啓動apache。

+0

得到錯誤而重新啓動Apache的「命令:無法初始化政策插件」 –

+0

這是完全不同的東西 - 你上面有涉及到兩個高品質的答案你的虛擬主機問題。如果您有更多問題,請創建新帖子。 – carousel

+1

但是爲了更有幫助,我認爲這個問題(re sudo)已經在askubuntu網站http://askubuntu.com/questions/170216/sudo-doesnt-work :-)上得到解決 – kguest