在linux上为opencart设置虚拟主机/多个商店

时间:2017-02-10 08:41:38

标签: linux apache opencart virtual-hosts lampp

我正在使用 Opencart 2.0 ,我想为第二家商店设置虚拟主机。我也在 Kali Linux 上使用 Xampp 。我在/opt/lampp/htdocs/main_store/有主商店,我用来访问它的网址是localhost/main_store我在后端创建了第二个商店,我已将其网址设置为http:localhost/store_2。我已经编辑了/etc/hosts并且添加了我的服务器名称

   127.0.0.1    localhost
   127.0.1.1    hostname

   127.0.0.1    localhost/store_2

我已编辑了/opt/lampp/etc/extra/http.v-hosts.conf并添加了

  # Sub domain localhost/store_2
 <VirtualHost *:80>
    DocumentRoot "/opt/lampp/htdocs/main_store/"
    ServerName localhost/store_2

    <Directory "/opt/lampp/htdocs/main_store/">
     Options Indexes FollowSymLinks MultiViews Includes 
     AllowOverride All 
     Order allow,deny 
     Allow from all 
     </Directory>
 </VirtualHost>

当我输入localhost/store_2时,我收到一个未找到对象的错误。我做错了什么?

1 个答案:

答案 0 :(得分:0)

第1步:在/etc/hosts中添加自定义主机。在您的终端中执行此操作

 sudo gedit /etc/hosts

然后添加自定义主机。例如,我的自定义主机是 mysite ,因此我添加了127.0.0.1 mysite。在您的情况下,它是 store_2

 127.0.0.1  localhost
 127.0.1.1  yourhostname

 127.0.0.1  mysite

第2步:。通过编辑httpd.conf

启用虚拟主机
   sudo gedit /opt/lampp/etc/httpd.conf

查找 #Include etc / extra / httpd-vhosts.conf 并删除#以取消注释此行

第3步:打开httpd-vhosts.conf文件添加新的虚拟主机

 sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf

通常,默认情况下,此文件中有两个虚拟主机。注释这些虚拟主机或删除它们。例如在我的情况下

#<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host.example.com
#DocumentRoot "/opt/lampp/docs/dummy-host.example.com"
#ServerName dummy-host.example.com
#ServerAlias www.dummy-host.example.com
#ErrorLog "logs/dummy-host.example.com-error_log"
#CustomLog "logs/dummy-host.example.com-access_log" common
#</VirtualHost>

#<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host2.example.com
#DocumentRoot "/opt/lampp/docs/dummy-host2.example.com"
#ServerName dummy-host2.example.com
#ErrorLog "logs/dummy-host2.example.com-error_log"
#CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>

然后添加

 NameVirtualHost 127.0.0.1
 <VirtualHost 127.0.0.1> 
   DocumentRoot /opt/lampp/htdocs/
   ServerName localhost
</VirtualHost>

<VirtualHost mysite>
    ServerAdmin webmaster@localhost
    DocumentRoot /opt/lampp/htdocs/your_project_folder/
    ServerName mysite
    ServerAlias mysite
    RewriteEngine On
    RewriteOptions inherit
    CustomLog /var/log/apache2/mysite.log combined
    <Directory /opt/lampp/htdocs/your_project_folder/>
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

在上面的代码中,项目文件夹是 main_store 。同时用 store_2

替换 mysite

第4步:重启XAMPP服务器。这非常重要

    sudo /opt/lampp/lampp restart

第5步:在浏览器的地址栏中键入http://mysite/,它应该可以正常工作。在您的情况下http://store_2/