From 4edffd33ee5a53dbdee7d2f6a3f7c1727edaddc9 Mon Sep 17 00:00:00 2001
From: Julian PEREZ-RAMIREZ <julian.perez-ramirez@imt-atlantique.net>
Date: Sun, 23 Feb 2025 12:20:57 +0100
Subject: [PATCH] symfony app working with ngnix

---
 .docker/nginx/default.conf       | 20 ++++++++++++
 compose.yaml                     | 56 ++++++++++++++++++--------------
 composer.json                    |  8 -----
 Dockerfile => symfony.dockerfile |  0
 web_app/compose.override.yaml    |  7 ----
 web_app/compose.yaml             | 25 --------------
 www/app/Controllers/user.php     |  0
 www/app/Models/user.php          |  0
 www/app/Views/user.html          |  0
 www/config/config.php            |  0
 www/config/database.php          |  0
 www/index.php                    | 11 -------
 www/public/css/user.css          |  0
 www/public/images/ejem.txt       |  0
 www/public/js/script.js          |  0
 www/routes/web.php               |  0
 16 files changed, 51 insertions(+), 76 deletions(-)
 create mode 100644 .docker/nginx/default.conf
 delete mode 100644 composer.json
 rename Dockerfile => symfony.dockerfile (100%)
 delete mode 100644 web_app/compose.override.yaml
 delete mode 100644 web_app/compose.yaml
 delete mode 100644 www/app/Controllers/user.php
 delete mode 100644 www/app/Models/user.php
 delete mode 100644 www/app/Views/user.html
 delete mode 100644 www/config/config.php
 delete mode 100644 www/config/database.php
 delete mode 100644 www/index.php
 delete mode 100644 www/public/css/user.css
 delete mode 100644 www/public/images/ejem.txt
 delete mode 100644 www/public/js/script.js
 delete mode 100644 www/routes/web.php

diff --git a/.docker/nginx/default.conf b/.docker/nginx/default.conf
new file mode 100644
index 0000000..92f16ae
--- /dev/null
+++ b/.docker/nginx/default.conf
@@ -0,0 +1,20 @@
+server {
+    listen 80;
+    server_name localhost;
+    root /var/www/public;
+
+    index index.php index.html;
+
+    location / {
+    try_files $uri $uri/ /index.php?$query_string;
+    }
+
+    location ~ \.php(/|$) {
+        fastcgi_pass app:9000;
+        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+        include fastcgi_params;
+    }
+
+    error_log  /var/log/nginx/error.log;
+    access_log /var/log/nginx/access.log;
+}
\ No newline at end of file
diff --git a/compose.yaml b/compose.yaml
index f86b3c8..62d271e 100644
--- a/compose.yaml
+++ b/compose.yaml
@@ -1,40 +1,46 @@
 services:
-  symfony:
-    image: bitnami/symfony
-    container_name: symfony_app
+  web:
+    image: nginx:alpine
+    container_name: nginx_server
+    working_dir: /var/www
     ports:
-      - "80:8000"
-    environment:
-      - SYMFONY_PROJECT_SKELETON=symfony/skeleton
-      - DATABASE_HOST=mysql
-      - SYMFONY_DATABASE_PASSWORD=symfony
+      - "8080:80"
     volumes:
-      - ./web_app:/app
+      - ./web_app:/var/www
+      - ./.docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
     depends_on:
-      - mysql
+      - app
 
-  mysql:
-    image: mysql:8.1
+  app:
+    image: php:8.2-fpm
+    container_name: symfony_app
+    working_dir: /var/www
+    volumes:
+      - ./web_app:/var/www
+    environment:
+      - APP_ENV=dev
+    depends_on:
+      - db
+
+  db:
+    image: mysql:9.2.0
     container_name: symfony_db
     environment:
-      MYSQL_ROOT_PASSWORD: password
       MYSQL_DATABASE: wishlist_db
-      MYSQL_USER: symfony
-      MYSQL_PASSWORD: symfony
+      MYSQL_ROOT_PASSWORD: password
+      MYSQL_USER: admin
+      MYSQL_PASSWORD: admin_password
     ports:
       - "3306:3306"
     volumes:
       - ./mysql_data:/var/lib/mysql
 
