GithubHelp home page GithubHelp logo

1275381 / docker-skeleton-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from federkun/docker-skeleton-php

1.0 2.0 0.0 77 KB

A simple Docker PHP development environment

License: MIT License

PHP 32.44% Shell 67.56%

docker-skeleton-php's Introduction

docker-skeleton-php

nginx mysql php5.6 php7.0 php7.1

Usage

  1. Copy .env.dist to .env:

    $ cp .env.dist .env
  2. If you plan to use the default docker repository to pull the Docker’s images, you can keep the default values of the PROJECT_NAMESPACE and REPOSITORY_NAME environment variables from the .env file and skip this step. Otherwise you need to build your own images. You can do that with:

    $ ./bin/build
  3. Start the container.

    $ docker-compose up -d
  4. Access your application via http://localhost/.

Documentation

Docker

Useful docker commands

# Start containers.
$ docker-compose up -d

# Restart services.
$ docker-compose restart

# List containers.
$ docker-compose ps

# Start a terminal session for <container_name> (i.e: php).
$ docker-compose exec <container_name> /bin/bash

# View logs.
$ docker-compose logs

# List/remove network.
$ docker network [ ls | rm <network_name> ]

# List/remove volumes.
$ docker volume [ ls | rm <volume_name> ]

# Stop containers.
$ docker-compose stop

# Stop and remove containers. Any data which is not in a volume will be lost.
$ docker-compose down

PHP

Choose a different version of php

By default docker-compose.yml uses the latest tag name of the php image which corresponds to php 7.1.

services:
  php:
    image: ${PROJECT_NAMESPACE}/${REPOSITORY_NAME}-php:latest

If you want a specific version of php, you can change it with one of those values: 5.6, 7.0 or 7.1. Example:

  php:
    image: ${PROJECT_NAMESPACE}/${REPOSITORY_NAME}-php:5.6

The default docker repository already provides the images for those php version. Otherwise you need to build them by yourself with:

$ ./bin/build

Add PHPMyAdmin

Edit docker-compose.yml and add a new service definition:

services:
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
     - "8080:80"
    environment:
      PMA_HOST: mysql
    networks:
      - backend

Then phpmyadmin will be accessible to http://localhost:8080/

Composer basic usage

Place the composer.json file that describes the dependencies of your project inside the app folder, then install the defined dependencies through the php container:

$ docker-compose run --rm php composer install

Create a new Symfony project

You can use Composer to ease the creation of a new symfony project:

$ rm -rf app/* && docker-compose run --rm -u $(id -u):$(id -g) php composer create-project symfony/framework-standard-edition .

As from Symfony3.2 you can use the environment variables into you service container configuration, using the %env(MYSQL_DATABASE)% notation:

Symfony config

Composer will create a new Symfony Standard Edition application under the app/ directory.

A minimum configuration file to get your application running under Nginx is already provided from docker-skeleton-php. Remove the default.conf file and rename symfony.conf.example into symfony.conf:

$ rm sites/default.conf
$ mv sites/symfony.conf.example sites/symfony.conf

Now remove the access check from app/web/app_dev.php:

// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) || php_sapi_name() === 'cli-server')
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

Warning: After you deploy to production, make sure that you cannot access the app_dev.php

You can start the containers now:

$ docker-compose up -d

Symfony console

How can I use Symfony's console?

  • For Symfony 3:

    $ docker-compose run --rm php php bin/console
  • For Symfony 2:

    $ docker-compose run --rm php php app/console

docker-skeleton-php's People

Contributors

emirb avatar federkun avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.