Skip to content

Instantly share code, notes, and snippets.

@rafabarzotto
Forked from pollend/Dockerfile
Created February 7, 2022 17:07
Show Gist options
  • Save rafabarzotto/33083d1d386cdb8e986375343fce6a31 to your computer and use it in GitHub Desktop.
Save rafabarzotto/33083d1d386cdb8e986375343fce6a31 to your computer and use it in GitHub Desktop.
A sample configuration for deploying symfony for Azure.

Sample Symfony Azure AppService Configuration

This contains a couple core file that can be used to deploy a Symfony Application built for Azure AppService. The basic process involves copying the source files into a symfony project and the process of deplyoing is for the user to work out. Azure Samples

  • A Docker file - Dockerfile
  • A supervisor configuration - supervisord.conf
  • ngnix web config - symfony-prod.conf

Docker

The default configuration for azure is fairly basic and is not ideal for use with symfony. The docker container is running two services: ngnix and php-fpm. ngnix handles the request and the results are funneled to the php-fpm workers through a local local port on 9000. this configuration is more suited and runs significantly faster to the default cgi bin/apache configuration that comes default with azure when deploying with code. It's possible to enable extensions to improve the performance for code based configuration but a docker based configuration is more reproducible (php extensions).

Deployment

The general process involes building the docker image in the root of the project and deploying it to a container registry. This can be either in azure, or a local instance. Azure devops integrates really well with azure and can be used to deploy to an azure registry that publishes the built images to azure app service. running the images to a public host like dockerhub can also be fairly ideal. more information can be found here.

######################################################################3
FROM node:10
# This first part uses a node image to build the frontend dependencies and copies
# the results into the next setep to produce the final deployed image
ADD . /var/www/symfony
WORKDIR /var/www/symfony
RUN yarn install --no-progress
RUN yarn build
RUN rm -rf node_modules && rm -rf assets
######################################################################3
FROM php:7.2-fpm
MAINTAINER Michael Pollind <polli104@mail.chapman.edu>
RUN apt-get update && apt-get install -y \
openssl \
unzip \
libpq-dev \
libzip-dev \
zip \
nginx \
supervisor
# Configure Ngnix ###############################
# Add symfony production configuration and remove default ngnix configuration
ADD symfony-prod.conf /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-available/symfony-prod.conf /etc/nginx/sites-enabled/symfony \
&& rm /etc/nginx/sites-enabled/default
RUN echo "upstream php-upstream { server 127.0.0.1:9000; }" > /etc/nginx/conf.d/upstream.conf
RUN usermod -u 1000 www-data
##################################################
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& composer --version
# Configure php extenions
RUN docker-php-ext-configure zip --with-libzip
RUN docker-php-ext-install pdo pdo_pgsql zip
RUN docker-php-ext-configure opcache --enable-opcache \
&& docker-php-ext-install opcache
RUN pecl install redis && docker-php-ext-enable redis
# bring in the symfony configuration from the first stage
COPY --from=0 --chown=www-data:www-data /var/www/symfony /var/www/symfony
WORKDIR /var/www/symfony
# PHP configurations for production
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY opcache-prod.ini $PHP_INI_DIR/conf.d/opcache.ini
RUN sed -i '/realpath_cache_size/c \realpath_cache_size=4096K' "$PHP_INI_DIR/php.ini"
RUN sed -i '/realpath_cache_ttl/c \realpath_cache_ttl=600' "$PHP_INI_DIR/php.ini"
# ssh #############################################
ENV SSH_PASSWD "root:Docker!"
RUN apt-get update \
&& apt-get install -y --no-install-recommends dialog \
&& apt-get update \
&& apt-get install -y --no-install-recommends openssh-server \
&& echo "$SSH_PASSWD" | chpasswd
COPY sshd_config /etc/ssh/
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
USER www-data
RUN composer install
RUN composer dump-autoload --optimize --classmap-authoritative
USER root
CMD ["/usr/bin/supervisord"]
EXPOSE 80
EXPOSE 443
EXPOSE 2222
[opcache]
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0
#
# /etc/ssh/sshd_config
#
Port 2222
ListenAddress 0.0.0.0
LoginGraceTime 180
X11Forwarding yes
Ciphers aes128-cbc,3des-cbc,aes256-cbc
MACs hmac-sha1,hmac-sha1-96
StrictModes yes
SyslogFacility DAEMON
PrintMotd no
IgnoreRhosts no
#deprecated option
#RhostsAuthentication no
RhostsRSAAuthentication yes
RSAAuthentication no
PasswordAuthentication yes
PermitEmptyPasswords no
PermitRootLogin yes
[supervisord]
nodaemon=true
[program:ngnix]
command=/usr/sbin/nginx -g 'daemon off;'
priority=900
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
username=www-data
autorestart=true
[program:fpm]
command=/usr/local/sbin/php-fpm
autostart=true
autorestart=true
priority=5
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:ssh]
command=service ssh start
priority=1
user=root
server {
server_name symfony.local;
root /var/www/symfony/public;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
#fastcgi_pass unix:/var/run/php7.2-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment