Skip to content

Commit 8f63081

Browse files
committed
feat: enhance Docker deployment with phpMyAdmin integration
1 parent e7a7f0e commit 8f63081

File tree

9 files changed

+145
-26
lines changed

9 files changed

+145
-26
lines changed

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ APP_ENV=local
33
APP_DEBUG=true
44
APP_URL=http://localhost:8000
55

6-
DB_HOST=localhost
6+
DB_HOST=db
77
DB_PORT=3306
88
DB_DATABASE=test_db
99
DB_USERNAME=root
10-
DB_PASSWORD=
10+
DB_PASSWORD=password
1111

1212
JWT_SECRET=your-secret-key-here
1313
JWT_EXPIRE=3600

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.5.0] - 2025-11-20
6+
7+
### Added
8+
- **phpMyAdmin Integration** - Web-based database management interface
9+
- Automatic phpMyAdmin service in Docker Compose
10+
- Pre-configured connection to project database
11+
- Access via http://localhost:8081
12+
- Secure authentication with MySQL credentials
13+
14+
### Improved
15+
- **Docker Configuration** - Enhanced containerized deployment
16+
- Fixed environment variable loading in Config class
17+
- Improved docker-entrypoint.sh for reliable startup
18+
- Better database connection handling in containers
19+
- Optimized migration execution during container startup
20+
21+
### Fixed
22+
- **Environment Configuration** - Config class now properly reads Docker environment variables
23+
- **Docker Entrypoint** - Changed from 'fresh' to 'migrate' to avoid foreign key constraint issues
24+
- **Database Connection** - Resolved connection issues in Docker containers
25+
26+
### Docker Services
27+
- **App Service** - PHP 8.1 Apache container on port 8000
28+
- **Database Service** - MySQL 8.0 container on port 3307
29+
- **phpMyAdmin Service** - Web interface on port 8081
30+
531
## [1.4.0] - 2025-10-21
632

733
### Added

Dockerfile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
FROM php:8.1-apache
22

3+
# Install system dependencies
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
unzip \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Install Composer
10+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
11+
312
# Install PHP extensions
413
RUN docker-php-ext-install pdo pdo_mysql
514

@@ -18,4 +27,10 @@ ENV APACHE_DOCUMENT_ROOT /var/www/html/public
1827
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
1928
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
2029

21-
EXPOSE 80
30+
# Copy entrypoint script
31+
COPY docker-entrypoint.sh /usr/local/bin/
32+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
33+
34+
EXPOSE 80
35+
36+
ENTRYPOINT ["docker-entrypoint.sh"]

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,24 @@ docker-compose logs -f app
590590
docker-compose down
591591
```
592592

593+
### Docker Services
594+
595+
The Docker setup includes three services:
596+
597+
- **App Service** - PHP 8.1 Apache server on `http://localhost:8000`
598+
- **Database Service** - MySQL 8.0 on port `3307`
599+
- **phpMyAdmin Service** - Web database interface on `http://localhost:8081`
600+
601+
### Database Management
602+
603+
Access phpMyAdmin at `http://localhost:8081` to manage your database:
604+
- **Server**: db
605+
- **Username**: root
606+
- **Password**: password
607+
- **Database**: test_db
608+
609+
This provides a user-friendly web interface for database administration, table management, and query execution.
610+
593611
## 🛠️ Requirements
594612

595613
- PHP 8.0+

app/config/database.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
2-
$servername = "localhost";
2+
$servername = "db";
33
$username = "root";
4-
$password = "";
5-
$database = "hrms_db";
4+
$password = "password";
5+
$database = "test_db";
66

77
$conn = new mysqli($servername, $username, $password, $database);
88

app/core/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ private function loadEnv()
2727

2828
public static function get($key, $default = null)
2929
{
30-
return self::$config[$key] ?? $default;
30+
return getenv($key) ?: (self::$config[$key] ?? $default);
3131
}
3232
}

app/database/Migrator.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,33 @@ public function migrate()
4444

4545
public function seed()
4646
{
47-
$seeders = glob($this->seedersPath . '/*.php');
48-
sort($seeders);
47+
// Define seeder order based on dependencies
48+
$seederOrder = [
49+
'DepartmentsSeeder',
50+
'UsersSeeder',
51+
'EmployeeProfilesSeeder',
52+
'LeaveTypesSeeder',
53+
'LeaveRequestsSeeder',
54+
'AttendanceSeeder',
55+
'PayrollSeeder'
56+
];
4957

50-
foreach ($seeders as $seeder) {
51-
$className = 'App\\Database\\Seeders\\' . basename($seeder, '.php');
52-
require_once $seeder;
53-
54-
try {
55-
$sql = $className::run();
56-
$this->db->exec($sql);
57-
echo "Seeded: " . basename($seeder) . "\n";
58-
} catch (\PDOException $e) {
59-
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
60-
echo "Skipped (already exists): " . basename($seeder) . "\n";
61-
} else {
62-
throw $e;
58+
foreach ($seederOrder as $seederName) {
59+
$seederFile = $this->seedersPath . '/' . $seederName . '.php';
60+
if (file_exists($seederFile)) {
61+
$className = 'App\\Database\\Seeders\\' . $seederName;
62+
require_once $seederFile;
63+
64+
try {
65+
$sql = $className::run();
66+
$this->db->exec($sql);
67+
echo "Seeded: " . $seederName . ".php\n";
68+
} catch (\PDOException $e) {
69+
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
70+
echo "Skipped (already exists): " . $seederName . ".php\n";
71+
} else {
72+
throw $e;
73+
}
6374
}
6475
}
6576
}
@@ -71,9 +82,19 @@ public function rollback()
7182
rsort($migrations);
7283

7384
foreach ($migrations as $migration) {
74-
$className = 'App\\Database\\Migrations\\' . basename($migration, '.php');
85+
$baseName = basename($migration, '.php');
86+
$className = 'App\\Database\\Migrations\\' . substr($baseName, 4); // Remove number prefix
87+
if (strpos($baseName, '001_') === 0) $className .= '001';
88+
elseif (strpos($baseName, '002_') === 0) $className = 'App\\Database\\Migrations\\CreateDepartmentsTable002';
89+
elseif (strpos($baseName, '003_') === 0) $className = 'App\\Database\\Migrations\\CreateEmployeeProfilesTable003';
90+
elseif (strpos($baseName, '004_') === 0) $className = 'App\\Database\\Migrations\\CreateAttendanceTable004';
91+
elseif (strpos($baseName, '005_') === 0) $className = 'App\\Database\\Migrations\\CreateLeaveTypesTable005';
92+
elseif (strpos($baseName, '006_') === 0) $className = 'App\\Database\\Migrations\\CreateLeaveRequestsTable006';
93+
elseif (strpos($baseName, '007_') === 0) $className = 'App\\Database\\Migrations\\CreatePayrollTable007';
94+
elseif (strpos($baseName, '008_') === 0) $className = 'App\\Database\\Migrations\\CreatePerformanceReviewsTable008';
95+
elseif (strpos($baseName, '009_') === 0) $className = 'App\\Database\\Migrations\\CreateTokensTable009';
96+
7597
require_once $migration;
76-
7798
$sql = $className::down();
7899
$this->db->exec($sql);
79100
echo "Rolled back: " . basename($migration) . "\n";

docker-compose.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,21 @@ services:
2121
MYSQL_ROOT_PASSWORD: password
2222
MYSQL_DATABASE: test_db
2323
ports:
24-
- "3306:3306"
24+
- "3307:3306"
2525
volumes:
2626
- db_data:/var/lib/mysql
2727

28+
phpmyadmin:
29+
image: phpmyadmin/phpmyadmin
30+
environment:
31+
PMA_HOST: db
32+
PMA_PORT: 3306
33+
PMA_USER: root
34+
PMA_PASSWORD: password
35+
ports:
36+
- "8081:80"
37+
depends_on:
38+
- db
39+
2840
volumes:
29-
db_data:
41+
db_data:

docker-entrypoint.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd /var/www/html
6+
7+
# Copy .env.example to .env if .env doesn't exist
8+
if [ ! -f .env ]; then
9+
cp .env.example .env
10+
fi
11+
12+
# Install Composer dependencies
13+
composer install --no-interaction --optimize-autoloader
14+
15+
# Wait for MySQL to be ready
16+
echo "Waiting for MySQL to be ready..."
17+
until php -r "new PDO('mysql:host=db;dbname=test_db', 'root', 'password');" 2>/dev/null; do
18+
echo "MySQL is unavailable - sleeping"
19+
sleep 2
20+
done
21+
echo "MySQL is up - executing migrations"
22+
23+
# Run migrations
24+
php migrate.php migrate
25+
26+
# Start Apache
27+
apache2-foreground

0 commit comments

Comments
 (0)