Commit 664210e8 authored by Administrator's avatar Administrator

Update 7 files via Son of Anton

parent 63bd524e
Pipeline #17 canceled with stage
...@@ -26,7 +26,6 @@ RUN apt-get update && apt-get install -y \ ...@@ -26,7 +26,6 @@ RUN apt-get update && apt-get install -y \
# Apache configuration # Apache configuration
RUN a2enmod rewrite headers RUN a2enmod rewrite headers
COPY docker/000-default.conf /etc/apache2/sites-available/000-default.conf
# PHP configuration # PHP configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
...@@ -47,10 +46,9 @@ RUN mkdir -p \ ...@@ -47,10 +46,9 @@ RUN mkdir -p \
&& chown -R www-data:www-data /var/www/html/storage \ && chown -R www-data:www-data /var/www/html/storage \
&& chmod -R 775 /var/www/html/storage && chmod -R 775 /var/www/html/storage
# Set Apache document root to public/ # ─── Apache: Set DocumentRoot to /var/www/html/public ───
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public # Do NOT use sed — it causes double-path bugs. Use a clean vhost config instead.
RUN sed -ri -e 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/*.conf \ COPY docker/000-default.conf /etc/apache2/sites-available/000-default.conf
&& sed -ri -e 's!/var/www/!/var/www/html/public!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# Entrypoint for DB initialization # Entrypoint for DB initialization
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
......
...@@ -8,7 +8,9 @@ $dbConfig = require ROOT_PATH . '/config/database.php'; ...@@ -8,7 +8,9 @@ $dbConfig = require ROOT_PATH . '/config/database.php';
try { try {
$dsn = "mysql:host={$dbConfig['host']};port={$dbConfig['port']};dbname={$dbConfig['database']};charset={$dbConfig['charset']}"; $dsn = "mysql:host={$dbConfig['host']};port={$dbConfig['port']};dbname={$dbConfig['database']};charset={$dbConfig['charset']}";
$pdo = new PDO($dsn, $dbConfig['username'], $dbConfig['password'], $dbConfig['options']); $options = $dbConfig['options'] ?? [];
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
$pdo = new PDO($dsn, $dbConfig['username'], $dbConfig['password'], $options);
} catch (PDOException $e) { } catch (PDOException $e) {
echo "DB Connection Failed: {$e->getMessage()}\n"; echo "DB Connection Failed: {$e->getMessage()}\n";
exit(1); exit(1);
......
...@@ -8,7 +8,9 @@ $dbConfig = require ROOT_PATH . '/config/database.php'; ...@@ -8,7 +8,9 @@ $dbConfig = require ROOT_PATH . '/config/database.php';
try { try {
$dsn = "mysql:host={$dbConfig['host']};port={$dbConfig['port']};dbname={$dbConfig['database']};charset={$dbConfig['charset']}"; $dsn = "mysql:host={$dbConfig['host']};port={$dbConfig['port']};dbname={$dbConfig['database']};charset={$dbConfig['charset']}";
$pdo = new PDO($dsn, $dbConfig['username'], $dbConfig['password'], $dbConfig['options']); $options = $dbConfig['options'] ?? [];
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
$pdo = new PDO($dsn, $dbConfig['username'], $dbConfig['password'], $options);
} catch (PDOException $e) { } catch (PDOException $e) {
echo "DB Connection Failed: {$e->getMessage()}\n"; echo "DB Connection Failed: {$e->getMessage()}\n";
exit(1); exit(1);
......
...@@ -12,5 +12,7 @@ return [ ...@@ -12,5 +12,7 @@ return [
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_STRINGIFY_FETCHES => false,
// Disable SSL verification for internal Docker networking
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
], ],
]; ];
\ No newline at end of file
<VirtualHost *:80> <VirtualHost *:80>
ServerAdmin webmaster@localhost ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public DocumentRoot /var/www/html/public
ServerName localhost
<Directory /var/www/html/public> <Directory /var/www/html/public>
Options -Indexes +FollowSymLinks
AllowOverride All AllowOverride All
Require all granted Require all granted
Options -Indexes +FollowSymLinks
# Route everything through index.php
FallbackResource /index.php
</Directory>
# Deny access to sensitive directories
<DirectoryMatch "/var/www/html/(engine|modules|config|database|cli|bootstrap|storage|docker|templates)">
Require all denied
</DirectoryMatch>
# Allow storage/uploads for file serving
<Directory /var/www/html/storage/uploads>
Require all granted
</Directory> </Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log ErrorLog ${APACHE_LOG_DIR}/error.log
......
...@@ -20,6 +20,9 @@ echo " DB_USER: ${DB_USER}" ...@@ -20,6 +20,9 @@ echo " DB_USER: ${DB_USER}"
echo " DB_PASS: [REDACTED]" echo " DB_PASS: [REDACTED]"
echo "" echo ""
# ─── Common MySQL flags (disable SSL for internal Docker networking) ───
MYSQL_FLAGS="--ssl-mode=DISABLED"
# ─── Debug: DNS Resolution ─── # ─── Debug: DNS Resolution ───
echo "Attempting DNS resolution for ${DB_HOST}..." echo "Attempting DNS resolution for ${DB_HOST}..."
if getent hosts "${DB_HOST}" > /dev/null 2>&1; then if getent hosts "${DB_HOST}" > /dev/null 2>&1; then
...@@ -27,21 +30,8 @@ if getent hosts "${DB_HOST}" > /dev/null 2>&1; then ...@@ -27,21 +30,8 @@ if getent hosts "${DB_HOST}" > /dev/null 2>&1; then
echo " ✅ ${DB_HOST} resolves to ${RESOLVED_IP}" echo " ✅ ${DB_HOST} resolves to ${RESOLVED_IP}"
else else
echo " ❌ CANNOT RESOLVE ${DB_HOST}" echo " ❌ CANNOT RESOLVE ${DB_HOST}"
echo "" echo " Starting Apache anyway — app will show DB errors."
echo " This means either:" exec "$@"
echo " 1. You haven't created a MySQL app named 'mysql-db' on CapRover"
echo " 2. Your MySQL app has a different name (check CapRover dashboard)"
echo " 3. The apps aren't on the same Docker network"
echo ""
echo " To fix on CapRover:"
echo " - Go to Apps → One-Click Apps → MySQL"
echo " - Name it 'mysql-db' (creates hostname 'srv-captain--mysql-db')"
echo " - OR set DB_HOST env var on your app to the correct hostname"
echo ""
echo " Available Docker networks this container can see:"
cat /etc/hosts 2>/dev/null || true
echo ""
echo " Proceeding anyway (MySQL might come up later)..."
fi fi
echo "" echo ""
...@@ -53,15 +43,23 @@ ATTEMPT=0 ...@@ -53,15 +43,23 @@ ATTEMPT=0
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
ATTEMPT=$((ATTEMPT + 1)) ATTEMPT=$((ATTEMPT + 1))
if mysqladmin ping -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" --silent 2>/dev/null; then # Try with SSL disabled first, then without the flag for older clients
if mysqladmin ping -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" ${MYSQL_FLAGS} --silent 2>/dev/null; then
echo "✅ MySQL is ready! (attempt ${ATTEMPT}/${MAX_ATTEMPTS})" echo "✅ MySQL is ready! (attempt ${ATTEMPT}/${MAX_ATTEMPTS})"
break break
fi fi
# Every 10 attempts, try a raw TCP connection test for better debugging # Fallback: try with --skip-ssl for older mysql client versions
if mysqladmin ping -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" --skip-ssl --silent 2>/dev/null; then
echo "✅ MySQL is ready via --skip-ssl! (attempt ${ATTEMPT}/${MAX_ATTEMPTS})"
MYSQL_FLAGS="--skip-ssl"
break
fi
if [ $((ATTEMPT % 10)) -eq 0 ]; then if [ $((ATTEMPT % 10)) -eq 0 ]; then
echo " MySQL not ready... (attempt ${ATTEMPT}/${MAX_ATTEMPTS})" echo " MySQL not ready... (attempt ${ATTEMPT}/${MAX_ATTEMPTS})"
echo " TCP test: $(timeout 2 bash -c "echo > /dev/tcp/${DB_HOST}/${DB_PORT}" 2>&1 && echo 'port open' || echo 'port closed/unreachable')" # Show the actual error for debugging
mysqladmin ping -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" ${MYSQL_FLAGS} 2>&1 || true
else else
echo " MySQL not ready... (attempt ${ATTEMPT}/${MAX_ATTEMPTS})" echo " MySQL not ready... (attempt ${ATTEMPT}/${MAX_ATTEMPTS})"
fi fi
...@@ -71,52 +69,77 @@ done ...@@ -71,52 +69,77 @@ done
if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then
echo "" echo ""
echo "╔══════════════════════════════════════════════════════════════╗" echo "❌ FATAL: Could not connect to MySQL after ${MAX_ATTEMPTS} attempts"
echo "║ ❌ FATAL: Could not connect to MySQL after ${MAX_ATTEMPTS} attempts ║" echo " Last error:"
echo "║ ║" mysqladmin ping -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" ${MYSQL_FLAGS} 2>&1 || true
echo "║ Host: ${DB_HOST}:${DB_PORT} "
echo "║ User: ${DB_USER} "
echo "║ ║"
echo "║ CHECKLIST: ║"
echo "║ 1. Is MySQL running? Check CapRover dashboard. ║"
echo "║ 2. Is the app name correct? Should be 'mysql-db' ║"
echo "║ for hostname 'srv-captain--mysql-db' ║"
echo "║ 3. Are credentials correct? Check env vars. ║"
echo "║ 4. Try: CapRover → App → Edit Default Nginx Config ║"
echo "║ to check networking. ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo "" echo ""
echo "Starting Apache anyway (app will show DB errors)..." echo " Starting Apache anyway (app will show DB errors)..."
exec "$@" exec "$@"
exit 0
fi fi
# ─── Helper function for mysql commands ───
run_mysql() {
mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" ${MYSQL_FLAGS} "$@" 2>&1
}
run_mysql_silent() {
mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" ${MYSQL_FLAGS} -N "$@" 2>/dev/null
}
# ─── Create Database if not exists ─── # ─── Create Database if not exists ───
echo "" echo ""
echo "Ensuring database '${DB_NAME}' exists..." echo "Ensuring database '${DB_NAME}' exists..."
mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" -e "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null run_mysql -e "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
echo "✅ Database ensured." echo "✅ Database ensured."
# ─── Run Schema if tables don't exist ─── # ─── Run Schema if tables don't exist ───
TABLE_COUNT=$(mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" -N -e "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DB_NAME}' AND TABLE_TYPE='BASE TABLE';" 2>/dev/null) TABLE_COUNT=$(run_mysql_silent -e "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DB_NAME}' AND TABLE_TYPE='BASE TABLE';" || echo "0")
echo "Current table count: ${TABLE_COUNT}" echo "Current table count: ${TABLE_COUNT}"
if [ "${TABLE_COUNT}" -lt "70" ] 2>/dev/null; then if [ "${TABLE_COUNT}" -lt "70" ] 2>/dev/null; then
echo "Running schema migration (expected 73 tables, found ${TABLE_COUNT})..." echo "Running schema migration (expected 73 tables, found ${TABLE_COUNT})..."
if [ -f "/var/www/html/database/schema.sql" ]; then # Try multiple possible paths for schema.sql
mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" "${DB_NAME}" < /var/www/html/database/schema.sql 2>&1 SCHEMA_FILE=""
for path in "/var/www/html/database/schema.sql" "/var/www/html/public/../database/schema.sql" "/var/www/html/schema.sql"; do
if [ -f "$path" ]; then
SCHEMA_FILE="$path"
break
fi
done
if [ -n "${SCHEMA_FILE}" ]; then
echo "Found schema at: ${SCHEMA_FILE}"
run_mysql "${DB_NAME}" < "${SCHEMA_FILE}"
echo "✅ Schema applied." echo "✅ Schema applied."
# Verify
NEW_COUNT=$(run_mysql_silent -e "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DB_NAME}' AND TABLE_TYPE='BASE TABLE';" || echo "0")
echo "Tables after migration: ${NEW_COUNT}"
else else
echo "⚠️ No schema.sql found at /var/www/html/database/schema.sql" echo "❌ schema.sql not found! Searched:"
echo " Skipping schema creation." echo " /var/www/html/database/schema.sql"
echo ""
echo " Files in /var/www/html/database/:"
ls -la /var/www/html/database/ 2>/dev/null || echo " (directory does not exist)"
echo ""
echo " Files in /var/www/html/:"
ls -la /var/www/html/ 2>/dev/null | head -20
fi fi
# Run seed data # Run seed data
if [ -f "/var/www/html/database/seed.sql" ]; then SEED_FILE=""
echo "Running seed data..." for path in "/var/www/html/database/seed.sql" "/var/www/html/seed.sql"; do
mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" "${DB_NAME}" < /var/www/html/database/seed.sql 2>&1 if [ -f "$path" ]; then
SEED_FILE="$path"
break
fi
done
if [ -n "${SEED_FILE}" ]; then
echo "Running seed data from: ${SEED_FILE}"
run_mysql "${DB_NAME}" < "${SEED_FILE}" || echo "⚠️ Some seed data may already exist (duplicates skipped)."
echo "✅ Seed data applied." echo "✅ Seed data applied."
fi fi
else else
...@@ -124,27 +147,30 @@ else ...@@ -124,27 +147,30 @@ else
fi fi
# ─── Create Super Admin ─── # ─── Create Super Admin ───
SA_EXISTS=$(mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASS}" -N -e "SELECT COUNT(*) FROM \`${DB_NAME}\`.users WHERE role='super_admin';" 2>/dev/null || echo "0") SA_EXISTS=$(run_mysql_silent -e "SELECT COUNT(*) FROM \`${DB_NAME}\`.users WHERE role='super_admin';" || echo "0")
if [ "${SA_EXISTS}" = "0" ]; then if [ "${SA_EXISTS}" = "0" ]; then
echo "Creating Super Admin..." echo "Creating Super Admin..."
if [ -f "/var/www/html/cli/create-superadmin.php" ]; then if [ -f "/var/www/html/cli/create-superadmin.php" ]; then
php /var/www/html/cli/create-superadmin.php php /var/www/html/cli/create-superadmin.php
else
echo "⚠️ create-superadmin.php not found"
fi fi
else else
echo "✅ Super Admin already exists. Skipping." echo "✅ Super Admin already exists. Skipping."
fi fi
# ─── Fix Permissions ─── # ─── Fix Permissions ───
echo "Setting permissions..." echo ""
echo "Setting file permissions..."
chown -R www-data:www-data /var/www/html/storage 2>/dev/null || true chown -R www-data:www-data /var/www/html/storage 2>/dev/null || true
chmod -R 775 /var/www/html/storage 2>/dev/null || true chmod -R 775 /var/www/html/storage 2>/dev/null || true
echo "" echo ""
echo "╔══════════════════════════════════════════════════════════════╗" echo "╔══════════════════════════════════════════════════════╗"
echo "║ ✅ AL-ARCADE HR Platform v3.0 — Ready! ║" echo "║ ✅ AL-ARCADE HR Platform v3.0 — Ready! ║"
echo "║ Starting Apache... ║" echo "║ Starting Apache... ║"
echo "╚══════════════════════════════════════════════════════════════╝" echo "╚══════════════════════════════════════════════════════╝"
echo "" echo ""
# ─── Start Apache ─── # ─── Start Apache ───
......
...@@ -25,7 +25,15 @@ final class Connection ...@@ -25,7 +25,15 @@ final class Connection
$this->config['database'], $this->config['database'],
$this->config['charset'] $this->config['charset']
); );
$this->pdo = new PDO($dsn, $this->config['username'], $this->config['password'], $this->config['options'] ?? []);
$options = $this->config['options'] ?? [];
// Ensure SSL cert verification is disabled for Docker internal networking
if (!isset($options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT])) {
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
}
$this->pdo = new PDO($dsn, $this->config['username'], $this->config['password'], $options);
} }
return $this->pdo; return $this->pdo;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment