Before we get started, I think it best to explain a little bit what my intentions on here. I would like to integrate Metabase into a flask application that I have already built. Therefore, the tutorial will cover the extent of the work I did to get all of that set up properly. However, I will try to color the Flask step in a different color so that you can still use the tutorial for just Metabase installations on Ubuntu. Additional note, I like to run all of my commands as root so that I don’t have to type in sudo each time, but that is completely up to you.
Step One: Download Tools
Step Two: Create Database
If you are using MySQL like I am you can follow these commands:
Step Three: Configure PHPMyAdmin
Step Four: Configure Access Through Groups
At this stage, I needed to configure permissions so that Metabase could have access to certain files and directories on the server. I decided that the best practice for my server was to create a new user and a new group to handle this dilemma.
I decided to change the apache run group to Metabase so that I could give apache certain access to the HTML directory. This is helpful for if you decide to place your jar file inside of the HTML directory because it will now have permission to create files in this directory.
Step Five: Download & Configure Metabase
This step really focuses on the foundation that you need in order to setup metabase as a service for Ubuntu. You will basically need to setup to configuration files. The first file, /etc/init.d/metabase, controls what bash commands you can use on metabase. For example, sudo service metabase start. The next config file is all of the configuration variables that metabase will need to know in order to launch properly.
Additional Documentation: Note: I did have to change the start command to have the default config variables imported before the jar file ran.
Step Six: Setup Proxy with Apache2
This is a really important step because without it whenever someone hits your domain apache will not know how to send it to the metabase service on port 3000.
Enable the Proxy:
Setting up Metabase as a Service
Allow Ports to access the database
The last thing you will need to do on our server is configured the firewall. For right now we are going to open ports 80 & 443 to access the database. Later I would HIGHLY recommend changing this so that only 443 can access the database. For just testing our setup port 80 is fine.
sudo service metabase start
This concludes the setup guide for metabase, if you seem to be running into issues I would recommend running this command:
sudo tail -vf /etc/log/metabase.log
It definitely helped me debug my metabase problems. Feel free to comment with any questions and I will try to respond whenever I can.
Part Two: Flask Integration
My overall goal was to find a way to integrate my flask application with metabase. This part of the tutorial finalizes all the steps you would need to complete a metabase and flask integration.
Step One: Permissions
First, if you followed step four from above, I would go ahead and add whatever user you are to the metabase group. This will be helpful later on when you try to access files inside of the git repository.
Note: During the vim setup.sh command above, I was adding pip install PyMySQL to my virtualenv.
Step Two: Edit WSGI File
NOTE: At this point, it would be a good idea to go into your flask application and set your database connection to match the metabase database that we set up earlier. E.g: DB=MySQLDatabase(‘DB_Name’, user=’user’, password=’pass’,host=’localhost’)
Edit Apache Configuration
The flask application should run right when you go to the root directory; however, if you type /metabase/ to the end of url metabase will activate. I hope that this tutorial was helpful, and if I can help in any way please just let me know. Thanks 🙂