This repository contains implementations of an HTTP server for both Linux (WSL) and Windows environments. The server serves static files and handles PHP scripts, supporting various HTTP methods.
- Static File Serving: Serve HTML, CSS, JavaScript, images, etc., from a designated directory (
./www
by default). - PHP Integration: Execute PHP scripts via PHP CGI (
/usr/bin/php-cgi
{Linux[WSL]} and:\php\php-cgi.exe
[Windows] path adjustable). - HTTP Methods Supported: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, COPY, LINK, UNLINK, PURGE, LOCK, UNLOCK, PROPFIND, VIEW.
- HTTP Response Handling: Proper status codes and content types for different file types and methods.
- Multi-threaded Handling: Handles multiple client connections concurrently using C++ threads.
-
Linux Version (WSL):
- Windows Subsystem for Linux (WSL)
- C++ compiler compatible with C++23
-
Windows Version:
- Visual Studio Code (for Windows version codebase)
- MinGW (for compilation on Windows)
- C++ version: C++23, adjust in your code editor configuration
-
Open a WSL terminal or Linux terminal
# bash for example
-
Clone the Repository:
git clone https://github.com/aashishbishow/http_servers.git
-
Navigate to Linux folder:
cd http_servers/Linux
-
Open in a Code editor:
code . # for vs code
-
Do the necessary configuration:
- Read Customization
-
Compile the Server:
g++ -std=c++2b -o server http.cpp -pthread
-
Run the Server:
./server
By default, the server listens on port 8080
.
- Type
localhost
in your browser's address bar and hit enter for defaultindex.html
. - Type
localhost:8080/path_to_your_file
in your browser's address bar and hit enter for your specific file.
- Place your static files (HTML, CSS, JavaScript, images, etc.) in the
./www
directory. - PHP scripts can be placed alongside static files with the
.php
extension.
- Adjust
PORT
,BUFFER_SIZE
,WEB_ROOT
, andPHP_CGI
inhttp.cpp
as per your requirements.
-
Open a command prompt or terminal(Powershell)
# for example
-
Clone the Repository:
git clone https://github.com/aashishbishow/http_servers.git
-
Navigate to Windows folder:
cd http_servers/Linux
-
Open in a Code editor:
code . # for vs code
-
Do the necessary configuration:
- Read Customization
-
Compile the Server:
g++ -std=c++2b -o server.exe http.cpp -lws2_32
-
Run the Server:
./server
By default, the server listens on port 8080
.
- Type
localhost
in your browser's address bar and hit enter to view the defaultindex.html
. - Type
localhost:8080/path_to_your_file
in your browser's address bar and hit enter to access a specific file in./www
.
- Place your static files (HTML, CSS, JavaScript, images, etc.) in the
./www
directory. - PHP scripts can be placed alongside static files with the
.php
extension.
- Adjust
PORT
,BUFFER_SIZE
,WEB_ROOT
, andPHP_CGI
inserver.cpp
as per your requirements.
Feel free to fork this repository, make improvements, and submit pull requests. Contributions are welcome!
This project is licensed under the MIT License. See the LICENSE file for details.