In this article, we introduce the project that you will work on throughout this course. You will develop Ansible playbooks to deploy the KodeKloud ecommerce website—a fictional online store selling electronic devices. This project is divided into stages, starting with setting up a lab environment and creating simple playbooks, and then progressing to advanced best practices using includes and roles. The KodeKloud ecommerce website uses a LAMP stack architecture:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- Linux as the operating system
- Apache HTTP Server for web services
- MariaDB as the database (a community fork of MySQL)
- PHP for server-side scripting
The focus of this project is on automating the deployment process with Ansible, rather than making changes to the application code itself.
- Choosing the deployment system (we use a CentOS Linux machine).
- Installing and configuring the Apache HTTP server, then enabling and starting the service.
- Installing and configuring the MariaDB database, then enabling and starting the service.
- Installing and configuring PHP.
- Downloading and setting up the application code such that it correctly connects to Apache and PHP.
- Configuring the system further by setting up the firewall and creating the necessary rules.
Step 1: Setting Up the Firewall
First, install firewalld on your CentOS system. Run the following commands to install, start, and enable the firewall service:Step 2: Configuring the MariaDB Database
Begin by installing the MariaDB server. Next, update the/etc/my.cnf file to change port settings if needed (remember that although the file is named my.cnf, it is also used by MariaDB). Then, start and enable the MariaDB service.
Make sure the database credentials and port settings in your configuration match those specified in your Ansible playbooks.
Step 3: Configuring the Web Server
This step involves installing Apache, PHP, and PHP-MySQL to enable database connectivity. Then, update the firewall rules to allow HTTP traffic and modify Apache’s configuration to useindex.php as the default file.
Install the necessary packages:
index.php:
Step 4: Deploying the Application Code
Clone the repository containing the KodeKloud ecommerce application code. If Git isn’t installed, install it first:index.php file with the correct database details (address, name, user ID, and password). Finally, verify the deployment with a simple test:
- Update
index.phpon the web server with the database server’s IP address. - In the database server, specify the web server’s IP address when configuring user access. This ensures that only the authorized web server can connect.
Always ensure that your database user permissions and firewall settings are secured in both single and multi-node setups to prevent unauthorized access.
Step 5: Reviewing the PHP Connection in the Application
The primary file to focus on within the application isindex.php, which contains the database connection details. The critical line in the file is:
Demo and Next Steps
After reviewing this demo:- Set up your project environment.
- Create Ansible playbooks to automate the deployment.
- Practice deploying the KodeKloud ecommerce application following the steps provided.