commit b6a258b3cfc67b8697d5b05b02fa959ca1bb034e Author: WOBBLEFANG THE THIRD Date: Sun Apr 19 19:22:38 2026 +0200 idk anymore! please put the dog down (me)! diff --git a/.env b/.env new file mode 100644 index 0000000..60996c7 --- /dev/null +++ b/.env @@ -0,0 +1,9 @@ +# Database +DB_HOST=database +DB_NAME=pawra +DB_USER=appuser +DB_PASSWORD=pick-a-real-password-here +DB_ROOT_PASSWORD=pick-another-real-password + +# App +APP_ENV=development \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1519588 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pawra.iml b/.idea/pawra.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/pawra.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..8d4f284 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b277dca --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM php:8.3-apache + +# Enable mod_rewrite for clean URLs +RUN a2enmod rewrite + +# Install PHP extensions +RUN docker-php-ext-install pdo_mysql + +# Copy Apache vhost config +COPY docker/apache.conf /etc/apache2/sites-available/000-default.conf + +# Copy all project files into the container +COPY . /var/www/html + +# Fix permissions +RUN chown -R www-data:www-data /var/www/html + +WORKDIR /var/www/html \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..da63586 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,30 @@ +services: + server: + build: . + restart: always + ports: + - "8080:80" + volumes: + - ".:/var/www/html" # whole project, not just src/ + environment: + - DB_HOST=${DB_HOST} + - DB_NAME=${DB_NAME} + - DB_USER=${DB_USER} + - DB_PASSWORD=${DB_PASSWORD} + depends_on: + database: + condition: service_healthy + + database: + image: mariadb:lts + restart: always + environment: + MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} + MARIADB_DATABASE: ${DB_NAME} + MARIADB_USER: ${DB_USER} + MARIADB_PASSWORD: ${DB_PASSWORD} + healthcheck: + test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] + interval: 10s + timeout: 5s + retries: 5 \ No newline at end of file diff --git a/docker/apache.conf b/docker/apache.conf new file mode 100644 index 0000000..2d26a7a --- /dev/null +++ b/docker/apache.conf @@ -0,0 +1,14 @@ + + DocumentRoot /var/www/html/public + + PassEnv DB_HOST DB_NAME DB_USER DB_PASSWORD + + + AllowOverride All + Require all granted + Options -Indexes + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + \ No newline at end of file diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..7b0f6f9 --- /dev/null +++ b/public/index.php @@ -0,0 +1,27 @@ +index(); +} \ No newline at end of file diff --git a/src/Controllers/HomeController.php b/src/Controllers/HomeController.php new file mode 100644 index 0000000..59a7c32 --- /dev/null +++ b/src/Controllers/HomeController.php @@ -0,0 +1,24 @@ +db->query("SELECT * FROM posts LIMIT 10")->fetchAll() + ); + + View::render('home', $data); + } +} \ No newline at end of file diff --git a/src/Database.php b/src/Database.php new file mode 100644 index 0000000..eb457bd --- /dev/null +++ b/src/Database.php @@ -0,0 +1,32 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ] + ); + } + return self::$instance; + } +} \ No newline at end of file diff --git a/src/View.php b/src/View.php new file mode 100644 index 0000000..89232bb --- /dev/null +++ b/src/View.php @@ -0,0 +1,22 @@ + + + + + <?= htmlspecialchars($data->pageTitle) ?> + + +

pageTitle) ?>

+ + posts as $post): ?> +

+

+ + + + \ No newline at end of file diff --git a/src/migrations.php b/src/migrations.php new file mode 100644 index 0000000..58216b0 --- /dev/null +++ b/src/migrations.php @@ -0,0 +1,27 @@ +exec("CREATE TABLE IF NOT EXISTS users ( + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + email VARCHAR(255) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +)"); + +$db->exec("CREATE TABLE IF NOT EXISTS posts ( + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + user_id INT UNSIGNED NOT NULL, + title VARCHAR(255) NOT NULL, + body TEXT NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE +)"); + +echo "Migrations ran successfully.\n"; \ No newline at end of file diff --git a/src/seeds.php b/src/seeds.php new file mode 100644 index 0000000..9935f56 --- /dev/null +++ b/src/seeds.php @@ -0,0 +1,45 @@ +exec("SET FOREIGN_KEY_CHECKS = 0"); +$db->exec("TRUNCATE TABLE posts"); +$db->exec("TRUNCATE TABLE users"); +$db->exec("SET FOREIGN_KEY_CHECKS = 1"); + +$users = [ + ['luna', 'luna@pawra.dev', 'password123'], + ['marco', 'marco@pawra.dev', 'password456'], +]; + +$insertUser = $db->prepare( + "INSERT INTO users (username, email, password) VALUES (?, ?, ?)" +); + +foreach ($users as [$username, $email, $password]) { + $insertUser->execute([ + $username, + $email, + password_hash($password, PASSWORD_DEFAULT), + ]); +} + +$posts = [ + [1, 'First post', 'Hello from Luna — Pawra is live!'], + [1, 'Getting started', 'Here is how I set up my profile...'], + [2, 'Hello Pawra', 'Marco here, excited to join!'], +]; + +$insertPost = $db->prepare( + "INSERT INTO posts (user_id, title, body) VALUES (?, ?, ?)" +); + +foreach ($posts as $post) { + $insertPost->execute($post); +} + +echo "Seeded successfully.\n"; \ No newline at end of file