This project demonstrates an end-to-end setup for a PHP and MySQL application, leveraging Apache2 as the web server. Follow these instructions to run the application locally on your Linux machine.
Before you begin, ensure you have the following installed on your Linux machine:
- Apache2
- PHP 8.2
- MySQL
- Composer
Download and install Composer globally:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Navigate to your project directory and initialize Composer:
cd task-management-system
composer init
Install the necessary PHP packages:
composer install
composer require vlucas/phpdotenv
Install Apache2:
sudo apt install apache2
Install PHP 8.2 along with the required modules:
sudo apt-get install php8.2 php8.2-mysql php8.2-cli php8.2-common
sudo apt-get install php-mysql
sudo a2enmod php8.2
sudo systemctl restart apache2
After completing the setup, place your PHP project files in the appropriate Apache directory (commonly /var/www/html
). Then, navigate to localhost
or the respective IP address in your web browser to view your application.
If you encounter any issues, ensure that:
- All services (Apache2, MySQL) are running.
- PHP version compatibility is checked.
- File permissions are set correctly in the Apache directory.
This project is configured to run as a set of microservices using Docker Compose, which includes services for the frontend, user management (login, registration, and dashboard), a logout service, and a MySQL database. An Nginx service is used as a reverse proxy to route requests to the appropriate microservice based on the URL path.
- Docker
- Docker Compose
Use Docker Compose to build and start the services. This might take some time initially as Docker needs to build the images for each service.
docker-compose up --build
The --build flag ensures that Docker Compose builds the images before starting the containers.
Once all services are up and running, you can access the application by opening a web browser and navigating to:
http://localhost
This will take you to the frontend service. The Nginx reverse proxy routes requests to the appropriate microservice based on the URL path:
/
routes to the frontend service./pages/login
routes to the user login page provided by the users-service./pages/register
routes to the user registration page provided by the users-service./pages/logout
routes to the logout service./pages/dashboard
routes to the user dashboard provided by the users-service.
http {
server {
listen 80;
location / {
proxy_pass http://frontend:80/;
}
location /pages/login {
proxy_pass http://users-service:80;
}
...................................................................
This guide will walk you through the process of deploying the application on Minikube, including the frontend, logout and users-services, database, and Ingress for routing external traffic.
-
Start Minikube:
Begin by starting your Minikube cluster:
minikube start
-
Enable Ingress Controller:
Enable the Ingress controller in Minikube:
minikube addons enable ingress
-
Deploy all k8s files:
This will create the deployment and service for each of the services, and
PVC
for the database:- frontend-service: which contains the home page of the application
- users-service: which contains the users login and registration page with the dashboard after login.
- logout-service: which contains the logout page
- database: deploy mysql where we have the data of the users stored.
- ingress: route the traffic between the deployed services
kubectl apply -n NAMESPACE -f k8s/
-
Access the Application:
Get the Minikube IP to access your application:
minikube ip
Then, navigate to this IP address in your web browser. The Ingress controller will route the traffic to the appropriate services based on the path.
-
Delete Deployment:
To stop the application and free resources, you can delete the deployments and services:
kubectl delete -f path/to/deployment-or-service.yaml
To deploy the application, follow these steps:
Run the following script:
./build.sh
This script will handle the following tasks:
- Build EKS, VPC, Subnets, ECR, RDS, and Secret Manager for storing RDS credentials. It also deploys an EC2 instance for Jenkins to handle the CI process.
- Deploy a monitoring stack including Prometheus, Grafana, and Alertmanager.
- Set up Ingress.
After running the script, follow these steps:
- Update your local kubeconfig.
- Ensure all old Docker images are removed.
- Build a new Docker image for each service.
- Log in to ECR (Elastic Container Registry).
- Push the Docker images to the repositories created on the ECR.
- Create namespaces for the application and ArgoCD.
- Fetch RDS credentials from the Secret Manager and create Kubernetes secrets with them.
- Apply the Kubernetes manifest files.
- Reveal the LoadBalancer URL of all the deployed applications.
To set up Jenkins, follow these steps:
-
Initialize a Jenkins EC2 instance.
-
Connect to the EC2 instance via SSH.
-
Create a
file.sh
script and copy the contents fromjenkins-provision.sh
. This script installs Jenkins, Docker, and AWS CLI, and reveals the Jenkins default password. -
Access Jenkins using the public IP of the EC2 instance (available in the Terraform output).
-
In Jenkins, navigate to
Manage Jenkins > Manage Plugins
and install the "AWS Credential" plugin. -
Go to
Manage Jenkins > Manage Credentials > Global credentials
and add AWS secret key and secret access key. Assign an ID to these credentials. -
Add your
.env
file as a secret in Jenkins: -
Configure global environment variables in Jenkins:
-
Navigate to
Manage Jenkins > System → Global Properties
. -
Tick the
Environment variables
checkbox. -
Add the following environment variables with their respective values:
FRONTEND_REPOSITORY_URI
LOGOUT_REPOSITORY_URI
MYSQL_JOB_REPOSITORY_URI
USERS_REPOSITORY_URI
TAG
REGION
APP_DOCKERFILE_PATH
MYSQL_JOB_DOCKERFILE_PATH
-
-
Create a pipeline for each service
-
Go to the Jenkins Dashboard and click
Add Item
. -
Create a new pipeline and use SCM.
-
Add the Git repository URL (use credentials if the repository is private).
-
Ensure the branch name and path to the
Jenkinsfile
are correct.
For ArgoCD setup: