From 968788a11c3ab783892aba3b195986e4d1a43c8b Mon Sep 17 00:00:00 2001 From: Pablo Gutierrez Date: Sun, 29 Sep 2024 17:48:59 +0200 Subject: [PATCH 1/5] Adding docker as container service --- Dockerfile | 19 +++++++++++++++++++ docker-compose.yml | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..acf63f1c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM php:7.3-apache + +# Habilitar mod_rewrite, mod_headers y otros módulos necesarios +RUN a2enmod rewrite headers cgi include + +# Instalar extensiones de PHP necesarias, incluyendo mysqli +RUN docker-php-ext-install pdo_mysql mysqli + +# Copiar el código fuente +COPY ./html /var/www/html + +# Establecer permisos adecuados +RUN chown -R www-data:www-data /var/www/html + +# Establecer permisos de acceso al archivo .htaccess +RUN chmod -R 755 /var/www/html/.htaccess + +# Reiniciar Apache para aplicar cambios +CMD ["apache2-foreground"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..7c54ea62 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +version: '3.8' + +services: + web: + build: . + container_name: bcoe_web + ports: + - "80:80" + - "443:443" + volumes: + - ./html:/var/www/html + environment: + - DB_HOST=bcoe_db + - DB_USER=root + - DB_PASSWORD=rootpassword + - DB_NAME=brewing_competition + - DB_PORT=3306 # You can change if you need + depends_on: + - db + + db: + image: mysql:5.7 + container_name: bcoe_db + environment: + MYSQL_ROOT_PASSWORD: rootpassword + MYSQL_DATABASE: brewing_competition + MYSQL_USER: bcoe_user + MYSQL_PASSWORD: bcoe_password + volumes: + - db_data:/var/lib/mysql + +volumes: + db_data: From 95e47a1d59fbc014df294f413661dc23a6be8198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Guti=C3=A9rrez?= Date: Sun, 29 Sep 2024 18:02:26 +0200 Subject: [PATCH 2/5] Update Dockerfile Adding correct source and english comments --- Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index acf63f1c..c6f45483 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,19 @@ FROM php:7.3-apache -# Habilitar mod_rewrite, mod_headers y otros módulos necesarios +# Enable mod_rewrite, mod_headers, and other necessary modules RUN a2enmod rewrite headers cgi include -# Instalar extensiones de PHP necesarias, incluyendo mysqli +# Install necessary PHP extensions, including mysqli RUN docker-php-ext-install pdo_mysql mysqli -# Copiar el código fuente -COPY ./html /var/www/html +# Copy the source code +COPY ./ /var/www/html -# Establecer permisos adecuados +# Set appropriate permissions RUN chown -R www-data:www-data /var/www/html -# Establecer permisos de acceso al archivo .htaccess +# Set access permissions for the .htaccess file RUN chmod -R 755 /var/www/html/.htaccess -# Reiniciar Apache para aplicar cambios +# Restart Apache to apply changes CMD ["apache2-foreground"] From dd7eeff958136f2049ba002085985e9ed3545134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Guti=C3=A9rrez?= Date: Sun, 29 Sep 2024 18:02:48 +0200 Subject: [PATCH 3/5] Update docker-compose.yml Adding correct source --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7c54ea62..f86cf54d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - "80:80" - "443:443" volumes: - - ./html:/var/www/html + - ./:/var/www/html environment: - DB_HOST=bcoe_db - DB_USER=root From 35d23da735b7f1cbc75434f3e74bbf32df0912d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Guti=C3=A9rrez?= Date: Sun, 29 Sep 2024 18:21:53 +0200 Subject: [PATCH 4/5] Update .htaccess Adding HTTP_HOST for localhost to work on Docker --- .htaccess | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.htaccess b/.htaccess index 187cbb6d..fce37393 100644 --- a/.htaccess +++ b/.htaccess @@ -6,6 +6,7 @@ DirectoryIndex index.php RewriteEngine on RewriteCond %{HTTPS} off +RewriteCond %{HTTP_HOST} !^localhost [NC] RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] # If storing your installation in a sub-folder, uncomment the following line (remove the # symbol) and replace [subfolder] with the name of your subfolder @@ -118,4 +119,4 @@ Options +ExecCGI +Includes +IncludesNOEXEC +SymLinksIfOwnerMatch -Indexes # Caching schema Header set Cache-Control "max-age=3600" - \ No newline at end of file + From 39640e8ddd18a5fc8dfca56cdb830e8e28226bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Guti=C3=A9rrez?= Date: Sun, 29 Sep 2024 18:25:33 +0200 Subject: [PATCH 5/5] Update config.php Adding variables that we can get from Dockerfile, then avoid to changes on file --- site/config.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/site/config.php b/site/config.php index c2860a3d..5a18dfdc 100644 --- a/site/config.php +++ b/site/config.php @@ -20,7 +20,7 @@ * *** https://www.godaddy.com/help/viewing-your-database-details-with-shared-hosting-accounts-39 */ -$hostname = 'localhost'; +$hostname = getenv('DB_HOST') ?: 'localhost'; /** * Enter the username for your database (generally the same as your login code @@ -31,7 +31,7 @@ */ -$username = ''; +$username = getenv('DB_USER') ?: ''; /** @@ -40,7 +40,7 @@ * $password = 'flintsone'. */ -$password = ''; +$password = getenv('DB_PASSWORD') ?: ''; /** * The following line is the name of your MySQL database you set up already. @@ -48,7 +48,7 @@ * http://brewingcompetitions.com/install-instructions for setup instructions. */ -$database = ''; +$database = getenv('DB_NAME') ?: ''; /** @@ -57,7 +57,7 @@ * Example: $database_port = 3308; */ -$database_port = ini_get('mysqli.default_port'); +$database_port = getenv('DB_PORT') ?: ini_get('mysqli.default_port'); /** * This line strings the information together and connects to MySQL. @@ -209,4 +209,4 @@ $server_root = $_SERVER['DOCUMENT_ROOT']; //$server_root = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT']; -?> \ No newline at end of file +?>