Your web applications need a solution to store and retrieve its data. A relational database is often used in web
applications. MySQL, MariaDB and PostgreSQL are some popular relational databases. There’s also SQLite. Many
applications can use any of these relational databases by the virtue of the database layer abstraction. If you are
writing your own web application, pick any one database and install it on your web server.
Install The Database
- Install the package.
- Enable and start the database
- Initialize the database server.
- Create databases.
- Create database users and set their passwords.
Connect The Web Application To The Database Server
- Database hostname. In the simple lab exercise, the same Linux host, hosts the web server as well as the database server
- Database name
- Database username
- Database password. The applications can connect to database using a number of authentication mechanisms. Let us focus
on the simplest one, ie authenticating using username and password.
Use the credentials in your web application. I have repeatedly emphasized on using your own reference application for
the labs. For this exercise, you may also use an open source web application such as WordPress.
Backup And Restore
The next step is to think about backups and restoration. What if the server goes down for some hardware or software
failure? Create a script to generate a backup and store the backup in an external system such as another VM. Use a
cron job to execute the backup script on a schedule. Frequently perform a restore test.
Take the game to the next level with database replication.
As with any other DevOps project, use IAC to manage the database servers. Write a shell script or Ansible playbook to
perform the database installation steps.
Tech Chorus References