|
1 |
| -# lemp-docker-compose |
| 1 | +# docker-php-nginx-mysql-postgres-composer |
2 | 2 |
|
3 |
| -Fully LEMP working environment for Docker compose. |
| 3 | +Docker Compose configuration to run PHP, Nginx, PHP-FPM, MySQL, PostgreSQL, Composer and Symfony |
4 | 4 |
|
5 | 5 | PHP 7.4.14
|
6 | 6 |
|
7 | 7 | Nginx 1.18
|
8 | 8 |
|
9 |
| -Mysql 8.0.23 |
| 9 | +MySQL 8.0.23 |
10 | 10 |
|
11 |
| -## Pre-requisites |
| 11 | +PostgreSQL 13.1 |
12 | 12 |
|
13 |
| -You must have docker desktop running on your computer. Follow instalation instructions from here: |
| 13 | +## Overview |
| 14 | + |
| 15 | +This Docker Compose configuration allows you to run PHP 7.4 with Nginx 1.18, PHP-FPM, MySQL 8.0.23 and PostgreSQL 13.1, Composer and Symfony. |
| 16 | + |
| 17 | +It exposes 5 services: |
| 18 | + |
| 19 | +nginx |
| 20 | +php-fom |
| 21 | +mysql |
| 22 | +postgres |
| 23 | +composer |
| 24 | + |
| 25 | +To know all extensions enabled for PHP you can run it using `docker-compose up`and visit: http://localhost/phpinfo.php and check the PHP info. |
| 26 | + |
| 27 | +The UUID extension for PostgreSQL has been added. |
| 28 | + |
| 29 | +Nginx includes default configuration for Symfony 5. |
| 30 | + |
| 31 | +Composer runs during boot to install the vendors. |
| 32 | + |
| 33 | +Symfony command is available. |
| 34 | + |
| 35 | + |
| 36 | +## Prerequisites |
| 37 | + |
| 38 | +You must have docker running on your computer. Follow instalation instructions from here: |
14 | 39 |
|
15 | 40 | https://docs.docker.com/desktop/
|
16 | 41 |
|
| 42 | + |
| 43 | +## How to use it |
| 44 | + |
| 45 | +### Start docker compose |
| 46 | + |
| 47 | +Checkout this repo or download it. |
| 48 | + |
| 49 | +Just run `docker-compose up` |
| 50 | + |
| 51 | +By default nginx will be available on `http://localhost:80`, PostgreSQL on `http://localhost:5432` and MySQL on `http://localhost:3306` |
| 52 | + |
| 53 | +### Use nginx |
| 54 | + |
| 55 | +You can run some nginx commands when needed, i.e.: |
| 56 | + |
| 57 | +`docker-compose exec nginx nginx -v` |
| 58 | + |
| 59 | +### Use Composer |
| 60 | + |
| 61 | +You can run composer commands, i.e.: |
| 62 | + |
| 63 | +`docker-compose run composer <composer-command>` |
| 64 | + |
| 65 | +`docker-compose run composer -V` |
| 66 | + |
| 67 | +### Use Symfony |
| 68 | + |
| 69 | +You can run symfony commands, i.e.: |
| 70 | + |
| 71 | +`docker-compose exec php-fpm symfony <symfony-command>` |
| 72 | + |
| 73 | +For instance, you can check symfony requirements: |
| 74 | + |
| 75 | +`docker-compose exec php-fpm symfony check:req` |
| 76 | + |
| 77 | +### Use PHP |
| 78 | + |
| 79 | +`docker-compose exec php-fpm php -v` |
| 80 | + |
| 81 | +### Use PostgreSQL |
| 82 | + |
| 83 | +You can run postgres commands, i.e.: |
| 84 | + |
| 85 | +`docker-compose exec postgres postgres -V` |
| 86 | + |
| 87 | +And work with your DBs: |
| 88 | + |
| 89 | +`docker-compose exec postgres psql -d testdb -U myuser` |
| 90 | + |
| 91 | +### Use MySQL |
| 92 | + |
| 93 | +You can run mysql commands, i.e.: |
| 94 | + |
| 95 | +`docker-compose exec mysql mysql -V` |
| 96 | + |
| 97 | +And work with your DBs: |
| 98 | + |
| 99 | +`docker-compose exec mysql mysql -u root -pmyrootpassword` |
| 100 | + |
| 101 | + |
| 102 | + |
17 | 103 | ## Configuration
|
18 | 104 |
|
19 |
| -Check docker-compose.yml and change the volume for nginx and php-fpm where you have your code, by default it's serving from `src/` folder a default phpinfo() file. |
| 105 | +### Configuring volumes |
| 106 | + |
| 107 | +By default when you run `docker-compose up` it's attaching the `src/` folder as volume. It will be the folder used to serve the source code. |
| 108 | + |
| 109 | +Check `docker-compose.yml` and change the volumes for nginx and php-fpm where you have your code. |
| 110 | + |
| 111 | +You can change `./src/` under `volumes:` to any other folder in your system. |
| 112 | + |
| 113 | +``` |
| 114 | +volumes: |
| 115 | + - ./src/:/var/www/ |
| 116 | +``` |
| 117 | + |
| 118 | +For instance: |
| 119 | + |
| 120 | +``` |
| 121 | +volumes: |
| 122 | + - ../my-symfony-project/:/var/www/ |
| 123 | +``` |
| 124 | + |
| 125 | +### Configuring DBs |
| 126 | + |
| 127 | +The `docker-compose.yml` runs both MySQL and PostgreSQL but if you want to use only one you can comment the code out (or delete it) the DB you don't want to use in `docker-compose.yml` file. |
| 128 | + |
| 129 | +The `.env` file contains the sensitive user & password information for connecting to the DBs. |
| 130 | + |
| 131 | +Modify `.env` file default parameters according to your needs. |
| 132 | + |
| 133 | +### Configuring PHP |
| 134 | + |
| 135 | +You can enable/disable any PHP directive just by editing these files: |
20 | 136 |
|
21 |
| -## Get up & running |
| 137 | +`./php-fpm/conf.d/php.ini` or `./php-fpm/conf.d/xdebug.ini` |
22 | 138 |
|
23 |
| -Just run `docker-compose up` |
|
0 commit comments