adding server code

This commit is contained in:
Janis Steiner
2024-01-14 11:48:31 +00:00
parent c3f3fb85af
commit 343720365a
5 changed files with 140 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
<VirtualHost *:80>
ServerName cyberhex.srv
DocumentRoot /var/www/html
#SSLEngine on
#SSLCertificateFile /etc/apache2/certs/fullchain.pem
#SSLCertificateKeyFile /etc/apache2/certs/privkey.pem
#SSLCertificateChainFile /etc/apache2/certs/chain.pem
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName cyberhex.srv
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateKeyFile /etc/apache2/certs/privkey.pem
SSLCertificateFile /etc/apache2/certs/fullchain.pem
# SSLCertificateChainFile /etc/apache2/certs/fullchain.pem
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

View File

@@ -0,0 +1,48 @@
<?php
$servername = "cyberhex-db";
$username = "root";
$password = "1234";
$database = "cyberhex_db";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE IF NOT EXISTS $database";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully\n";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
// Connect to the new database
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create sample tables
$sql = "CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL
)";
if ($conn->query($sql) === TRUE) {
echo "Table 'users' created successfully\n";
} else {
echo "Error creating table: " . $conn->error;
}
$conn->close();
?>

View File

@@ -0,0 +1,45 @@
version: '3.8'
services:
cyberhex-db:
image: mysql:latest
container_name: cyberhex-db
environment:
MYSQL_ROOT_PASSWORD: 1234
networks:
cyberhex-network:
ipv4_address: 192.168.178.2
# ports:
# - "3306:3306"
volumes:
- cyberhex-db-storage:/var/lib/mysql
cyberhex-srv:
build:
context: .
dockerfile: srv_dockerfile
container_name: cyberhex-srv
networks:
cyberhex-network:
ipv4_address: 192.168.178.3
ports:
- "80:80"
- "443:443"
depends_on:
- cyberhex-db
volumes:
- ./cyberhex-code:/var/www/html
- ./apache-conf:/etc/apache2/sites-available
- ./certs:/etc/apache2/certs
networks:
cyberhex-network:
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.178.0/24
volumes:
cyberhex-db-storage:
external: true

5
src/server/install.txt Normal file
View File

@@ -0,0 +1,5 @@
1: download the file docker-compose.yml and the folder cyberhex-code
2: create the cyberhex-db-storage volume
3: request some ssl certs via certbot form letsencrypt and put them into certs/
sudo certbot certonly --manual --preferred-challenges=http --http-01-port=8080
3: use docker-compose up to start the whole thing

View File

@@ -0,0 +1,7 @@
# Extend the official PHP image
FROM php:apache
# Install the mysqli extension
RUN docker-php-ext-install mysqli
RUN a2enmod ssl
RUN service apache2 restart