File size: 3,507 Bytes
2da3758
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# ================================
# SoftEdge Corporation — HF Spaces
# PHP 8.3 + Apache (ESTÁVEL)
# ================================
FROM php:8.3-apache

# ----------------
# VARIÁVEIS
# ----------------
ENV PORT=7860
ENV APACHE_RUN_USER=www-data
ENV APACHE_RUN_GROUP=www-data
ENV APACHE_LOG_DIR=/var/log/apache2

# ----------------
# DEPENDÊNCIAS DO SISTEMA
# ----------------
RUN apt-get update && apt-get install -y --no-install-recommends \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    libzip-dev \
    libicu-dev \
    libxml2-dev \
    libcurl4-openssl-dev \
    libonig-dev \
    sqlite3 \
    libsqlite3-dev \
    git \
    curl \
    cron \
    unzip \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# ----------------
# EXTENSÕES PHP (CONTROLADAS)
# ----------------
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install \
        mbstring \
        exif \
        bcmath \
        intl \
        zip \
        gd \
        mysqli \
        pdo \
        pdo_mysql \
        pdo_sqlite \
    && docker-php-ext-enable \
        mbstring exif bcmath intl zip gd mysqli pdo_mysql pdo_sqlite

# 🔥 LIMPEZA DE INIs DUPLICADOS (CRÍTICO)
RUN find /usr/local/etc/php/conf.d -type f -name "*docker-php-ext-*" -exec sed -i '/^extension=/d' {} \;

# ----------------
# COMPOSER
# ----------------
RUN curl -sS https://getcomposer.org/installer | php -- \
    --install-dir=/usr/local/bin \
    --filename=composer

# ----------------
# NODE (opcional p/ React)
# ----------------
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && node -v && npm -v

# ----------------
# APACHE CONFIG
# ----------------
RUN a2enmod rewrite headers

# ServerName GLOBAL (remove AH00558 de vez)
RUN echo "ServerName localhost" > /etc/apache2/conf-available/servername.conf \
    && a2enconf servername

# Porta HF Spaces
RUN sed -i 's/Listen 80/Listen 7860/' /etc/apache2/ports.conf

RUN printf '<VirtualHost *:7860>\n\
    ServerName localhost\n\
    DocumentRoot /var/www/html\n\
    <Directory /var/www/html>\n\
        AllowOverride All\n\
        Require all granted\n\
    </Directory>\n\
    ErrorLog ${APACHE_LOG_DIR}/error.log\n\
    CustomLog ${APACHE_LOG_DIR}/access.log combined\n\
</VirtualHost>\n' > /etc/apache2/sites-available/000-default.conf

# ----------------
# APP
# ----------------
WORKDIR /var/www/html
COPY . .

# Logs e storage
RUN mkdir -p logs storage \
    && chown -R www-data:www-data /var/www/html \
    && chmod -R 775 logs storage

# ----------------
# COMPOSER INSTALL
# ----------------
RUN if [ -f composer.json ]; then \
    composer install --no-dev --optimize-autoloader --no-interaction; \
    fi

# ----------------
# REACT BUILD (SE EXISTIR)
# ----------------
RUN if [ -f package.json ]; then \
    npm install && npm run build; \
    fi

# ----------------
# PHP CONFIG FINAL
# ----------------
RUN printf "display_errors=Off\n\
log_errors=On\n\
error_log=/var/www/html/logs/php_errors.log\n\
memory_limit=256M\n\
upload_max_filesize=10M\n\
post_max_size=10M\n\
max_execution_time=300\n" > /usr/local/etc/php/conf.d/99-softedge.ini

# ----------------
# HEALTHCHECK
# ----------------
RUN echo "<?php http_response_code(200); echo 'OK';" > /var/www/html/health.php

HEALTHCHECK --interval=60s --timeout=5s \
 CMD curl -f http://localhost:7860/health.php || exit 1

# ----------------
# START
# ----------------
EXPOSE 7860
CMD ["apache2-foreground"]