Deploying your CakePHP applications in production using Docker

Dockerfile

#start with our base image (the foundation) - version 7.1.5 FROM php:7.1.5-apache 
#install all the system dependencies and enable PHP modules
RUN apt-get update && apt-get install -y \ libicu-dev \ libpq-dev \ libmcrypt-dev \ mysql-client \ git \ zip \ unzip \ && rm -r /var/lib/apt/lists/* \ && docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \ && docker-php-ext-install \ intl \ mbstring \ mcrypt \ pcntl \ pdo_mysql \ pdo_pgsql \ pgsql \ zip \ opcache
#install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer #set our application folder as an environment variable ENV APP_HOME /var/www/html #change uid and gid of apache to docker user uid/gid RUN usermod -u 1000 www-data && groupmod -g 1000 www-data #change the web_root to cakephp /var/www/html/webroot folder RUN sed -i -e "s/html/html\/webroot/g" /etc/apache2/sites-enabled/000-default.conf # enable apache module rewrite RUN a2enmod rewrite #copy source files and run composer COPY . $APP_HOME # install all PHP dependencies RUN composer install --no-interaction #change ownership of our applications
RUN chown -R www-data:www-data $APP_HOME

Docker-Compose

version: '2' # define all services services:    # our service is called CakePHP ;-)    cakephp:      # we want to use the image which is build from our Dockerfile  

build: .
# apache is running on port 80 but we want to expose this to port 4000 on our local machine ports: - "4000:80" # we depending on the mysql backend depends_on: - mysql # we mount the working dir into the container, handyfor development volumes: - .:/var/www/html/ environment: - SECURITY_SALT=ashjg23697sds97139871298ashk - MYSQL_URL=mysql - MYSQL_USERNAME=root - MYSQL_PASSWORD=root mysql: # we use the mysql base image, version 5.6.36 image: mysql:5.6.36 # we mount a datavolume to make sure we don't loose data volumes: - mysql_data:/var/lib/mysql # setting some envvars to create the DB environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=cakephp volumes: mysql_data:
'Datasources' => [    'default' => [        'className' => 'Cake\Database\Connection',        'driver' => 'Cake\Database\Driver\Mysql',        'persistent' => false,        'username' => env('MYSQL_USERNAME', 'root'),        'password' => env('MYSQL_PASSWORD', ''),        'database' => 'cakephp',        'encoding' => 'utf8',        'timezone' => 'UTC',        'flags' => [],        'cacheMetadata' => true,        'log' => false,        'quoteIdentifiers' => false,        'host' => env('MYSQL_URL', null),    ],

Running in production using Cloud 66

--

--

--

DevOps-as-a-Service to help developers build, deploy and maintain apps on any Cloud. Sign-up for a free trial by visting: www.cloud66.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Your first Aiven API call

Call-centre tutorial: part 3

Leased Line Providers in Capel Bangor #Capel #Bangor https://t.co/u1dOPSv9YF

Google Sheets — How to Filter by Cell Fill Color

Product Update 43— AMA Product Update Recap — APRIL FOOLS EDITION

Testing a Spring Boot REST API against a Contract with Spring Cloud Contract

21 days of Code with Code Warriors — Day 2

Creating a Boss Weapon in Unity

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloud 66

Cloud 66

DevOps-as-a-Service to help developers build, deploy and maintain apps on any Cloud. Sign-up for a free trial by visting: www.cloud66.com

More from Medium

PHP Apache MySQL using Docker

Local Docker + MySQL (MacOS)

How to Set up Gitlab CI/CD and Deploy Laravel Application with Gitlab CI/CD

table_open_cache