A lightweight, efficient, and extensible web server written in C. Supports static file serving, PHP execution, concurrent clients, and real-time logging.
- π Static file serving: Supports
.html,.css,.js,.jpg,.png,.mp4,.pdf, etc. - π₯ Multi-client handling: Uses POSIX threads (
pthread) for concurrency. - π HTTP/1.1 Keep-Alive: Keeps connections alive for multiple requests per client.
- βοΈ PHP script execution: Handles
.phpfiles using system-installed PHP interpreter. - β‘ High performance: Uses
sendfile()for kernel-level, zero-copy static file delivery. - πͺ΅ Real-time logging: Logs all activity to both terminal and
logs/server.log. - π§Ύ Detailed request logs: Timestamp, log level, IP, request path, thread ID, and status.
- β Error handling: Sends 404 and 405 HTTP responses where appropriate.
- π Path traversal protection: Blocks unsafe URL paths like
../.
- GCC (or compatible compiler)
- POSIX-compliant system (Linux recommended)
- PHP installed and available via
phpcommand
- Server starts on port
8080and listens for incoming connections. - Each client gets its own thread for handling requests.
- Request is parsed β only
GETis supported. - If file is
.php, server usespopen()to execute PHP and return output. - For static files, server sends file directly using
sendfile()for speed. - Server logs each interaction with client.
make
./server
Once the server is running, open your browser and go to: http://localhost:8080/