In the last lesson, we discussed how software backends work. We learnt that a backend comprises of different server applications which are installed and configured to provide various services. In this lesson, we will install some of those server applications for the backend of our Google Contacts Clone app. The server applications we will install are: 1. MySQL database server, and 2. Redis server. We will also install Postman which will be used for testing our API endpoints before we connect them to the frontend.
Installing and Configuring MySQL Database Server
-
For Linux, open this link and follow the instructions to install for your Linux environment.
-
For Windows, open this link and follow the instructions for your Windows environment.
-
For MacOs, open this link and follow the instructions for your MacOS environment.
Write down the password you provided for the root user during MySQL installation.
Installing MySQL Workbench
-
Download and install MySQL Workbench for your OS from here.
-
When you are done installing, launch MySQL Workbench. Next you will add a new connection.
-
Click the [+] icon to the right of the MySQL Connections title on the home screen. This opens the Setup New Connection form.
- In
Connection Namefield, enter:Root - Local Connection. - Leave the
HostnameandPortfields with the default values of127.0.0.1and3306, respectively. - Leave the
Usernameasroot. - In the
Passwordfield, click theStore in Vault...button. Enter the root password. - At the bottom right of the dialog box, click
Test Connect. If everything is right, a success alert will be displayed. - Click
OKto close the dialog box. Then click on theRoot - Local Connectionconnection now listed on the home. This will open the Workbench interface.
- In
Creating the schema for our project
Schema is another word for database
- At the bottom of the Navigator panel on the left side of the Workbench interface, switch to the
Schemastab. Within theSchemapanel, right click and chooseCreate Schemaon the context menu. This opens thenew_schematab. - In the Name field, enter
google_contacts_clone_appas the name of the schema. - For
Charset/Collation, selectutf8as theDefault Charsetand selectutf8_general_cias the Default Collation. - At the bottom right, click
Apply. On theApply SQL Script to Databasedialog, clickApplyto create the schema using the SQL statement shown. ClickFinishwhen the success message is shown within dialog box. - Check the
Schematab on the left-side of the interface. Now, you will see your newly-createdgoogle_contacts_clone_appschema.
Creating a User for our Schema (Database)
For our API server to connect to our database (schema), we need to provide an existing user within our database server and the password for that user. The user must have full access to the schema we want to connect to. By default, the root user has full access to any schema created plus full administrative permissions within the database server. So, we can easily provide the API server with the credentials (name and password) of the root user and move on. However, this is not recommended. It is not advisable to connect to a database (schema) for a web application with the root user. It poses create security risks. The root user should be reserved for administrative tasks which are usually performed over the command line (terminal) such as periodic backups, dropping of schemas, etc.
So, the recommended approach is to create a dedicated user within our database server which will have access to only the google_contacts_clone_app schema. Let’s do this.
- On the left-side of the interface, switch to the
Administrationtab. Within the tab and underManagement, clickUsers and Privileges. This opens theAdministration - Users and Privilegestab window. - Under the
User Accountspanel, clickAdd Account. Within theDetails for account...panel, do the following:- For
Login Name, enter:google_contacts_clone_user. - For
Authentication Type, selectStandard. - For
Limit to Hosts Matching, enter127.0.0.1. This is because we do not want connections to our local database server from the internet. Only within our local computer. - For
Password, enter a secure password and note it down somewhere. We will make use of it when setting up ourAPI server. Confirm the password in the next field. - Now, we want to specify which schema this user should have access to. Switch to the
Schema Privilegestab. ClickAdd Entry...button. Within theNew Schema Privilege Definitiondialog box, switch toSelected schemaand selectgoogle_contacts_clone_app. ClickOKto close the dialog box. - Now, we want to specify which rights the user has within the
google_contacts_clone_appschema. At the bottom right of theSchema Privileges, clickSelect "ALL". You will notice that theGRANT OPTIONis not selected. This is okay as we don’t want this user to be able to grant other users rights. - Click
Applyto create the user with the attached privileges. - The new user
google_contacts_clone_useris now listed within theUser Accountpanel.
- For
You can close MySQL Workbench for now.
Installing the Redis Server
Follow the instructions in the article to install Redis Server on Windows, Linux, or MacOS.
When you are done, open any command line (or terminal) of your choice, enter:
redis-cli ping
PONG # <-- response
You will get: PONGas response.
Why did we install Redis Server. Initially, Redis server will be used mainly for storing authentication tokens of logged-in users and ensuring they self-expire after a given time. Later on, Redis server will be used for caching the data of our contact for fast fetching.
Installing the Postman
Visit https://www.postman.com/downloads/ to download and install for your environment.
This concludes the installation and setup of our backend. In the next lesson, we will discuss why we chose AdonisJS for this project by highlighting its features and capabilities.
