Skip to content

Commit f3eb6a5

Browse files
committed
Merge branch 'support-mongo'
* support-mongo: add Mongo Support to the Readme added php-mongodb extension simple reformatting set the original volume path get mongo volum from the data container added mongodb driver for php5.5 5.6 added mongodb image + PHP7 driver Fix Conflicts in: docker-compose.yml php-fpm/Dockerfile-55 php-fpm/Dockerfile-56 php-fpm/Dockerfile-70 php-fpm/laravel.ini
2 parents 1148a3d + 685c34d commit f3eb6a5

8 files changed

Lines changed: 106 additions & 8 deletions

File tree

README.md

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ It's like Laravel Homestead but for Docker instead of Vagrant.
4040
- [Install Laravel from a Docker Container](#Install-Laravel)
4141
- [Run Artisan Commands](#Run-Artisan-Commands)
4242
- [Use Redis](#Use-Redis)
43+
- [Use Mongo](#Use-Mongo)
4344
- [PHP](#PHP)
4445
- [Install PHP Extensions](#Install-PHP-Extensions)
4546
- [Change the PHP-FPM Version](#Change-the-PHP-FPM-Version)
@@ -92,6 +93,7 @@ docker-compose up nginx mysql redis
9293
- PostgreSQL
9394
- MariaDB
9495
- Neo4j
96+
- MongoDB
9597
- Redis
9698
- Memcached
9799
- Beanstalkd
@@ -208,7 +210,7 @@ docker-compose up -d nginx mysql
208210
*Note: the PHP-FPM, Workspace, Application and Data Containers will automatically run.*
209211

210212

211-
Supported Containers: `nginx`, `mysql`, `redis`, `postgres`, `mariadb`, `neo4j`, `memcached`, `beanstalkd`, `beanstalkd-console`, `workspace`, `data`, `php-fpm`, `application`.
213+
Supported Containers: `nginx`, `mysql`, `redis`, `postgres`, `mariadb`, `neo4j`, `mongo`, `memcached`, `beanstalkd`, `beanstalkd-console`, `workspace`, `data`, `php-fpm`, `application`.
212214

213215

214216

@@ -512,9 +514,6 @@ Composer update
512514
```bash
513515
phpunit
514516
```
515-
```bash
516-
laravel new blog
517-
```
518517

519518

520519

@@ -527,7 +526,11 @@ laravel new blog
527526
<a name="Use-Redis"></a>
528527
### Use Redis
529528

530-
1 - First make sure you run the Redis Container with the `docker-compose` command.
529+
1 - First make sure you run the Redis Container (`redis`) with the `docker-compose up` command.
530+
531+
```bash
532+
docker-compose up -d redis
533+
```
531534

532535
2 - Open your Laravel's `.env` file and set the `REDIS_HOST` to your `Docker-IP` instead of the default `127.0.0.1` IP.
533536

@@ -555,7 +558,7 @@ CACHE_DRIVER=redis
555558
SESSION_DRIVER=redis
556559
```
557560

558-
4 - Finally make sure you have the `predis/predis` package `(~1.0)` installed via Composer first.
561+
4 - Finally make sure you have the `predis/predis` package `(~1.0)` installed via Composer:
559562

560563
```bash
561564
composer require predis/predis:^1.0
@@ -571,6 +574,59 @@ composer require predis/predis:^1.0
571574

572575

573576

577+
<br>
578+
<a name="Use-Mongo"></a>
579+
### Use Mongo
580+
581+
1 - First make sure you run the MongoDB Container (`mongo`) with the `docker-compose up` command.
582+
583+
```bash
584+
docker-compose up -d mongo
585+
```
586+
587+
588+
2 - Add the MongoDB configurations to the `config/database.php` config file:
589+
590+
```php
591+
'connections' => [
592+
593+
'mongodb' => [
594+
'driver' => 'mongodb',
595+
'host' => env('DB_HOST', 'localhost'),
596+
'port' => env('DB_PORT', 27017),
597+
'database' => env('DB_DATABASE', 'database'),
598+
'username' => '',
599+
'password' => '',
600+
'options' => [
601+
'database' => '',
602+
]
603+
],
604+
605+
// ...
606+
607+
],
608+
```
609+
610+
3 - Open your Laravel's `.env` file and update the following variables:
611+
612+
- set the `DB_HOST` to your `Docker-IP`.
613+
- set the `DB_PORT` to `27017`.
614+
- set the `DB_DATABASE` to `database`.
615+
616+
617+
4 - Finally make sure you have the `jenssegers/mongodb` package installed via Composer and its Service Provider is added.
618+
619+
```bash
620+
composer require jenssegers/mongodb
621+
```
622+
More details about this [here](https://github.com/jenssegers/laravel-mongodb#installation).
623+
624+
5 - Test it:
625+
626+
- First let your Models extend from the Mongo Eloquent Model. Check the [documentation](https://github.com/jenssegers/laravel-mongodb#eloquent).
627+
- Enter the Workspace Continer `docker exec -it laradock_workspace_1 bash`.
628+
- Migrate the Database `php artisan migrate`.
629+
574630

575631

576632

docker-compose.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ services:
3131
- /var/lib/postgres:/var/lib/postgres
3232
- /var/lib/mariadb:/var/lib/mariadb
3333
- /var/lib/memcached:/var/lib/memcached
34-
- /var/lib/neo4j:/var/lib/neo4j/data
3534
- /var/lib/redis:/data
35+
- /var/lib/neo4j:/var/lib/neo4j/data
36+
- /var/lib/mongo:/data/db
3637

3738
### Nginx Server Container ##################################
3839

@@ -101,6 +102,15 @@ services:
101102
volumes_from:
102103
- data
103104

105+
### MongoDB Container #######################################
106+
107+
mongo:
108+
build: ./mongo
109+
ports:
110+
- "27017:27017"
111+
volumes_from:
112+
- data
113+
104114
### Redis Container #########################################
105115

106116
redis:

mongo/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM mongo:latest
2+
3+
MAINTAINER Mahmoud Zalt <mahmoud@zalt.me>
4+
5+
#COPY mongo.conf /usr/local/etc/mongo/mongo.conf
6+
7+
VOLUME /data/db /data/configdb
8+
9+
CMD ["mongod"]
10+
11+
EXPOSE 27017
12+

php-fpm/Dockerfile-55

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ RUN pecl install memcached \
2525
RUN pecl install xdebug \
2626
&& docker-php-ext-enable xdebug
2727

28+
# Install mongodb driver
29+
RUN pecl install mongodb
30+
2831
RUN usermod -u 1000 www-data
2932

3033
WORKDIR /var/www/laravel

php-fpm/Dockerfile-56

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ RUN pecl install memcached \
2525
RUN pecl install xdebug \
2626
&& docker-php-ext-enable xdebug
2727

28+
# Install mongodb driver
29+
RUN pecl install mongodb
30+
2831
RUN usermod -u 1000 www-data
2932

3033
WORKDIR /var/www/laravel

php-fpm/Dockerfile-70

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ RUN curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-dev/php-m
2929
RUN pecl install xdebug \
3030
&& docker-php-ext-enable xdebug
3131

32+
# Install mongodb driver
33+
RUN pecl install mongodb
34+
3235
RUN usermod -u 1000 www-data
3336

3437
WORKDIR /var/www/laravel

php-fpm/laravel.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
date.timezone=UTC
22
display_errors=Off
3-
log_errors=On
3+
log_errors=On
4+
extension=mongodb.so

workspace/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ RUN apt-get update && apt-get install -y --force-yes \
3434
php7.0-sqlite3 \
3535
php7.0-zip \
3636
php7.0-memcached \
37+
php-dev \
38+
libcurl4-openssl-dev \
39+
libedit-dev \
40+
libssl-dev \
41+
libxml2-dev \
42+
xz-utils \
3743
sqlite3 \
3844
libsqlite3-dev \
3945
git \
@@ -66,6 +72,10 @@ RUN curl -s http://getcomposer.org/installer | php \
6672
&& mv composer.phar /usr/local/bin/ \
6773
&& echo "alias composer='/usr/local/bin/composer.phar'" >> ~/.bashrc
6874

75+
# Install mongodb extension
76+
RUN pecl install mongodb
77+
RUN echo "extension=mongodb.so" >> /etc/php/7.0/cli/php.ini
78+
6979
# Source the bash
7080
RUN . ~/.bashrc
7181

0 commit comments

Comments
 (0)