Skip to content

Instantly share code, notes, and snippets.

@TimoDJatomika
Last active March 19, 2020 15:04
Show Gist options
  • Save TimoDJatomika/a8f81ef2b22a7e81af0de5b36b9fbfaf to your computer and use it in GitHub Desktop.
Save TimoDJatomika/a8f81ef2b22a7e81af0de5b36b9fbfaf to your computer and use it in GitHub Desktop.

Revisions

  1. TimoDJatomika revised this gist Mar 19, 2020. 1 changed file with 16 additions and 25 deletions.
    41 changes: 16 additions & 25 deletions laravel.md
    Original file line number Diff line number Diff line change
    @@ -1,52 +1,42 @@
    # Using Laravel and Docker
    by Timo Stankowitz <[email protected]>

    The latest version of Laravel with Apache webserver in just one Docker container.

    If you have any questions of any suggestions just reach out to me.

    ## create a new project with composer
    ## Create a new project with composer

    Don't create an extra directory. Comperser will do this for you. The folder name will be *project-name* (change to your actual project name).

    Make sure you have the latest version of the composer docker image: `docker pull composer`

    `docker run -u 1000 --rm -v $(pwd):/app composer create-project --prefer-dist laravel/laravel *project-name*`

    This can take you up to 5 minutes.

    ## create an .env file
    `cp .env.example .env` You can copy and paste the first part of the example file.

    ## create an application encryption key
    This is required. Otherwise your application will not start. Use `php artisan` for that:

    ```bash
    cd project-name
    docker run --rm -v (pwd):/mount php:7.4 php /mount/artisan key:generate --ansi
    ```

    ## set the currect folder permission
    upcomming
    This can take up to 5 minutes.

    ## start your application with artisan
    The simplest way is to create a `Dockerfile` in you root directory with `touch Dockerfile`. Copy and paste the following content:

    ```
    FROM php
    FROM php:7.4-apache
    LABEL maintainer="Timo Stankowitz <[email protected]>"
    COPY ./ /mount
    WORKDIR /mount
    RUN a2enmod rewrite
    ENTRYPOINT ["php", "artisan", "serve"]
    ```
    COPY config/apache.conf /etc/apache2/sites-available/000-default.conf
    Per default your application will run on port **8000**. Just go to [http://localhost:8000](http://localhost:8000) to check if your application is running.
    RUN rmdir /var/www/html
    If you want to change the port just replace the list line with this: `ENTRYPOINT ["php", "artisan", "serve", "--port=80"]`. In this example your application will be running on port *80*.
    COPY ./ /var/www/
    # update permission
    RUN chown -R www-data: /var/www/bootstrap/cache/
    RUN chmod -R 777 /var/www/storage/
    RUN chmod -R 777 /var/www/bootstrap/cache/
    ```

    ### create `docker-compose.yml`
    ### Create `docker-compose.yml`
    Replace *project-name* with your actually project name.
    ```
    version: '3'
    @@ -73,4 +63,5 @@ networks:

    and run `docker-compose up`

    Open a webbrowser and open [localhost](http://localhost)

  2. TimoDJatomika revised this gist Mar 19, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion laravel.md
    Original file line number Diff line number Diff line change
    @@ -57,7 +57,8 @@ services:
    - project-name
    ports:
    - 80:8000
    endpoint: ["php", "artisan", "serve", "--host=0.0.0.0"]
    working_dir: "/mount"
    entrypoint: ["php", "artisan", "serve", "--host=0.0.0.0"]
    volumes:
    - ./:/mount
  3. TimoDJatomika revised this gist Mar 19, 2020. 1 changed file with 16 additions and 4 deletions.
    20 changes: 16 additions & 4 deletions laravel.md
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ This is required. Otherwise your application will not start. Use `php artisan` f

    ```bash
    cd project-name
    docker run --rm -v (pwd):/mount php:7.3 php /mount/artisan key:generate --ansi
    docker run --rm -v (pwd):/mount php:7.4 php /mount/artisan key:generate --ansi
    ```

    ## set the currect folder permission
    @@ -47,15 +47,27 @@ If you want to change the port just replace the list line with this: `ENTRYPOINT


    ### create `docker-compose.yml`

    Replace *project-name* with your actually project name.
    ```
    version: '3'
    services:
    project-name:
    build: .
    network_mode: 'host'
    image: php:7.4
    networks:
    - project-name
    ports:
    - 80:8000
    endpoint: ["php", "artisan", "serve", "--host=0.0.0.0"]
    volumes:
    - ./:/mount
    networks:
    project-name:
    driver: bridge
    ipam:
    driver: default
    config:
    - subnet: 172.29.1.0/24
    ```

    and run `docker-compose up`
  4. TimoDJatomika revised this gist Mar 19, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion laravel.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,9 @@ If you have any questions of any suggestions just reach out to me.

    Don't create an extra directory. Comperser will do this for you. The folder name will be *project-name* (change to your actual project name).

    `docker run -u 1000 --rm -v $(pwd):/app composer/composer create-project --prefer-dist laravel/laravel *project-name*`
    Make sure you have the latest version of the composer docker image: `docker pull composer`

    `docker run -u 1000 --rm -v $(pwd):/app composer create-project --prefer-dist laravel/laravel *project-name*`

    This can take you up to 5 minutes.

  5. TimoDJatomika revised this gist Jul 28, 2019. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion laravel.md
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,10 @@ This can take you up to 5 minutes.
    ## create an application encryption key
    This is required. Otherwise your application will not start. Use `php artisan` for that:

    `docker run --rm -v $(pwd):/mount php php /mount/artisan key:generate`
    ```bash
    cd project-name
    docker run --rm -v (pwd):/mount php:7.3 php /mount/artisan key:generate --ansi
    ```

    ## set the currect folder permission
    upcomming
  6. TimoDJatomika revised this gist Oct 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion laravel.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ If you have any questions of any suggestions just reach out to me.

    Don't create an extra directory. Comperser will do this for you. The folder name will be *project-name* (change to your actual project name).

    `docker run -u 1000 ---rm -v $(pwd):/app composer/composer create-project --prefer-dist laravel/laravel *project-name*`
    `docker run -u 1000 --rm -v $(pwd):/app composer/composer create-project --prefer-dist laravel/laravel *project-name*`

    This can take you up to 5 minutes.

  7. TimoDJatomika revised this gist Aug 18, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion laravel.md
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,7 @@ ENTRYPOINT ["php", "artisan", "serve"]

    Per default your application will run on port **8000**. Just go to [http://localhost:8000](http://localhost:8000) to check if your application is running.

    If you want to change the port just replace the list line with this: `ENTRYPOINT ["php", "artisan", "serve", "--port=80"]`. In this example your port will be *80*.
    If you want to change the port just replace the list line with this: `ENTRYPOINT ["php", "artisan", "serve", "--port=80"]`. In this example your application will be running on port *80*.


    ### create `docker-compose.yml`
  8. TimoDJatomika revised this gist Aug 18, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion laravel.md
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ The simplest way is to create a `Dockerfile` in you root directory with `touch D

    ```
    FROM php
    LABEL maintainer="Timo Stankowitz <timo.stankowitz@gmail.com>"
    LABEL maintainer="Timo Stankowitz <laravel@brainoftimo.com>"
    COPY ./ /mount
  9. TimoDJatomika created this gist Aug 18, 2018.
    58 changes: 58 additions & 0 deletions laravel.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    # Using Laravel and Docker
    by Timo Stankowitz <[email protected]>

    If you have any questions of any suggestions just reach out to me.

    ## create a new project with composer

    Don't create an extra directory. Comperser will do this for you. The folder name will be *project-name* (change to your actual project name).

    `docker run -u 1000 ---rm -v $(pwd):/app composer/composer create-project --prefer-dist laravel/laravel *project-name*`

    This can take you up to 5 minutes.

    ## create an .env file
    `cp .env.example .env` You can copy and paste the first part of the example file.

    ## create an application encryption key
    This is required. Otherwise your application will not start. Use `php artisan` for that:

    `docker run --rm -v $(pwd):/mount php php /mount/artisan key:generate`

    ## set the currect folder permission
    upcomming

    ## start your application with artisan
    The simplest way is to create a `Dockerfile` in you root directory with `touch Dockerfile`. Copy and paste the following content:

    ```
    FROM php
    LABEL maintainer="Timo Stankowitz <[email protected]>"
    COPY ./ /mount
    WORKDIR /mount
    ENTRYPOINT ["php", "artisan", "serve"]
    ```

    Per default your application will run on port **8000**. Just go to [http://localhost:8000](http://localhost:8000) to check if your application is running.

    If you want to change the port just replace the list line with this: `ENTRYPOINT ["php", "artisan", "serve", "--port=80"]`. In this example your port will be *80*.


    ### create `docker-compose.yml`

    ```
    version: '3'
    services:
    project-name:
    build: .
    network_mode: 'host'
    volumes:
    - ./:/mount
    ```

    and run `docker-compose up`