File size: 3,720 Bytes
ede938f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17bc34e
5d4c685
ede938f
 
 
5d4c685
ede938f
 
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
# 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

# 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

# Set proper permissions
RUN chown -R www-data:www-data /var/www/html && \
    chmod -R 755 /var/www/html && \
    chmod 644 /var/www/html/.htaccess

# Create SQLite database directory
RUN mkdir -p /var/www/html/wp-content/database && \
    chown -R www-data:www-data /var/www/html/wp-content/database && \
    chmod 755 /var/www/html/wp-content/database

# 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"]