-  phpmyadmin:
-    image: phpmyadmin/phpmyadmin
-    container_name: phpmyadmin
+  phpMyAdmin:
+    image: phpmyadmin:5.2.2-apache
+    container_name: phpMyAdmin
     ports:
-      - "8080:80"    #this line maps your pc port to the container port
-    depends_on:
-      - mysql    #this line links this container to the db container
+    - "8081:80"
     environment:
-      PMA_HOST: mysql
-
-#If you got an error about folder permissions with innodb_redo, 
-# try to fix it by running sudo chmod -R 755 ~/<your_path>/wishlist/mysql_data 
\ No newline at end of file
+      - MYSQL_ROOT_PASSWORD=password
+      - MYSQL_USER=admin
+      - MYSQL_PASSWORD=admin_password
\ No newline at end of file
diff --git a/composer.json b/composer.json
deleted file mode 100644
index 6da41e5..0000000
--- a/composer.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-    "require": {
-        "symfony/orm-pack": "^2.4"
-    },
-    "require-dev": {
-        "symfony/maker-bundle": "^1.62"
-    }
-}
diff --git a/Dockerfile b/symfony.dockerfile
similarity index 100%
rename from Dockerfile
rename to symfony.dockerfile
diff --git a/web_app/compose.override.yaml b/web_app/compose.override.yaml
deleted file mode 100644
index c5612b0..0000000
--- a/web_app/compose.override.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-services:
-###> doctrine/doctrine-bundle ###
-  database:
-    ports:
-      - "5432"
-###< doctrine/doctrine-bundle ###
diff --git a/web_app/compose.yaml b/web_app/compose.yaml
deleted file mode 100644
index 89c74d1..0000000
--- a/web_app/compose.yaml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-services:
-###> doctrine/doctrine-bundle ###
-  database:
-    image: postgres:${POSTGRES_VERSION:-16}-alpine
-    environment:
-      POSTGRES_DB: ${POSTGRES_DB:-app}
-      # You should definitely change the password in production
-      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
-      POSTGRES_USER: ${POSTGRES_USER:-app}
-    healthcheck:
-      test: ["CMD", "pg_isready", "-d", "${POSTGRES_DB:-app}", "-U", "${POSTGRES_USER:-app}"]
-      timeout: 5s
-      retries: 5
-      start_period: 60s
-    volumes:
-      - database_data:/var/lib/postgresql/data:rw
-      # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
-      # - ./docker/db/data:/var/lib/postgresql/data:rw
-###< doctrine/doctrine-bundle ###
-
-volumes:
-###> doctrine/doctrine-bundle ###
-  database_data:
-###< doctrine/doctrine-bundle ###
diff --git a/www/app/Controllers/user.php b/www/app/Controllers/user.php
deleted file mode 100644
index e69de29..0000000
diff --git a/www/app/Models/user.php b/www/app/Models/user.php
deleted file mode 100644
index e69de29..0000000
diff --git a/www/app/Views/user.html b/www/app/Views/user.html
deleted file mode 100644
index e69de29..0000000
diff --git a/www/config/config.php b/www/config/config.php
deleted file mode 100644
index e69de29..0000000
diff --git a/www/config/database.php b/www/config/database.php
deleted file mode 100644
index e69de29..0000000
diff --git a/www/index.php b/www/index.php
deleted file mode 100644
index 62d9429..0000000
--- a/www/index.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>WishList</title>
-</head>
-<body>
-    <p> WishList is running ! </p>
-</body>
-</html>
\ No newline at end of file
diff --git a/www/public/css/user.css b/www/public/css/user.css
deleted file mode 100644
index e69de29..0000000
diff --git a/www/public/images/ejem.txt b/www/public/images/ejem.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/www/public/js/script.js b/www/public/js/script.js
deleted file mode 100644
index e69de29..0000000
diff --git a/www/routes/web.php b/www/routes/web.php
deleted file mode 100644
index e69de29..0000000
-- 
GitLab