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 m2.dev

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

<VirtualHost *:80>
  ServerName yourdomain.com
  ServerAlias www.yourdomain.com m2.dev www.m2.dev
  DocumentRoot "/opt/bitnami/apps/magento/htdocs/"
  Include "/opt/bitnami/apps/magento/conf/httpd-app.conf"
</VirtualHost>

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

sudo /opt/bitnami/ctlscript.sh 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 http://m2.dev/ and “Secure Base URL” to https://m2.dev/ and click save. After saving the user will be logged out of the system as the m2.dev 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.

192.168.1.108 m2.dev www.m2.dev

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

Source: http://bit.ly/2qgRjTQ

Advertisements
Posted in Uncategorized

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s