wordpress / Dockerfile
CatPtain's picture
Upload 9 files
efc9636 verified
# Dockerfile optimized for Hugging Face Spaces deployment
# Based on WordPress 6.8.1 with PHP 8.3 Apache
FROM php:8.3-apache
# Set environment variables for HF Spaces
ENV APACHE_DOCUMENT_ROOT=/var/www/html
ENV APACHE_RUN_USER=www-data
ENV APACHE_RUN_GROUP=www-data
# Install system dependencies
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ghostscript \
libfreetype6-dev \
libicu-dev \
libjpeg-dev \
libpng-dev \
libwebp-dev \
libzip-dev \
libsqlite3-dev \
sqlite3 \
wget \
unzip \
; \
rm -rf /var/lib/apt/lists/*
# Configure and install PHP extensions
RUN set -ex; \
docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
; \
docker-php-ext-install -j "$(nproc)" \
bcmath \
exif \
gd \
intl \
mysqli \
pdo \
pdo_sqlite \
zip \
;
# Configure PHP settings
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
RUN { \
echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE'; \
echo 'display_errors = Off'; \
echo 'log_errors = On'; \
echo 'error_log = /dev/stderr'; \
echo 'memory_limit = 256M'; \
echo 'upload_max_filesize = 32M'; \
echo 'post_max_size = 32M'; \
} > /usr/local/etc/php/conf.d/wordpress.ini
# Configure Apache for HF Spaces
RUN set -eux; \
a2enmod rewrite expires headers; \
# Configure Apache to listen on port 7860 (HF Spaces requirement)
sed -i 's/Listen 80/Listen 7860/' /etc/apache2/ports.conf; \
sed -i 's/:80>/:7860>/' /etc/apache2/sites-available/000-default.conf; \
# Set ServerName to avoid warnings
echo 'ServerName localhost' >> /etc/apache2/apache2.conf
# Download and install WordPress
RUN set -eux; \
version='6.8.1'; \
sha1='52d5f05c96a9155f78ed84700264307e5dea14b4'; \
curl -o wordpress.tar.gz -fL "https://wordpress.org/wordpress-$version.tar.gz"; \
echo "$sha1 *wordpress.tar.gz" | sha1sum -c -; \
tar -xzf wordpress.tar.gz -C /usr/src/; \
rm wordpress.tar.gz; \
cp -a /usr/src/wordpress/. /var/www/html/; \
chown -R www-data:www-data /var/www/html
# Install SQLite integration plugin for WordPress
RUN set -eux; \
wget -O sqlite-plugin.zip "https://downloads.wordpress.org/plugin/sqlite-database-integration.2.1.15.zip"; \
unzip sqlite-plugin.zip -d /var/www/html/wp-content/plugins/; \
rm sqlite-plugin.zip; \
chown -R www-data:www-data /var/www/html/wp-content/plugins/sqlite-database-integration
# Create WordPress configuration for SQLite
COPY wp-config-hf.php /var/www/html/wp-config.php
COPY db.php /var/www/html/wp-content/db.php
COPY error-debug.php /var/www/html/debug.php
COPY test-php.php /var/www/html/test.php
# Create .htaccess for pretty permalinks
RUN { \
echo '# BEGIN WordPress'; \
echo 'RewriteEngine On'; \
echo 'RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]'; \
echo 'RewriteBase /'; \
echo 'RewriteRule ^index\.php$ - [L]'; \
echo 'RewriteCond %{REQUEST_FILENAME} !-f'; \
echo 'RewriteCond %{REQUEST_FILENAME} !-d'; \
echo 'RewriteRule . /index.php [L]'; \
echo '# END WordPress'; \
} > /var/www/html/.htaccess
# Create necessary directories with proper permissions
RUN mkdir -p /var/www/html/wp-content/database && \
mkdir -p /var/www/html/wp-content/uploads && \
mkdir -p /var/www/html/wp-content/cache && \
chown -R www-data:www-data /var/www/html && \
chmod -R 777 /var/www/html && \
chmod 644 /var/www/html/.htaccess
# Add user for HF Spaces compatibility
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
# Expose port 7860 for Hugging Face Spaces
EXPOSE 7860
# Copy startup script
COPY start-hf.sh /usr/local/bin/start-hf.sh
RUN chmod +x /usr/local/bin/start-hf.sh
# Start Apache
CMD ["/usr/local/bin/start-hf.sh"]