Skip to content

savaliyabhargav/multi_threaded_web_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


# Multi-Threaded Web Server (C++ with Docker)

## Overview
This project is a custom multi-threaded web server implemented in C++, designed to serve static and dynamic content.  
The development environment runs entirely inside Docker containers, including the server and database (MySQL).

---

## Features
- C++ multi-threaded web server core
- Thread pool, job queue, buffering, and caching support
- MySQL database for dynamic site support
- Fully Dockerized environment
- Easy to extend and configure

---

## Project Structure

project-root/ │ ├── docker-compose.yml # Defines cpp-server & mysql services ├── docker/ │ ├── cpp-server/ │ │ └── Dockerfile # C++ dev container build instructions │ └── mysql/ │ └── custom.cnf # MySQL config (optional) ├── mysql_data/ # MySQL persistent storage (auto-created) ├── .gitignore └── README.md


---

## Development Environment Setup

### **1. Clone the repository**
```bash
git clone <your-repo-url>
cd multi-threaded-webserver

2. Build and start containers

docker compose build
docker compose up -d

3. Verify containers are running

docker ps

You should see:

cpp-server   ...   Up
mysql        ...   Up

Testing MySQL Connection from cpp-server

  1. Enter the cpp-server container:
docker compose exec cpp-server bash
  1. Check MySQL CLI is installed:
mysql --version
  1. Connect to MySQL service:
mysql -h mysql -u webuser -pwebpass webserver_db
  • Host: mysql (service name from docker-compose.yml)
  • User: webuser
  • Password: webpass
  • Database: webserver_db
  1. Run a test query:
SHOW TABLES;

If everything is set up correctly, you’ll see:

Empty set (0.00 sec)

(That’s fine — no tables yet.)

  1. Exit:
exit;

Restarting the Environment

docker compose down       # Stop all containers
docker compose up -d      # Start containers again

Services

  • cpp-server — C++ development container with MySQL client & headers installed
  • mysql — MySQL database container (with persistent volume at mysql_data/)

License

MIT License


---


You’re right—my bad. Your flow is:

1. run the Makefile → 2) run `./server` → 3) hit it with curl.
   Here’s the exact, minimal sequence:

2. Build

```bash
make clean && make
  1. Run the server
./server

You should see:

✅ Server listening on http://localhost:8080
  1. Test from another terminal
curl -i http://localhost:8080

You should get a 200 OK with your HTML body. The server terminal will print the request.

Quick fixes if something blocks you:

  • Address already in use: a previous server is running. Kill it:

    pkill -f ./server

    then run ./server again.

  • No response: make sure you’re curling the same machine the server runs on (and port 8080).

Once you confirm this works, say “Step 1 complete” and I’ll plug in the queue (no behavior change yet—just routing requests through FIFO).

If you push this version to GitHub now, anyone cloning your repo can bring up the environment and confirm MySQL connectivity without asking you how.

Do you want me to also include a small connection test C++ program in /src so that the first time you run the container, it can already demonstrate talking to MySQL? That could make verification even easier before we start Step 5.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published