I am using Opencart 2.0 and I want to set up a virtual host for the second store. I am also using Xampp on Kali Linux. I have the main store at /opt/lampp/htdocs/main_store/
and the url I am using to access it is localhost/main_store
I have created a second store in the backend and I have set its url to http:localhost/store_2
. I have edited my /etc/hosts
and I have add my server name
127.0.0.1 localhost
127.0.1.1 hostname
127.0.0.1 localhost/store_2
I have edited my /opt/lampp/etc/extra/http.v-hosts.conf
and added
# 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>
When I type localhost/store_2
I get an object not found error. What am I doing wrong?
Step 1: Add your custom host in /etc/hosts
. Execute this in your terminal
sudo gedit /etc/hosts
Then add your custom host. For example my custom host is mysite so I have added 127.0.0.1 mysite
. In your case it is store_2
127.0.0.1 localhost
127.0.1.1 yourhostname
127.0.0.1 mysite
Step 2:. Enable virtual hosts by editing httpd.conf
sudo gedit /opt/lampp/etc/httpd.conf
Find #Include etc/extra/httpd-vhosts.conf and remove the # to un-comment this line
step 3: Add new virtual host by opening the httpd-vhosts.conf file
sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf
Usually, by default there are two virtual hosts in this file. Comment these virtual hosts or delete them. For example in my case
#<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>
Then add
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>
In the above code, in your case the project folder is main_store. Also replace mysite with your store_2
Step 4: Restart XAMPP server. This is very IMPORTANT
sudo /opt/lampp/lampp restart
Step 5: Type http://mysite/
in browser’s address bar and it should work. In your case http://store_2/