Adding virtual host to bitnami magento 2 virtual machine

To setup virtual host on the bitnami virtual machine two files will have to be changed. They are htaccess.conf and httpd-vhosts.conf. These files are located at /opt/bitnami/apps/magento/conf/ folder.

First we have to update the htaccess file and add the following lines at the end –

SetEnvIf Host ^m2\.dev MAGE_RUN_CODE=base
SetEnvIf Host ^m2\.dev MAGE_RUN_TYPE=website

Here, the MAGE_RUN_CODE’s value “base” is the code for the default magento stores front-end and “^m2\.dev” is regular expression for setting domain staring with

Once the htaccess file is updated. Now, we have to update the httpd-vhosts.conf file and add the alias.

<VirtualHost *:80>
  DocumentRoot "/opt/bitnami/apps/magento/htdocs/"
  Include "/opt/bitnami/apps/magento/conf/httpd-app.conf"

Once these two files are updated we have to restart apache server by running the following command –

sudo /opt/bitnami/ restart apache

Now, we have to login to the admin using IP address one last time and go to stores > configuration > web. We have to update the “Base URL” to and “Secure Base URL” to and click save. After saving the user will be logged out of the system as the domain is applied. Login back to the admin panel and now you will see notification to refresh cache. Follow the link and refresh the cache. Now you are ready to use the virtual host with this virtual machine.

Don’t forget to add the virtual host IP in the host computers /etc/hosts file.

To keep the virtual host setup from getting reset follow the following steps.

Additional Task:
Every time the virtual machine is restarted the IP is automatically assigned as the base url of magento. This is done to ensure the application adapt to a changing IP address on each restart. But in our case this becomes a problem as on each restart we have to go and set the virtual host domain again. To stop this from happening we have to rename two files at /opt/bitnami/apps/magento/ the files that needs to be renamed are updateip and bnconfig.

mv /opt/bitnami/apps/magento/updateip /opt/bitnami/apps/magento/updateip.old
mv /opt/bitnami/apps/magento/bnconfig /opt/bitnami/apps/magento/bnconfig.old



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.