feat: update Docker configuration
Removed version specification from docker-compose.yml and added mysqli extension installation in Dockerfile.
This commit is contained in:
297
dockerfile-php-sql-2008/Dockerfile
Normal file
297
dockerfile-php-sql-2008/Dockerfile
Normal file
@@ -0,0 +1,297 @@
|
||||
FROM php:8.3.4-fpm-bullseye
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /var/www/html
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
git \
|
||||
curl \
|
||||
libpng-dev \
|
||||
libonig-dev \
|
||||
libxml2-dev \
|
||||
zip \
|
||||
unzip \
|
||||
libzip-dev \
|
||||
libfreetype6-dev \
|
||||
libjpeg62-turbo-dev \
|
||||
libwebp-dev \
|
||||
libicu-dev \
|
||||
supervisor \
|
||||
nginx \
|
||||
gnupg2 \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
lsb-release \
|
||||
software-properties-common \
|
||||
unixodbc-dev \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Add Microsoft repository and install ODBC driver 17
|
||||
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
|
||||
&& curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list \
|
||||
&& apt-get update \
|
||||
&& ACCEPT_EULA=Y apt-get install -y msodbcsql17 mssql-tools \
|
||||
&& echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Configure OpenSSL to allow TLS 1.0 and 1.1 for SQL Server 2008 compatibility
|
||||
RUN echo "openssl_conf = openssl_init" > /etc/ssl/openssl.cnf.new \
|
||||
&& echo "" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "[openssl_init]" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "ssl_conf = ssl_sect" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "[ssl_sect]" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "system_default = system_default_sect" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "[system_default_sect]" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "MinProtocol = TLSv1.0" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "MaxProtocol = TLSv1.2" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "CipherString = DEFAULT@SECLEVEL=1" >> /etc/ssl/openssl.cnf.new \
|
||||
&& echo "" >> /etc/ssl/openssl.cnf.new \
|
||||
&& cat /etc/ssl/openssl.cnf >> /etc/ssl/openssl.cnf.new \
|
||||
&& mv /etc/ssl/openssl.cnf.new /etc/ssl/openssl.cnf
|
||||
|
||||
# Set environment variable to use the custom OpenSSL configuration
|
||||
ENV OPENSSL_CONF=/etc/ssl/openssl.cnf
|
||||
|
||||
# Configure and install PHP extensions
|
||||
RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp
|
||||
|
||||
RUN docker-php-ext-install -j$(nproc) \
|
||||
bcmath \
|
||||
ctype \
|
||||
fileinfo \
|
||||
gd \
|
||||
intl \
|
||||
mbstring \
|
||||
pdo \
|
||||
pdo_mysql \
|
||||
xml \
|
||||
zip \
|
||||
opcache \
|
||||
pcntl \
|
||||
sockets
|
||||
|
||||
# Install PECL extensions
|
||||
RUN pecl install redis && docker-php-ext-enable redis
|
||||
|
||||
# Install SQL Server extensions
|
||||
RUN pecl install sqlsrv && docker-php-ext-enable sqlsrv
|
||||
RUN pecl install pdo_sqlsrv && docker-php-ext-enable pdo_sqlsrv
|
||||
|
||||
# Clean up PECL cache
|
||||
RUN rm -rf /tmp/pear
|
||||
|
||||
# Install Composer
|
||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||
|
||||
# Install Node.js and npm (using NodeSource repository for latest version)
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
|
||||
&& apt-get install -y nodejs
|
||||
|
||||
# Configure PHP-FPM
|
||||
RUN sed -i 's/listen = 127.0.0.1:9000/listen = 127.0.0.1:9000/' /usr/local/etc/php-fpm.d/www.conf
|
||||
|
||||
# Configure PHP settings
|
||||
RUN echo "upload_max_filesize = 100M" >> /usr/local/etc/php/conf.d/uploads.ini \
|
||||
&& echo "post_max_size = 100M" >> /usr/local/etc/php/conf.d/uploads.ini \
|
||||
&& echo "max_execution_time = 300" >> /usr/local/etc/php/conf.d/uploads.ini \
|
||||
&& echo "memory_limit = 512M" >> /usr/local/etc/php/conf.d/uploads.ini \
|
||||
&& echo "opcache.enable=1" >> /usr/local/etc/php/conf.d/opcache.ini \
|
||||
&& echo "opcache.memory_consumption=128" >> /usr/local/etc/php/conf.d/opcache.ini \
|
||||
&& echo "opcache.interned_strings_buffer=8" >> /usr/local/etc/php/conf.d/opcache.ini \
|
||||
&& echo "opcache.max_accelerated_files=4000" >> /usr/local/etc/php/conf.d/opcache.ini \
|
||||
&& echo "opcache.revalidate_freq=2" >> /usr/local/etc/php/conf.d/opcache.ini \
|
||||
&& echo "opcache.fast_shutdown=1" >> /usr/local/etc/php/conf.d/opcache.ini
|
||||
|
||||
# Remove default nginx configuration and configure Nginx
|
||||
RUN rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
COPY <<EOF /etc/nginx/nginx.conf
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
use epoll;
|
||||
multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
|
||||
'\$status \$body_bytes_sent "\$http_referer" '
|
||||
'"\$http_user_agent" "\$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
client_max_body_size 100M;
|
||||
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
text/xml
|
||||
text/javascript
|
||||
application/json
|
||||
application/javascript
|
||||
application/xml+rss
|
||||
application/atom+xml
|
||||
image/svg+xml;
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
EOF
|
||||
|
||||
# Configure Laravel site
|
||||
RUN mkdir -p /etc/nginx/sites-enabled
|
||||
COPY <<EOF /etc/nginx/sites-enabled/default
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /var/www/html/public;
|
||||
index index.php index.html index.htm;
|
||||
|
||||
location / {
|
||||
try_files \$uri \$uri/ /index.php?\$query_string;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
fastcgi_read_timeout 300;
|
||||
}
|
||||
|
||||
location ~ /\.ht {
|
||||
deny all;
|
||||
}
|
||||
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
try_files \$uri =404;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create required directories
|
||||
RUN mkdir -p /var/run \
|
||||
&& mkdir -p /var/log/supervisor
|
||||
|
||||
# Configure Supervisor
|
||||
COPY <<EOF /etc/supervisor/conf.d/supervisord.conf
|
||||
[unix_http_server]
|
||||
file=/var/run/supervisor.sock
|
||||
chmod=0700
|
||||
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
logfile=/var/log/supervisor/supervisord.log
|
||||
pidfile=/var/run/supervisord.pid
|
||||
user=root
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///var/run/supervisor.sock
|
||||
|
||||
[program:nginx]
|
||||
command=nginx -g "daemon off;"
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stderr_logfile=/var/log/supervisor/nginx.err.log
|
||||
stdout_logfile=/var/log/supervisor/nginx.out.log
|
||||
user=root
|
||||
|
||||
[program:php-fpm]
|
||||
command=php-fpm -F
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stderr_logfile=/var/log/supervisor/php-fpm.err.log
|
||||
stdout_logfile=/var/log/supervisor/php-fpm.out.log
|
||||
user=root
|
||||
|
||||
[program:laravel-worker]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=php /var/www/html/artisan queue:work --sleep=3 --tries=3 --max-time=3600
|
||||
autostart=true
|
||||
autorestart=true
|
||||
user=www-data
|
||||
numprocs=1
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/supervisor/worker.log
|
||||
stopwaitsecs=3600
|
||||
EOF
|
||||
|
||||
# Create startup script
|
||||
COPY <<EOF /usr/local/bin/start.sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Create directories if they don't exist
|
||||
mkdir -p /var/www/html/storage/logs
|
||||
mkdir -p /var/www/html/storage/framework/cache
|
||||
mkdir -p /var/www/html/storage/framework/sessions
|
||||
mkdir -p /var/www/html/storage/framework/views
|
||||
mkdir -p /var/www/html/bootstrap/cache
|
||||
|
||||
# Set permissions
|
||||
chown -R www-data:www-data /var/www/html/storage || true
|
||||
chown -R www-data:www-data /var/www/html/bootstrap/cache || true
|
||||
chmod -R 775 /var/www/html/storage || true
|
||||
chmod -R 775 /var/www/html/bootstrap/cache || true
|
||||
|
||||
# Check if we're in a Laravel project and if vendor exists
|
||||
if [ -f "/var/www/html/artisan" ] && [ ! -d "/var/www/html/vendor" ]; then
|
||||
echo "Installing Composer dependencies..."
|
||||
composer install --no-dev --optimize-autoloader
|
||||
fi
|
||||
|
||||
# Check if package.json exists and node_modules doesn't
|
||||
if [ -f "/var/www/html/package.json" ] && [ ! -d "/var/www/html/node_modules" ]; then
|
||||
echo "Installing npm dependencies..."
|
||||
npm install
|
||||
npm run build
|
||||
fi
|
||||
|
||||
# Run Laravel optimizations if this is a Laravel project
|
||||
if [ -f "/var/www/html/artisan" ]; then
|
||||
echo "Running Laravel optimizations..."
|
||||
php artisan config:cache || true
|
||||
php artisan route:cache || true
|
||||
php artisan view:cache || true
|
||||
fi
|
||||
|
||||
# Start supervisor
|
||||
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
||||
EOF
|
||||
|
||||
RUN chmod +x /usr/local/bin/start.sh
|
||||
|
||||
# Set correct ownership
|
||||
RUN chown -R www-data:www-data /var/www/html
|
||||
|
||||
# Expose port
|
||||
EXPOSE 80
|
||||
|
||||
# Start the application
|
||||
CMD ["/usr/local/bin/start.sh"]
|
||||
Reference in New Issue
Block a user