├── README.md ├── docker-compose.yml ├── index.php ├── nginx ├── Dockerfile └── default.conf └── php └── Dockerfile /README.md: -------------------------------------------------------------------------------- 1 | # Pre-requisites 2 | 3 | You must have Docker installed for this code to work! Check the [Installation Guide](https://docs.docker.com/engine/installation/) if you haven't got it installed. 4 | 5 | It contains a basic LEMP stack running with Docker, intented to be used for local web development. 6 | 7 | ## Get started 8 | 9 | Clone the project and run docker-compose 10 | 11 | ```bash 12 | git clone https://github.com/jivoi/php-development-in-docker.git 13 | cd php-development-in-docker 14 | docker-compose up -d 15 | docker-machine ip default 16 | docker-compose -d down 17 | ``` 18 | 19 | ## Description 20 | 21 | The different containers are described in [`docker-compose.yml`](https://github.com/jivoi/php-development-in-docker/blob/master/docker-compose.yml). 22 | 23 | There are 6 of them: 24 | 25 | - a container for Nginx 26 | - a container for PHP-FPM 27 | - a container for MySQL 28 | - a container for phpMyAdmin 29 | - a container to make MySQL data persistent 30 | - a container for the application code 31 | 32 | All of them are using official images. 33 | 34 | The current directory is mounted into the one served by Nginx on the container, so any update to the code is available without having to rebuild the container. 35 | 36 | The MySQL data sits in its own directory mounted into its own container to make it persistent. 37 | 38 | The application is available on the port 80 of the host machine. 39 | 40 | phpMyAdmin is available on port 8080. 41 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | nginx: 2 | build: ./nginx/ 3 | ports: 4 | - 80:80 5 | links: 6 | - php 7 | volumes_from: 8 | - app 9 | 10 | php: 11 | build: ./php/ 12 | expose: 13 | - 9000 14 | links: 15 | - mysql 16 | volumes_from: 17 | - app 18 | 19 | app: 20 | image: php:7.0-fpm 21 | volumes: 22 | - .:/var/www/html 23 | command: "true" 24 | 25 | mysql: 26 | image: mysql:latest 27 | volumes_from: 28 | - data 29 | environment: 30 | MYSQL_ROOT_PASSWORD: secret 31 | MYSQL_DATABASE: project 32 | MYSQL_USER: project 33 | MYSQL_PASSWORD: project 34 | 35 | data: 36 | image: mysql:latest 37 | volumes: 38 | - /var/lib/mysql 39 | command: "true" 40 | 41 | phpmyadmin: 42 | image: phpmyadmin/phpmyadmin 43 | ports: 44 | - 8080:80 45 | links: 46 | - mysql 47 | environment: 48 | PMA_HOST: mysql -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 | query("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_TYPE='BASE TABLE'"); 13 | $tables = $query->fetchAll(PDO::FETCH_COLUMN); 14 | 15 | if (empty($tables)) { 16 | echo "

There are no tables in database \"{$database}\".

"; 17 | } else { 18 | echo "

Database \"{$database}\" has the following tables:

"; 19 | echo ""; 24 | } 25 | ?> 26 | 27 | -------------------------------------------------------------------------------- /nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:latest 2 | 3 | COPY ./default.conf /etc/nginx/conf.d/default.conf -------------------------------------------------------------------------------- /nginx/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | root /var/www/html; 4 | index index.html index.php; 5 | 6 | charset utf-8; 7 | 8 | location / { 9 | try_files $uri $uri/ /index.php?$query_string; 10 | } 11 | 12 | location = /favicon.ico { access_log off; log_not_found off; } 13 | location = /robots.txt { access_log off; log_not_found off; } 14 | 15 | access_log off; 16 | error_log /var/log/nginx/error.log error; 17 | 18 | sendfile off; 19 | 20 | client_max_body_size 100m; 21 | 22 | location ~ \.php$ { 23 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 24 | fastcgi_pass php:9000; 25 | fastcgi_index index.php; 26 | include fastcgi_params; 27 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 28 | fastcgi_intercept_errors off; 29 | fastcgi_buffer_size 16k; 30 | fastcgi_buffers 4 16k; 31 | } 32 | 33 | location ~ /\.ht { 34 | deny all; 35 | } 36 | } -------------------------------------------------------------------------------- /php/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.0-fpm 2 | 3 | RUN docker-php-ext-install pdo_mysql --------------------------------------------------------------------------------